The second item thus become the first.
var a = [1,2,3]
assert a.shift == 1
assert a.shift == 2
assert a == [3]
REQUIRE not is_empty
redef fun shift
do
assert not_empty
var node = head_node
while node.length == 0 do
# Delete empty node
var nullable_node = node.next
assert is_not_empty: nullable_node != null
node = nullable_node
node.prev = null
self.head_node = node
end
var item = node.items[node.head_index]
node.head_index += 1
length -= 1
return item
end
lib/more_collections/more_collections.nit:502,2--520,4
# If empty, blocks until an item is inserted with `push` or `unshift`
redef fun shift do
mutex.lock
if real_collection.is_empty then
actor.working = false
sys.active_actors.decrement
while real_collection.is_empty do self.cond.wait(mutex)
end
var r = real_collection.shift
mutex.unlock
return r
end
lib/actors/actors.nit:99,2--110,4