tags:

views:

116

answers:

1

Which open source implementations of a tree (with arbitrary number of children per node; nodes containing a small data type like int or a pointer (additional to the implementation-specific indexing data, of course)) in a (linear) buffer do exist? (Obviously, the maximum number of tree nodes is bounded by the buffer size)

(Graph instead of tree would also be okay).

A: 

You can take any implementation of a tree that allows a stateful allocator, and implement a custom allocator on top of your fixed size buffer.

Though the C++ standard doesn't guarantee support for stateful allocators, they work "with most STL implementations most of the time". Allocator state is usually only a problem when moving nodes between containers.

If you can live with one instance, the buffer can also be a template parameter.

peterchen
nategoose
bk1e
a custom allocator could be designed to use indices as pointers, though I'm not sure if an STL allocator can do that.
peterchen
@bk1e: Um... I am embarrassed. Yes, I meant _unary_.
nategoose