Project

order_tree

0.0
No commit activity in last 3 years
No release in over 3 years
Use OrderTree when you need both insertion order access and nested hash path style access
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

 Project Readme

#Ordered Tree

This is a nested hash / unbalance tree structure which iterates over all of its available values in insertion order.

##Like a Normal Hash?

Exactly like a normal hash. Althought with a standard Ruby Hash it's impossible to know whether or not hash["a"]["b"] was inserted before or after hash["b"]["c"] because each individual Hash maintains it's own insertion order.

Now you can know. If you need to. The main thing you gain with this over an Array is the ability to prune or transplant multiple values at the same time by cutting on one of the branches.

##Caveat

Each value is actually stored in a proxy object which maintains a unique id. This is necessary so that if you insert three 4s into the tree you can tell which one came first. This wouldn't actually be necessary in a C implementation, or in one based on WeakRefs, but it works okay here.

You can generally treat the OrderTree exactly like a nested hash, but be aware that the first and last methods (as well as the #each iterator) actually return an OrderTreeNode and not the actual object stored at that location. (You can get at it by using #orig on the returned value.