mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-08 03:47:51 +00:00
replaced linear search with binary search in run container
This commit is contained in:
parent
ccef8be844
commit
6609120464
2 changed files with 15 additions and 12 deletions
|
|
@ -1337,18 +1337,22 @@ func (c *container) bitmapContains(v uint32) bool {
|
|||
return (c.bitmap[v/64] & (1 << uint64(v%64))) != 0
|
||||
}
|
||||
|
||||
func (c *container) runContains(v uint32) bool {
|
||||
// TODO binary search
|
||||
for _, iv := range c.runs {
|
||||
if v > iv.last {
|
||||
continue
|
||||
}
|
||||
if v < iv.start {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
//runBinSearch uses a binary search of the runs and returns the index of nearest
|
||||
//run.
|
||||
func runBinSearch(v uint32, a []interval32) (int, bool) {
|
||||
i := sort.Search(len(a),
|
||||
func(i int) bool { return a[i].last >= v })
|
||||
if i < len(a) {
|
||||
return i, (v >= a[i].start) && (v <= a[i].last)
|
||||
}
|
||||
return false
|
||||
|
||||
return i, false
|
||||
}
|
||||
|
||||
//runContains determines if v is in the containers run set.
|
||||
func (c *container) runContains(v uint32) bool {
|
||||
_, found := runBinSearch(v, c.runs)
|
||||
return found
|
||||
}
|
||||
|
||||
// remove removes a value from the container.
|
||||
|
|
|
|||
|
|
@ -360,7 +360,6 @@ func testBitmapQuick(t *testing.T, n int, min, max uint64) {
|
|||
}
|
||||
|
||||
// Remove all values in random order.
|
||||
fmt.Println(len(a))
|
||||
for _, i := range rand.Perm(len(a)) {
|
||||
removed, _ := bm.Remove(a[i])
|
||||
if removed {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue