clear()
click to toggle source
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
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
compare_and_clear(head)
click to toggle source
def compare_and_clear(head)
compare_and_set_head head, EMPTY
end
compare_and_pop(head)
click to toggle source
def compare_and_pop(head)
compare_and_set_head head, head.next_node
end
compare_and_push(head, value)
click to toggle source
def compare_and_push(head, value)
compare_and_set_head head, Node[value, head]
end
each(head = nil) { |value| ... }
click to toggle source
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?()
click to toggle source
def empty?
head.equal? EMPTY
end
peek()
click to toggle source
pop()
click to toggle source
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
def push(value)
while true
current_head = head
return self if compare_and_set_head current_head, Node[value, current_head]
end
end