Skip to content

Commit

Permalink
refactor: array: replace array functions with bitmap. see: http://git…
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Nov 23, 2020
1 parent 208e992 commit eab6e78
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions array/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"encoding/binary"
"reflect"

"math/bits"

"github.com/openacid/errors"
"github.com/openacid/low/bitmap"
"github.com/openacid/slim/encode"
Expand Down Expand Up @@ -104,17 +102,8 @@ func (a *Base) ExtendIndex(n int32) {
//
// Since 0.2.0
func (a *Base) GetEltIndex(idx int32) (int32, bool) {
iBm, iBit := bmBit(idx)

var bmWord = a.Bitmaps[iBm]

if ((bmWord >> uint(iBit)) & 1) == 0 {
return 0, false
}

base := a.Offsets[iBm]
cnt1 := bits.OnesCount64(bmWord & ((uint64(1) << uint(iBit)) - 1))
return base + int32(cnt1), true
r, b := bitmap.Rank64(a.Bitmaps, a.Offsets, idx)
return r, b == 1
}

// Has returns true if idx is in array, else return false.
Expand Down

0 comments on commit eab6e78

Please sign in to comment.