class Concurrent::LockFreeStack

@!macro warn.edge

def self.of1(value)

@!visibility private
def self.of1(value)
  new Node[value, EMPTY]
end

def self.of2(value1, value2)

@!visibility private
def self.of2(value1, value2)
  new Node[value1, Node[value2, EMPTY]]
end

def clear

Returns:
  • (true, false) -
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

def clear_each(&block)

Other tags:
    Yieldparam: value -

Other tags:
    Yield: - over the cleared stack

Returns:
  • (self) -
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

def clear_if(head)

Returns:
  • (true, false) -

Parameters:
  • head (Node) --
def clear_if(head)
  compare_and_set_head head, EMPTY
end

def compare_and_clear(head)

Returns:
  • (true, false) -

Parameters:
  • head (Node) --
def compare_and_clear(head)
  compare_and_set_head head, EMPTY
end

def compare_and_pop(head)

Returns:
  • (true, false) -

Parameters:
  • head (Node) --
def compare_and_pop(head)
  compare_and_set_head head, head.next_node
end

def compare_and_push(head, value)

Returns:
  • (true, false) -

Parameters:
  • value (Object) --
  • head (Node) --
def compare_and_push(head, value)
  compare_and_set_head head, Node[value, head]
end

def each(head = nil)

Returns:
  • (self) -

Parameters:
  • head (Node) --
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

def empty?(head = head())

Returns:
  • (true, false) -

Parameters:
  • head (Node) --
def empty?(head = head())
  head.equal? EMPTY
end

def initialize(head = EMPTY)

Parameters:
  • head (Node) --
def initialize(head = EMPTY)
  super()
  self.head = head
end

def peek

Returns:
  • (Node) -
def peek
  head
end

def pop

Returns:
  • (Object) -
def pop
  while true
    current_head = head
    return current_head.value if compare_and_set_head current_head, current_head.next_node
  end
end

def push(value)

Returns:
  • (self) -

Parameters:
  • value (Object) --
def push(value)
  while true
    current_head = head
    return self if compare_and_set_head current_head, Node[value, current_head]
  end
end

def replace_if(head, new_head)

Returns:
  • (true, false) -

Parameters:
  • new_head (Node) --
  • head (Node) --
def replace_if(head, new_head)
  compare_and_set_head head, new_head
end

def to_s

Returns:
  • (String) - Short string representation.
def to_s
  format '%s %s>', super[0..-2], to_a.to_s
end