Class: DS::HeapStore
- Inherits:
-
Object
- Object
- DS::HeapStore
- Extended by:
- Forwardable
- Defined in:
- lib/ds/arrays/heap_store.rb
Overview
Simple Array-like data structure with indexing starting from one.
Direct Known Subclasses
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #first ⇒ Object
-
#initialize(*args) ⇒ HeapStore
constructor
A new instance of HeapStore.
- #length ⇒ Object (also: #size)
- #swap(x, y) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(*args) ⇒ HeapStore
Returns a new instance of HeapStore.
10 11 12 |
# File 'lib/ds/arrays/heap_store.rb', line 10 def initialize(*args) @store = [nil] + args.to_a end |
Instance Method Details
#empty? ⇒ Boolean
24 25 26 |
# File 'lib/ds/arrays/heap_store.rb', line 24 def empty? length <= 0 end |
#first ⇒ Object
18 19 20 |
# File 'lib/ds/arrays/heap_store.rb', line 18 def first @store[1] end |
#length ⇒ Object Also known as: size
14 15 16 |
# File 'lib/ds/arrays/heap_store.rb', line 14 def length @store.size - 1 end |
#swap(x, y) ⇒ Object
32 33 34 35 36 |
# File 'lib/ds/arrays/heap_store.rb', line 32 def swap(x, y) temp = self[y] self[y] = self[x] self[x] = temp end |
#to_a ⇒ Object
28 29 30 |
# File 'lib/ds/arrays/heap_store.rb', line 28 def to_a @store[1..-1] end |