Like Set except it maintains the order of objects
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.rbenv-gemsets
.rbenv-version
Gemfile
LICENSE
README.rdoc
Rakefile
VERSION
ordered_set.gemspec

README.rdoc

OrderedSet

OrderSet is an class for storing sets of objects. Unlike a Set, it maintains the order of the objects, but unlike an Array, each object can only exist once, and checking for inclusion takes constant time.

Usage:

s = [1,3,2,3,4,3].to_ordered_set
s.to_a
# => [1,3,2,4]

t = OrderedSet.new([6,7,5,6,5])
t.to_a
# => [6,7,5]

(s + t).to_a
# => [1,3,2,4,6,7,5]

s << 5
s.to_a
# => [1,3,2,4,5]

s.delete(1)
s.to_a
# => [3,2,4,5]

Install:

sudo gem install ninjudd-deep_clonable -s http://gems.github.com
sudo gem install ninjudd-ordered_set -s http://gems.github.com

License:

Copyright © 2008 Justin Balthrop, Geni.com; Published under The MIT License, see LICENSE