Ceasar / trees

Collection of various tree data structures.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

trees

https://badge.fury.io/py/trees.png

Collection of various tree data structures.

Installation

To install trees, simply:

$ pip install trees

AutovivifiedDict

An AutovivifiedDict automatically creates new AutovividedDicts if user looks for a missing key. The result is that you can chain together a bunch of keys to store data more easily.

>>> import trees
>>> d = trees.AutovivifiedDict()
>>> d[1][2][3] = 4
>>> d
{1: {2: {3: 4}}

ObjectifiedDict

An ObjectifiedDict provides a wrapper for dictionaries that allows interaction through object notation. Though not really a tree, an ObjectifiedDict is frequently useful when dealing with trees.

>>> import trees
>>> d = {'foo': 1, 'bar': {'red': True}}
>>> od = trees.ObjectifiedDict(d)
>>> od
{'foo': 1, 'bar': {'red': True}}
>>> od["foo"]
1
>>> od.foo
1
>>> od.bar.red
True
>>> od.car = 1
>>> od
{'foo': 1, 'bar': {'red': True}, 'car': 1}
>>> od.car
1

heap

A heap is a data structure that satisfies the heap property: If A is a parent node of B, then key(A) < key(B). Thus, heaps will always be sorted from smallest to largest.

>> import trees
>>> h = trees.heap()
>>> h.push(1)
>>> h.push(3)
>>> h.push(2)
>>> h.top
1
>>> h.pop()
1
>>> h.top
2
>>> h.pop()
2
>>> h.pop()
3
>>> h.empty
True

About

Collection of various tree data structures.

License:MIT License


Languages

Language:Python 100.0%