aboutsummaryrefslogtreecommitdiff
path: root/ber/bitstring.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-15 14:32:02 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-15 14:32:02 +0200
commita1c1227233f35978dd00ab8de541c7c763bbcd72 (patch)
tree570bb816502518aa0fdf4ee9d83579928eebdcc4 /ber/bitstring.go
parented424d007c1f0830e3c73bcf3e35e93a2f0d22e6 (diff)
Expand to powers of 2
Diffstat (limited to 'ber/bitstring.go')
-rw-r--r--ber/bitstring.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/ber/bitstring.go b/ber/bitstring.go
index 7e0fd93..eabc354 100644
--- a/ber/bitstring.go
+++ b/ber/bitstring.go
@@ -54,9 +54,17 @@ func (bs BitString) IsSet(n int) bool {
return bs[n]
}
+func pow2(n int) int {
+ i := 1
+ for i < n+1 {
+ i <<= 1
+ }
+ return i
+}
+
func (bs *BitString) Set(n int) {
if len(*bs) < n {
- nbs := make(BitString, n+1)
+ nbs := make(BitString, pow2(n))
copy(nbs, *bs)
*bs = nbs
}
@@ -65,7 +73,7 @@ func (bs *BitString) Set(n int) {
func (bs *BitString) Clear(n int) {
if len(*bs) < n {
- nbs := make(BitString, n+1)
+ nbs := make(BitString, pow2(n))
copy(nbs, *bs)
*bs = nbs
}