lib/circular_queue.rb in circular_queue-0.0.1 vs lib/circular_queue.rb in circular_queue-0.0.2
- old
+ new
@@ -17,12 +17,12 @@
# q << 1 # => [1]
# q << 2 # => [1, 2]
# q << 3 # => [1, 2, 3]
#
# # Elements are replaced when the queue reaches capacity
-# q << 4 # => [4, 2, 3]
-# q << 5 # => [4, 5, 3]
+# q << 4 # => [2, 3, 4]
+# q << 5 # => [3, 4, 5]
class CircularQueue
# Returns the maximum number of elements that can be enqueued
# @return [Integer]
attr_reader :capacity
@@ -30,11 +30,11 @@
# @return [Integer]
attr_reader :size
alias length size
# Creates a new queue of the specified capacity
- # @param [Integer] the maximum capacity of the queue
+ # @param [Integer] capacity the maximum capacity of the queue
def initialize(capacity)
@capacity = capacity
@data = Array.new(capacity)
@mutex = Mutex.new
@@ -42,22 +42,22 @@
clear
end
# Adds an item to the queue
- # @param [Object] item to add
+ # @param [Object] item item to add
def enq(item)
@mutex.synchronize do
enq_item(item)
wakeup_next_waiter
end
end
alias << enq
alias push enq
# Adds an item to the queue, raising an error if the queue is full
- # @param [Object] item to add
+ # @param [Object] item item to add
# @raise [ThreadError] queue is full
def enq!(item)
@mutex.synchronize do
raise ThreadError.new("Queue is full") if full?
@@ -66,11 +66,11 @@
end
end
alias push! enq!
# Removes an item from the queue
- # @param [Boolean] true to raise an error if the queue is empty; otherwise,
- # waits for an item to arrive from another thread
+ # @param [Boolean] non_block true to raise an error if the queue is empty;
+ # otherwise, waits for an item to arrive from another thread
# @raise [ThreadError] non_block was true and the queue was empty
def deq(non_block = false)
@mutex.synchronize do
while true
if empty?