sparsearray.rb

Path: lib/hashery/sparsearray.rb
Last Update: Tue Apr 05 12:31:31 -0400 2011

SparseArray

SparseArray is an implemenation of the Array class using only Hashes. Regular Arrays are never used except once to delegate the pack method, (and *args parameters of course). SparseArray is almost fully compatible with Array. There are still a few missing methods that came in with Ruby 1.9 that need to be added, and negative indexes are not quite fully supported yet.

Benchmarks comparing Ruby 1.6 circa 2004 compared to Ruby 1.8.7 circa 2010, show that Ruby‘s Array implementation has improved quite a bit. Where as Array was about 2-4 times faster than SparseArray in 2004, it is now over 10x faster, and able to handle large sparse arrays quite easily. Though surely SparseArray could still be improved, SparseArray is little more than an interesting novelty at this point, as opposed to a useful class, but we will keep her nonetheless for simple interests sake.

NOTE: SparseArray is also the first piece of code I used TDD to create.

Copyright (c) 2004 Thomas Sawyer

[Validate]