InitIndex initializes index bitmap for an array. Index must be an ascending int32 slice, otherwise, it return the ErrIndexNotAscending error Since 0.2.0
(index []int32)
| 38 | // |
| 39 | // Since 0.2.0 |
| 40 | func (a *Base) InitIndex(index []int32) error { |
| 41 | |
| 42 | for i := 0; i < len(index)-1; i++ { |
| 43 | if index[i] >= index[i+1] { |
| 44 | return ErrIndexNotAscending |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | a.Bitmaps = bitmap.Of(index) |
| 49 | a.Offsets = bitmap.IndexRank64(a.Bitmaps) |
| 50 | a.Cnt = int32(len(index)) |
| 51 | |
| 52 | // Be compatible to previous issue: |
| 53 | // Since v0.2.0, Offsets is not exactly the same as bitmap ranks. |
| 54 | // It is 0 for empty bitmap word. |
| 55 | // But bitmap ranks set rank[i*64] to rank[(i-1)*64] for empty word. |
| 56 | for i, word := range a.Bitmaps { |
| 57 | if word == 0 { |
| 58 | a.Offsets[i] = 0 |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return nil |
| 63 | } |
| 64 | |
| 65 | // Init initializes an array from the "indexes" and "elts". |
| 66 | // The indexes must be an ascending int32 slice, |
no outgoing calls