Class: Concurrent::LockFreeStack
- Inherits:
-
Synchronization::Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb
Overview
Note:
**Edge Features** are under active development and may change frequently.
-
Deprecations are not added before incompatible changes.
-
Edge version: major is always 0, minor bump means incompatible change, patch bump means compatible change.
-
Edge features may also lack tests and documentation.
-
Features developed in ‘concurrent-ruby-edge` are expected to move to `concurrent-ruby` when finalised.
Defined Under Namespace
Classes: Node
Constant Summary
collapse
- EMPTY =
The singleton for empty node
Node[nil, nil]
Instance Method Summary
collapse
Methods included from Enumerable
#as_json, #compact_blank, #exclude?, #excluding, #in_order_of, #including, #index_by, #index_with, #many?, #maximum, #minimum, #pick, #pluck, #sole, #sum
atomic_attribute?, atomic_attributes, attr_atomic, attr_volatile, ensure_safe_initialization_when_final_fields_are_present, safe_initialization!, safe_initialization?
Constructor Details
#initialize(head = EMPTY) ⇒ LockFreeStack
Returns a new instance of LockFreeStack.
49
50
51
52
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 49
def initialize(head = EMPTY)
super()
self.head = head
end
|
Instance Method Details
#clear ⇒ true, false
116
117
118
119
120
121
122
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 116
def clear
while true
current_head = head
return false if current_head == EMPTY
return true if compare_and_set_head current_head, EMPTY
end
end
|
#clear_each {|value| ... } ⇒ self
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 140
def clear_each(&block)
while true
current_head = head
return self if current_head == EMPTY
if compare_and_set_head current_head, EMPTY
each current_head, &block
return self
end
end
end
|
#clear_if(head) ⇒ true, false
126
127
128
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 126
def clear_if(head)
compare_and_set_head head, EMPTY
end
|
#compare_and_clear(head) ⇒ true, false
97
98
99
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 97
def compare_and_clear(head)
compare_and_set_head head, EMPTY
end
|
#compare_and_pop(head) ⇒ true, false
83
84
85
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 83
def compare_and_pop(head)
compare_and_set_head head, head.next_node
end
|
#compare_and_push(head, value) ⇒ true, false
63
64
65
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 63
def compare_and_push(head, value)
compare_and_set_head head, Node[value, head]
end
|
#each(head = nil) ⇒ self
105
106
107
108
109
110
111
112
113
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 105
def each(head = nil)
return to_enum(:each, head) unless block_given?
it = head || peek
until it.equal?(EMPTY)
yield it.value
it = it.next_node
end
self
end
|
#empty?(head = head()) ⇒ true, false
56
57
58
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 56
def empty?(head = head())
head.equal? EMPTY
end
|
77
78
79
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 77
def peek
head
end
|
88
89
90
91
92
93
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 88
def pop
while true
current_head = head
return current_head.value if compare_and_set_head current_head, current_head.next_node
end
end
|
#push(value) ⇒ self
69
70
71
72
73
74
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 69
def push(value)
while true
current_head = head
return self if compare_and_set_head current_head, Node[value, current_head]
end
end
|
#replace_if(head, new_head) ⇒ true, false
133
134
135
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 133
def replace_if(head, new_head)
compare_and_set_head head, new_head
end
|
#to_s ⇒ String
Also known as:
inspect
Returns Short string representation.
152
153
154
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 152
def to_s
format '%s %s>', super[0..-2], to_a.to_s
end
|