Class: Kibuvits_krl171bt4_arraycursor_t1
- Inherits:
-
Object
- Object
- Kibuvits_krl171bt4_arraycursor_t1
- Defined in:
- lib/kibuvits_ruby_library_krl171bt4_.rb
Overview
The Array.new.each {|array_element| do_something(array_element)} iterates over all elements of the array, but instances of this class allow to pause the iteration cycle and implement the “overflow” mechanism. For example, if ar is reached, it returns ar.
It allows to iterate to both directions, like 0,1,2,3 and 3,2,1,0.
Instance Attribute Summary collapse
-
#ar_core ⇒ Object
readonly
Returns the value of attribute ar_core.
Instance Method Summary collapse
-
#b_inited ⇒ Object
Explanation by example:.
-
#b_skip(x_array_element) ⇒ Object
This method is meant to be overridden.
-
#clear ⇒ Object
Description resides next to the method inc().
-
#dec ⇒ Object
Description resides next to the method inc().
-
#inc ⇒ Object
Throws or returns nil or an array element that the cursor points to.
-
#initialize(b_threadsafe = true) ⇒ Kibuvits_krl171bt4_arraycursor_t1
constructor
clear.
-
#ixs_low ⇒ Object
A single array element is selected by using 2 sindices: low and high.
-
#reset(ar_core) ⇒ Object
———————————————————————–.
Constructor Details
#initialize(b_threadsafe = true) ⇒ Kibuvits_krl171bt4_arraycursor_t1
clear
10582 10583 10584 10585 10586 10587 10588 10589 10590 10591 |
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10582 def initialize(b_threadsafe=true) if KIBUVITS_krl171bt4_b_DEBUG bn=binding() kibuvits_krl171bt4_typecheck bn, [TrueClass,FalseClass],b_threadsafe end # if KIBUVITS_krl171bt4_b_DEBUG @b_threadsafe=b_threadsafe @mx=nil @mx=Monitor.new if @b_threadsafe clear() end |
Instance Attribute Details
#ar_core ⇒ Object (readonly)
Returns the value of attribute ar_core.
10534 10535 10536 |
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10534 def ar_core @ar_core end |
Instance Method Details
#b_inited ⇒ Object
Explanation by example:
reset([“aa”,“bb”,“cc”); b_inited==true clear() b_inited==false
10762 10763 10764 |
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10762 def b_inited return @b_inited end |
#b_skip(x_array_element) ⇒ Object
This method is meant to be overridden. Methods inc() and dec() will skip all elements in the array, where this method returns true;
If all elements in the array are skipped, then the cursor position will not be changed and inc() and dec() will return nil. The dec() and inc() will avoid infinite loops by keeping track of the index accountancy. Code example:
ob_cursor=Kibuvits_krl171bt4_arraycursor_t1.new def ob_cursor.b_skip(x_array_element)
b_out=do_some_analysis(x_array_element)
return b_out
end # ob_cursor.b_skip
10609 10610 10611 |
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10609 def b_skip(x_array_element) return false end |
#clear ⇒ Object
Description resides next to the method inc().
10570 10571 10572 10573 10574 10575 10576 10577 10578 10579 10580 |
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10570 def clear if @b_threadsafe @mx.synchronize do @b_inited=false @ar_core=$kibuvits_krl171bt4_lc_emptyarray end # block else @b_inited=false @ar_core=$kibuvits_krl171bt4_lc_emptyarray end # if end |
#dec ⇒ Object
Description resides next to the method inc().
10745 10746 10747 10748 10749 10750 10751 10752 10753 |
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10745 def dec() if @b_threadsafe @mx.synchronize do inc_and_dec_impl(false) end # block else inc_and_dec_impl(false) end # if end |
#inc ⇒ Object
Throws or returns nil or an array element that the cursor points to.
The inc() and dec() return the element under the cursor and then move the cursor. Explanation by example:
reset(["aa","bb","cc");
inc()=="aa"; inc()=="bb"; inc()=="cc"; inc()=="aa"; dec()=="bb"; dec()==aa;
clear()
inc() and dec() will throw and exception.
reset(["aa","bb","cc");
inc()=="aa"; inc()=="bb";
reset([]);
inc()==nil; inc()==nil; dec()==nil
10734 10735 10736 10737 10738 10739 10740 10741 10742 |
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10734 def inc() if @b_threadsafe @mx.synchronize do inc_and_dec_impl(true) end # block else inc_and_dec_impl(true) end # if end |
#ixs_low ⇒ Object
A single array element is selected by using 2 sindices: low and high. urls.softf1.com/a1/krl/frag4_array_indexing_by_separators/
This method returns the lower bound that corresponds to the classical array index.
10771 10772 10773 |
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10771 def ixs_low return @ixs_low end |
#reset(ar_core) ⇒ Object
10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 |
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10538 def reset(ar_core) if KIBUVITS_krl171bt4_b_DEBUG bn=binding() kibuvits_krl171bt4_typecheck bn, Array,ar_core end # if KIBUVITS_krl171bt4_b_DEBUG # As the @ar_core is a reference, code outside might call # Array.clear(). and that might cause the cursor position # to become obsolete. if @b_threadsafe @mx.synchronize do @ar_core=ar_core @i_ar_core_expected_lenght=@ar_core.size # The indexing scheme: # http://longterm.softf1.com/specifications/array_indexing_by_separators/ @ixs_low=0 @ixs_high=0 @ixs_high=1 if 0<@i_ar_core_expected_lenght @b_inited=true end # block else @ar_core=ar_core @i_ar_core_expected_lenght=@ar_core.size # The indexing scheme: # http://longterm.softf1.com/specifications/array_indexing_by_separators/ @ixs_low=0 @ixs_high=0 @ixs_high=1 if 0<@i_ar_core_expected_lenght @b_inited=true end # if end |