class Concurrent::LockFreeStack
@!macro warn.edge
Constants
- EMPTY
The singleton for empty node
Public Class Methods
new(head = EMPTY)
click to toggle source
@param [Node] head
Calls superclass method
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 49 def initialize(head = EMPTY) super() self.head = head end
of1(value)
click to toggle source
@!visibility private
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 39 def self.of1(value) new Node[value, EMPTY] end
of2(value1, value2)
click to toggle source
@!visibility private
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 44 def self.of2(value1, value2) new Node[value1, Node[value2, EMPTY]] end
Public Instance Methods
clear()
click to toggle source
@return [true, false]
# File 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(&block)
click to toggle source
@return [self] @yield over the cleared stack @yieldparam [Object] value
# File 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)
click to toggle source
@param [Node] head @return [true, false]
# File 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)
click to toggle source
@param [Node] head @return [true, false]
# File 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)
click to toggle source
@param [Node] head @return [true, false]
# File 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)
click to toggle source
@param [Node] head @param [Object] value @return [true, false]
# File 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) { |value| ... }
click to toggle source
@param [Node] head @return [self]
# File 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())
click to toggle source
@param [Node] head @return [true, false]
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 56 def empty?(head = head()) head.equal? EMPTY end
peek()
click to toggle source
@return [Node]
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 77 def peek head end
pop()
click to toggle source
@return [Object]
# File 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)
click to toggle source
@param [Object] value @return [self]
# File 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)
click to toggle source
@param [Node] head @param [Node] new_head @return [true, false]
# File 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()
click to toggle source
@return [String] Short string representation.
Calls superclass method
# File 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
Also aliased as: inspect