class FSArray

Fixed Size FIFO, LIFO, and Array.

Constants

FSARRAY_SIZE_DEFAULT

Public Class Methods

new( _size = FSARRAY_SIZE_DEFAULT, size: FSARRAY_SIZE_DEFAULT, of_enable: false, of_proc: Proc.new{ raise "Overflow!" }, uf_enable: false, uf_proc: Proc.new{ raise "Underflow!" }, push_enable: false, push_proc: Proc.new{}, wm_size: 1, wm_enable: false, wm_proc: Proc.new{ raise "Reached WM!" } ) click to toggle source

FSArray#new( n ) FSArray#new( size: n, of_enable: true, of_proc: Proc.new{…} )

Calls superclass method
# File lib/fsfifo.rb, line 18
def initialize( _size = FSARRAY_SIZE_DEFAULT,
                size: FSARRAY_SIZE_DEFAULT,
                of_enable: false, of_proc: Proc.new{ raise "Overflow!" },
                uf_enable: false, uf_proc: Proc.new{ raise "Underflow!" },
                push_enable: false, push_proc: Proc.new{},
                wm_size: 1,
                wm_enable: false, wm_proc: Proc.new{ raise "Reached WM!" }
              )

  raise "Watermark #{wm_size} is out of range[0,#{size}]" if
    wm_size < 0 or wm_size > size

  size = _size if _size != FSARRAY_SIZE_DEFAULT
  @opt = {
    :size    => size,
    :of_enable => of_enable,
    :of_proc => of_proc,
    :uf_enable => uf_enable,
    :uf_proc => uf_proc,
    :push_enable => push_enable, #TODO.
    :push_proc => push_proc,
    :wm_size => wm_size,
    :wm_enable => wm_enable,
    :wm_proc => wm_proc,
  }

  @shifted = nil  #TODO.

  #
  super( )

end

Public Instance Methods

fifosize() click to toggle source

FIFO and data size-related methods.

# File lib/fsfifo.rb, line 65
def fifosize; @opt[:size]; end
push( obj ) click to toggle source
# File lib/fsfifo.rb, line 93
def push( obj )

  #
  push_org( obj )

  #
  of_called = false
  wm_called = false
  while self.size > @opt[:size]
    #
    shift_org

    # overflow callback.
    if @opt[:of_enable] and not(of_called)
      @opt[:of_proc].call
      of_called = true
    end

    # TODO.watermark callback.
    if @opt[:wm_enable] and not(wm_called)
      @opt[:wm_proc].call
      wm_called = true
    else
      #raise ""
    end
  end

  return self
end
Also aliased as: push_org
push_org( obj )
Alias for: push
resize( n ) click to toggle source

Array#size indicates the number of elements in fifo.

# File lib/fsfifo.rb, line 67
def resize( n )
  ret = []
  @opt[:wm_size] = n if @opt[:size] == @opt[:wm_size]
  @opt[:size] = n
  ret << self.shift_org while self.size > n

  return ret
end
shift() click to toggle source

shift and push - main methods of FSFIFO.

# File lib/fsfifo.rb, line 83
def shift

  # callback method when under flow is enabled.
  @opt[:uf_proc].call if self.size == 0 and @opt[:uf_enable]

  ret = shift_org

  return ret
end
Also aliased as: shift_org
shift_org()
Alias for: shift