plar / go-adaptive-radix-tree

Adaptive Radix Trees implemented in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question:how to terminate the ForEachPrefix function after running for a given times

SwaggieHu opened this issue · comments

I set the return value false in the callback function after running for a given times but it doesn't work , quite confused

code:
tree := art.New()
tree.Insert(art.Key("America#California#Irvine"), 1)
tree.Insert(art.Key("America#California#Sanfrancisco"), 2)
tree.Insert(art.Key("America#California#LosAngeles"), 3)

cnt := 0

tree.ForEachPrefix(art.Key("Amer"), func(node art.Node) (cont bool) {
	fmt.Println(node.Value())
	cnt += 1
	if cnt > 2 {
		return false
	}
	return true
})

problem: it is supposed to print and 1 since I return false when cnt = 2, but the result is ,1,3,2

Thanks for the bug report, nice catch! The bug has been fixed.

Thanks! Looks like you've made a bunch of fixes, improvements and new release! 🎉 I will have to work on integrating your changes into Bitcask and making a new version there too! Thanks for maintaining this nice library!