Class: Yardstick::OrderedSet
- Inherits:
-
Object
- Object
- Yardstick::OrderedSet
- Includes:
- Enumerable
- Defined in:
- lib/yardstick/ordered_set.rb
Overview
A base class for an ordered set
Direct Known Subclasses
Instance Method Summary collapse
-
#<<(entry) ⇒ Yardstick::OrderedSet
private
Append to the OrderedSet.
-
#each {|entry| ... } ⇒ Yardstick::OrderedSet
private
Iterate over each entry.
-
#empty? ⇒ Boolean
private
Check if there are any entries.
-
#include?(entry) ⇒ Boolean
private
Check if the entry exists in the set.
-
#index(entry) ⇒ Integer?
private
Return the index for the entry in the set.
-
#initialize(entries = nil) ⇒ Yardstick::OrderedSet
constructor
private
Returns the OrderedSet instance.
-
#length ⇒ Integer
private
The number of entries.
-
#merge(other) ⇒ Yardstick::OrderedSet
private
Merge in another OrderedSet.
Constructor Details
#initialize(entries = nil) ⇒ Yardstick::OrderedSet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the OrderedSet instance
17 18 19 20 21 |
# File 'lib/yardstick/ordered_set.rb', line 17 def initialize(entries = nil) @entries = [] @index = {} merge(entries || []) end |
Instance Method Details
#<<(entry) ⇒ Yardstick::OrderedSet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Append to the OrderedSet
32 33 34 35 36 37 38 |
# File 'lib/yardstick/ordered_set.rb', line 32 def <<(entry) unless include?(entry) @index[entry] = @entries.length @entries << entry end self end |
#each {|entry| ... } ⇒ Yardstick::OrderedSet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Iterate over each entry
66 67 68 69 |
# File 'lib/yardstick/ordered_set.rb', line 66 def each(&block) @entries.each(&block) self end |
#empty? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if there are any entries
77 78 79 |
# File 'lib/yardstick/ordered_set.rb', line 77 def empty? @entries.empty? end |
#include?(entry) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if the entry exists in the set
100 101 102 |
# File 'lib/yardstick/ordered_set.rb', line 100 def include?(entry) @index.key?(entry) end |
#index(entry) ⇒ Integer?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the index for the entry in the set
113 114 115 |
# File 'lib/yardstick/ordered_set.rb', line 113 def index(entry) @index[entry] end |
#length ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The number of entries
87 88 89 |
# File 'lib/yardstick/ordered_set.rb', line 87 def length @entries.length end |
#merge(other) ⇒ Yardstick::OrderedSet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Merge in another OrderedSet
49 50 51 52 |
# File 'lib/yardstick/ordered_set.rb', line 49 def merge(other) other.each { |entry| self << entry } self end |