Implementing a persistent data structure in C works basically the same as in a functional language. Chris Okasaki Purely functional data structures are a great recommendation.
In the general case, it is enough to compare fixed-width integers for objects, since while this does not give you a complete dictionary on its own, you can build the dictionary from above: use the hash of the actual key as the key of the base map, and the leaves indicate the lists (key , value) pairs of the same hash value.
The tricky part is memory management, because you usually donโt know when parts of the data structure become inaccessible. Fortunately, since most robust data structures are tree-based, link counting usually works well. To be able to manage the objects referenced by the data structure, you can provide a hook for callbacks that are called when the node link list becomes 0.
For example, my Patricia Trees bitmap C implementation provides the following API:
may give you some ideas.
Matthias benkard
source share