Question:how to terminate the ForEachPrefix function after running for a given times
SwaggieHu opened this issue · 4 comments
SwaggieHu commented
I set the return value false in the callback function after running for a given times but it doesn't work , quite confused
plar commented
Please provide a simple test case with the problem.
…On Tue, Aug 11, 2020, 03:22 SwaggieHu ***@***.***> wrote:
I set the return value false in the callback function after running for a
given times but it doesn't work , quite confused
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#14>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAARYI46OPQ2OJELOEWOUWLSAELVFANCNFSM4P24EXYA>
.
SwaggieHu commented
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
plar commented
Thanks for the bug report, nice catch! The bug has been fixed.