Class: MarkovTextGenerator::Api::Utils::DataStructures::LinkedList::Impl
- Inherits:
-
Object
- Object
- MarkovTextGenerator::Api::Utils::DataStructures::LinkedList::Impl
show all
- Includes:
- Enumerable, Errors
- Defined in:
- lib/markov_text_generator/api/utils/data_structures/linked_list/impl.rb
Constant Summary
Constants included
from Errors
Errors::Error, Errors::HaveNoIdeaError, Errors::UnknownLinkedListType
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Impl
Returns a new instance of Impl.
11
12
13
14
15
16
|
# File 'lib/markov_text_generator/api/utils/data_structures/linked_list/impl.rb', line 11
def initialize
@head = nil
@tail = nil
@length = 0
@op_counter = 0
end
|
Instance Attribute Details
#length ⇒ Object
Returns the value of attribute length.
9
10
11
|
# File 'lib/markov_text_generator/api/utils/data_structures/linked_list/impl.rb', line 9
def length
@length
end
|
Instance Method Details
#each(&block) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/markov_text_generator/api/utils/data_structures/linked_list/impl.rb', line 34
def each(&block)
next_node = @head
nodes = []
while next_node
nodes << next_node
next_node = next_node.succ
end
nodes.each(&block)
end
|
#first ⇒ Object
26
27
28
|
# File 'lib/markov_text_generator/api/utils/data_structures/linked_list/impl.rb', line 26
def first
@head ? @head.dup : fail_index_error
end
|
#last ⇒ Object
30
31
32
|
# File 'lib/markov_text_generator/api/utils/data_structures/linked_list/impl.rb', line 30
def last
@tail ? @tail.dup : fail_index_error
end
|
#push(data) ⇒ Object
22
23
24
|
# File 'lib/markov_text_generator/api/utils/data_structures/linked_list/impl.rb', line 22
def push(data)
link_tail_node data
end
|
#unshift(data) ⇒ Object
18
19
20
|
# File 'lib/markov_text_generator/api/utils/data_structures/linked_list/impl.rb', line 18
def unshift(data)
link_head_node data
end
|