An ordered set of things
{OrderedSet} implements set behavior and keeps track of the order in which entries were added.
{OrderedSet} allows to inject a class that implements {OrderedSet::Cache::API} at construction time, and will use that cache implementation to enforce set semantics and perform internal caching of insertion order.
@see OrderedSet::Cache::API @see OrderedSet::Cache @see SubjectSet::NameCache
@api private
This set’s entries
The order in this Array is not guaranteed to be the order in which the entries were inserted. Use # to access the entries in insertion order.
@return [Array]
this set's entries
@api private
Initialize an OrderedSet
@param [#] entries
the entries to initialize this set with
@param [Class
the cache implementation to use
@api private
# File lib/dm-core/support/ordered_set.rb, line 218 218: def initialize(entries = [], cache = Cache) 219: @cache = cache.new 220: @entries = [] 221: merge(entries.to_ary) 222: end
Add or update an entry in the set
If the entry to add isn’t part of the set already, it will be added. If an entry with the same cache key as the entry to add is part of the set already, it will be replaced with the given entry.
@param [Object] entry
the entry to be added
@return [OrderedSet] self
@api private
# File lib/dm-core/support/ordered_set.rb, line 258 258: def <<(entry) 259: if index = @cache[entry] 260: entries[index] = entry 261: else 262: @cache[entry] = size 263: entries << entry 264: end 265: self 266: end
Get the entry at the given index
@param [Integer] index
the index of the desired entry
@return [Object, nil]
the entry at the given index, or nil if no entry is present
@api private
# File lib/dm-core/support/ordered_set.rb, line 241 241: def [](index) 242: entries[index] 243: end
Removes all entries and returns self
@return [OrderedSet] self
@api private
# File lib/dm-core/support/ordered_set.rb, line 301 301: def clear 302: @cache.clear 303: entries.clear 304: self 305: end
Delete an entry from this OrderedSet
@param [Object] entry
the entry to delete
@return [Object, nil]
the deleted entry or nil
@api private
# File lib/dm-core/support/ordered_set.rb, line 290 290: def delete(entry) 291: if index = @cache.delete(entry) 292: entries.delete_at(index) 293: end 294: end
Iterate over each entry in the set
@yield [entry]
all entries in the set
@yieldparam [Object] entry
an entry in the set
@return [OrderedSet] self
@api private
# File lib/dm-core/support/ordered_set.rb, line 318 318: def each 319: entries.each { |entry| yield(entry) } 320: self 321: end
Check if there are any entries
@return [Boolean]
true if the set is empty
@api private
# File lib/dm-core/support/ordered_set.rb, line 339 339: def empty? 340: entries.empty? 341: end
Check if the entry exists in the set
@param [Object] entry
the entry to test for
@return [Boolean]
true if entry is included in the set
@api private
# File lib/dm-core/support/ordered_set.rb, line 352 352: def include?(entry) 353: entries.include?(entry) 354: end
Return the index for the entry in the set
@param [Object] entry
the entry to check the set for
@return [Integer, nil]
the index for the entry, or nil if it does not exist
@api private
# File lib/dm-core/support/ordered_set.rb, line 365 365: def index(entry) 366: @cache[entry] 367: end
Initialize a copy of OrderedSet
@api private
# File lib/dm-core/support/ordered_set.rb, line 227 227: def initialize_copy(*) 228: @cache = @cache.dup 229: @entries = @entries.dup 230: end
Merge with another Enumerable object
@param [#] other
the Enumerable to merge with this OrderedSet
@return [OrderedSet] self
@api private
# File lib/dm-core/support/ordered_set.rb, line 276 276: def merge(other) 277: other.each { |entry| self << entry } 278: self 279: end
The number of entries
@return [Integer]
the number of entries
@api private
# File lib/dm-core/support/ordered_set.rb, line 329 329: def size 330: entries.size 331: end
Convert the OrderedSet into an Array
@return [Array]
an array containing all the OrderedSet's entries
@api private
# File lib/dm-core/support/ordered_set.rb, line 375 375: def to_ary 376: entries 377: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.