An executable spec, benchmark and reference implementation for persistent Ruby data structure.
See issues for discussion about standardized interfaces.
The first data type under scrutiny is the persistent vector.
- Persistent::Vector A Java-native implementation for JRuby
- Hamster::Vector A pure ruby implementation
- Clojr::Persistent::Vector A wrapper around Clojure's PersitentVector
Included is also
RubyData::PersistentVector, a pure Ruby "simplest thing that could possibly work" implementation.
The proposed spec so far, for all persistent collections:
CollectionClass[1,2,3]creates a new collection containing the given items.
inspectreturns a similar representation,
eql?checks for type and content, e.g.
Vector[1,2,3].eql?([1,2,3]) #=> false,
Vector[1,2,3].eql?(Vector[1,2,3]) #=> true
==should follow Ruby type coercion rules, e.g. for vectors or lists it should call
to_aryon an object that implements it.
Vector[1,2,3] == [1,2,3] #=> true. Similarly a map should check for
addadds an element to the collection in the most efficient way. For a cons-based list this means adding it to the front, for a vector it would add it to the back.
Other methods that should be implemented with the usual semantics: 'include?', 'each'.
In addition to the above, list-like data types like vectors or lists, should implement the following:
to_ary, returning a plain Ruby array
In addition to all of the above, vectors should implement the following:
vector.append(4) #=> Vector[1,2,3,4]
vector.prepend(4) #=> Vector[4,1,2,3]
Currently implementing specs for the above, and preparing pull requests for the various projects to make them conforming.