k-sone / critbitgo

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

What does LongestPrefix do? #6

Closed aletheia7 closed 7 years ago

aletheia7 commented 7 years ago

If I Insert() the following keys:

/hi/bye/why
/hi/bye
/hi

LongestPrefix(/hi) will output /hi. I am expecting /hi/bye/why from the description.

Why is /hi the longest prefix?

k-sone commented 7 years ago

This is what I intended. Returns the key that following conditions:

Examples:

LongestPrefix("/hi")                 // Output: "/hi"
LongestPrefix("/hi/hoge")            // Output: "/hi"
LongestPrefix("/hi/bye/hoge")        // Output: "/hi/bye"
LongestPrefix("/hi/bye/why/hoge")    // Output: "/hi/bye/why"
aletheia7 commented 7 years ago

Thanks