k-sone / critbitgo

crit-bit for golang and its applications (sorted map, IP routing table)
MIT License
45 stars 14 forks source link

Allprefixed() incorrectly matches keys #4

Closed aletheia7 closed 7 years ago

aletheia7 commented 7 years ago

Allpfrefixed() incorrectly matches keys.

Example

package main

import (
    "log"
    "github.com/k-sone/critbitgo"
)

func main() {
        log.SetFlags(0)
        trie := critbitgo.NewTrie()
        trie.Insert([]byte("/ctrl_ready"), 1)
        trie.Insert([]byte("/router_message"), 2)
        trie.Insert([]byte("/router_ready"), 3)
        key := []byte("/router_message")
        trie.Allprefixed(key, func(key []byte, value interface{}) bool {
                log.Printf("Allprefixed: %s %v", key, value)
                return true
        })
}

Example Output

Allprefixed: /router_message 2
Allprefixed: /router_ready 3

Expected Output

Allprefixed: /router_message 2
k-sone commented 7 years ago

Thanks for the report!