Search code examples
cbinary-treebit-manipulationtriepatricia-trie

what the author of nedtries means by "in-place"?



I. Just implemented a kind of bitwise trie (based on nedtries), but my code does lot Of memory allocation (for each node). Contrary to my implemetation, nedtries are claimed to be fast , among othet things, Because of their small number of memory allocation (if any). The author claim his implementation to be "in-place", but what does it really means in this context ? And how does nedtries achieve such a small number of dynamic memory allocation ?

Ps: I know that the sources are available, but the code is pretty hard to follow and I cannot figure how it works


Solution

  • I took a look at the nedtrie.h source code. It seems that the reason it is "in-place" is that you have to add the trie bookkeeping data to the items that you want to store.

    You use the NEDTRIE_ENTRY macro to add parent/child/next/prev links to your data structure, and you can then pass that data structure to the various trie routines, which will extract and use those added members.

    So it is "in-place" in the sense that you augment your existing data structures and the trie code piggybacks on that.

    At least that's what it looks like. There's lots of macro goodness in that code so I could have gotten myself confused (: