Class: FSArray
- Inherits:
-
Array
- Object
- Array
- FSArray
- Defined in:
- lib/fsfifo.rb
Overview
Fixed Size FIFO, LIFO, and Array.
Instance Method Summary collapse
-
#fifosize ⇒ Object
FIFO and data size-related methods.
-
#initialize(args = {}) ⇒ FSArray
constructor
FSArray#new( n ) FSArray#new( size: n, of_enbl: true, of_proc: Proc.new… ).
- #of_disable ⇒ Object
- #of_enable ⇒ Object
- #of_enable? ⇒ Boolean
-
#of_proc ⇒ Object
Over/underflow callback methods getter/setter, etc.
- #of_proc=(newp) ⇒ Object
- #push(obj) ⇒ Object
- #push_org ⇒ Object
-
#resize(n) ⇒ Object
Array#size indicates the number of elements in fifo.
-
#shift ⇒ Object
shift and push - main methods of FSFIFO.
- #shift_org ⇒ Object
- #uf_disable ⇒ Object
- #uf_enable ⇒ Object
- #uf_enable? ⇒ Boolean
- #uf_proc ⇒ Object
- #uf_proc=(newp) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ FSArray
FSArray#new( n ) FSArray#new( size: n, of_enbl: true, of_proc: Proc.new… )
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fsfifo.rb', line 17 def initialize( args = {} ) if args.class == Fixnum args = { size: args, wm_size: args } end @opt = { :size => 1, :of_enbl => false, :of_proc => Proc.new{}, :uf_enbl => false, :uf_proc => Proc.new{}, :push_enbl => false, #TODO. :push_proc => Proc.new{}, :wm_size => 1, :wm_enbl => false, :wm_proc => Proc.new{}, }.merge( args ) @shifted = nil #TODO. # super( ) end |
Instance Method Details
#fifosize ⇒ Object
FIFO and data size-related methods.
61 |
# File 'lib/fsfifo.rb', line 61 def fifosize; @opt[:size]; end |
#of_disable ⇒ Object
49 |
# File 'lib/fsfifo.rb', line 49 def of_disable; @opt[:of_enbl] = false; end |
#of_enable ⇒ Object
48 |
# File 'lib/fsfifo.rb', line 48 def of_enable; @opt[:of_enbl] = true; end |
#of_enable? ⇒ Boolean
50 |
# File 'lib/fsfifo.rb', line 50 def of_enable?; @opt[:of_enbl] ; end |
#of_proc ⇒ Object
Over/underflow callback methods getter/setter, etc.
46 |
# File 'lib/fsfifo.rb', line 46 def of_proc; @opt[:of_proc]; end |
#of_proc=(newp) ⇒ Object
47 |
# File 'lib/fsfifo.rb', line 47 def of_proc=( newp ); @opt[:of_proc] = newp; end |
#push(obj) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/fsfifo.rb', line 92 def push( obj ) # push_org( obj ) # of_called = false wm_called = false while self.size > @opt[:size] # shift_org # overflow callback. if @opt[:of_enbl] and not(of_called) @opt[:of_proc].call of_called = true end # TODO.watermark callback. if @opt[:wm_enbl] and not(wm_called) @opt[:wm_proc].call wm_called = true else #raise "" end end return self end |
#push_org ⇒ Object
74 |
# File 'lib/fsfifo.rb', line 74 alias :push_org :push |
#resize(n) ⇒ Object
Array#size indicates the number of elements in fifo.
63 64 65 66 67 68 69 70 |
# File 'lib/fsfifo.rb', line 63 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 ⇒ Object
shift and push - main methods of FSFIFO.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/fsfifo.rb', line 79 def shift ret = shift_org # callback method when under flow is enabled. if self.size == 0 if @opt[:uf_enbl] @opt[:uf_proc].call end end return ret end |
#shift_org ⇒ Object
73 |
# File 'lib/fsfifo.rb', line 73 alias :shift_org :shift |
#uf_disable ⇒ Object
55 |
# File 'lib/fsfifo.rb', line 55 def uf_disable; @opt[:uf_enbl] = false; end |
#uf_enable ⇒ Object
54 |
# File 'lib/fsfifo.rb', line 54 def uf_enable; @opt[:uf_enbl] = true; end |
#uf_enable? ⇒ Boolean
56 |
# File 'lib/fsfifo.rb', line 56 def uf_enable?; @opt[:uf_enbl] ; end |
#uf_proc ⇒ Object
52 |
# File 'lib/fsfifo.rb', line 52 def uf_proc; @opt[:uf_proc]; end |
#uf_proc=(newp) ⇒ Object
53 |
# File 'lib/fsfifo.rb', line 53 def uf_proc=( newp ); @opt[:uf_proc] = newp; end |