Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

djb's "critbit" trees are much more interesting, I think: They are basically binary patricia trees (like nedtries, if I understand correctly). However, djb's observation is that in order to locate a specific string, you only have to look at the "critical" bits - the bits that are different between different entries in the database.

So, for example, if key 1 differs from key 2 (top two keys in the tree) in bit 317, you check bit 317, and you know which one of them it is NOT (and also, which branch of the tree it is not). Proceed recursively -- most keys will, in practice, be identified by log2(n) bits where n is the number of keys in the table, NOT the length of the key.



For the record, patricia tries in the literature are defined to have this "critbit" property. The wikipedia article on that subject is a little broken, but djb's article is correct when it states:

"This idea was introduced by Morrison in 1968 under the name PATRICIA, and independently by Gwehenberger at about the same time."


Also, I found this link to be a good reading for anyone interested in the implementation detail: https://github.com/agl/critbit/blob/master/critbit.w


The structure discussed at the link also shares this property, but only at the root of the trie (if I understand the code correctly... my c is relatively weak and it's written in a preprocessor heavy style I find hard to follow).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: