Sha256: 7c59a32b71623209211a085b8bc3f74eb41b025374c6e883b7b4dbe0fe07c32f

Contents?: true

Size: 563 Bytes

Versions: 3

Compression:

Stored size: 563 Bytes

Contents

require 'forwardable'
require 'hamster/queue'
require 'hamster/experimental/read_copy_update'

module Hamster

  def self.mutable_queue(*items)
    MutableQueue.new(queue(*items))
  end

  class MutableQueue

    extend Forwardable

    include ReadCopyUpdate

    def enqueue(item)
      transform { |queue| queue.enqueue(item) }
    end
    def_delegate :self, :enqueue, :<<
    def_delegate :self, :enqueue, :add

    def dequeue
      head = nil
      transform { |queue|
        head = queue.head
        queue.dequeue
      }
      head
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hamster-0.4.3 lib/hamster/experimental/mutable_queue.rb
hamster-0.4.2 lib/hamster/experimental/mutable_queue.rb
hamster-0.4.0 lib/hamster/experimental/mutable_queue.rb