[Python-ideas] A tree data structure for Python

Stephan Foley foley12723 at gmail.com
Thu Feb 18 20:53:04 EST 2016


Hi Andrew,

On Wed, Feb 17, 2016 at 2:51 PM, Andrew Barnert <abarnert at yahoo.com> wrote:
> It's not so much the overhead, as the design decisions. You need parent pointers; I not only don't need them, but need subtrees that don't keep their parents alive. I need threading, you don't want it, and don't want on do the log N work on each update to fix up the threads you're never going to use but the type demands them. You want first child and next sibling, I want all children. And so on. In most of there cases, there's no structure or API that's going to make us both happy.

I get what you're saying, but something simple like the C++ Boost
Property Tree might be general enough to be useful:

http://www.boost.org/doc/libs/1_60_0/doc/html/property_tree.html#property_tree.intro

> That's why a functional design works much better than an OO design for this particular problem. It's hard to explain in text, but easy to show in code, so check https://github.com/abarnert/treestuff

Ahhh....functional design....I'm going to hit my Scheme books :-)

In general, I only use OO for data and try to make everything else
functions. Classes work nicely to hold the pointers. Really, you can
also program a tree in a memory buffer with integer pointers as
offsets.


More information about the Python-ideas mailing list