go - Overlapping in treap package from stathat? -


according link stathat uses overlapping treap:

gollrb great , there's no reason should switch. thought idea behind treaps elegant solution our problem, implemented it. liked interface gollrb provided, mimicked in our implementation.

one thing added treap package allow iterate using overlap function, can keys in [3,9), example. use lot, struct key.

patrick

i playing following code , have no idea how continue:

package main  import(     "reflect"     "fmt"     "github.com/stathat/treap" )  func intless(p, q interface{}) bool {         return p.(int) < q.(int) }  func bucketoverlap(a, b interface{}) bool {     return false }  func main() {     tree := treap.newoverlaptree(intless, bucketoverlap)     tree.insert(5, "a")     tree.insert(7, "b")     tree.insert(2, "c")     tree.insert(1, "d")      v := range tree.iterateoverlap([]int{2,5}) {         fmt.printf("val: %v\n", v)     } } 

let's want keys in range [2,5] => [c,a]

the first place i'd start tests stathat treap code: https://github.com/stathat/treap/blob/master/treap_test.go#l164

it seems you're doing trying pass slice of keys when expecting single one. trying vector operations (i.e. range overlap) on value scalar (i.e. int).

maybe misunderstanding point of overlap, understanding use interval tree:

key1 := []int{1, 3} key2 := []int{2, 4} key3 := []int{5, 6} 

these intervals (low , high). key1 overlaps key2, , vice-versa. neither overlap key3. in case, overlap useful (i.e. iterateoverlap([]int{2,3}) give me key1 , key2, whereas iterateoverlap([]int{3,5}) return all).

i'm not sure how you'd iterate on these entries. maybe this:

for := 2; <= 5; i++ {   fmt.printf("val: %v\n", tree.get(i)) } 

again, i've not used implementation, forgive me if i'm barking wrong tree.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -