next up previous index
Next: Strings Up: Indexed collections: vector, array, Previous: Indexed collections: vector, array,   Index

Implementations

Several concrete implementations of indexed collections exist:

In vector.cecil:

abstract object vector[`T] isa indexed[T];
extend type vector[`T] subtypes vector[`S >= T];
method as_vector(v@:vector[`T]):vector[T];
method length(v@:vector[`T]):int;
method fetch(v@:vector[`T], index:int):T;
method fetch(v@:vector[`T], index:int, if_absent:&():T):T;
extend i_vector[`T] isa vector[T], i_indexed[T];
extend type i_vector[`T] subtypes i_vector[`S >= T];
method new_i_vector(size@:int, filler:`T):i_vector[T];
method new_i_vector_from(c@:collection[`T1], cl:&(T1):`T2):i_vector[T2];
method new_i_vector[T](size@:int, filler:T):i_vector[T];
method new_i_vector_init[T](size@:int, cl:&(int):T):i_vector[T];
method new_i_vector_init_from[T2](c@:collection[`T1],
                                cl:&(T1):T2):i_vector[T2];
method new_i_vector_init_from[T2](c@:ordered_collection[`T1],
                                cl:&(T1):T2):i_vector[T2];
method new_i_vector_init_from[T2](c@:indexed[`T1],
                                cl:&(T1):T2):i_vector[T2];
method new_i_vector_init_from[T2](c@:vector[`T1],
                                  cl:&(T1):T2):i_vector[T2];
method as_i_vector(v@:i_vector[`T]):i_vector[T];
method add_functional(src@:indexed[`T], new_elm:T):i_vector[T];
method collection_name(@:i_vector[`T]):string;
extend m_vector[`T] isa vector[T], m_indexed[T];
method store(v@:m_vector[`T], index:int, x:T, if_absent:&():void):void;
method new_m_vector(size@:int):m_vector[dynamic];
method new_m_vector(size@:int, filler:`T):m_vector[T];
method new_m_vector_from(c@:collection[`T1], cl:&(T1):`T2):m_vector[T2];
method new_m_vector[T](size@:int):m_vector[T];
method new_m_vector[T](size@:int, filler:T):m_vector[T];
method new_m_vector_init[T](size@:int, cl:&(int):T):m_vector[T];
method new_m_vector_init_from[T2](c@:collection[`T1],
                                  cl:&(T1):T2):m_vector[T2];
method new_m_vector_init_from[T2](c@:indexed[`T1],
                                  cl:&(T1):T2):m_vector[T2];
method new_m_vector_init_from[T2](c@:vector[`T1],
                                  cl:&(T1):T2):m_vector[T2];
method as_m_vector(v@:m_vector[`T]):m_vector[T];
method copy(v@:m_vector[`T]):m_vector[T];
method collection_name(@:m_vector[`T]):string;
i_vector is a primitive implementation of fixed-length immutable indexed collections. Besides the new_ methods (see the next paragraph on how they work), instances of i_vector can be created by Cecil vector constructor expressions, e.g., [3, 4, 5, x*12].

m_vector is a primitive implementation of fixed-length mutable indexed collections.

The new_(i|m)_vector function constructs a new (i|m)_vector of a given size all of whose elements are filler. The new_(i|m)_vector_init function constructs a (i|m)_vector of a particular size and uses the elems closure to construct the initial values of the vector's elements from the indices. The new_(i|m)_vector_init_from function constructs a (i|m)_vector of the same length as some other ordered collection and applies a mapping function to translate each element of the receiver collection into the corresponding vector element; new_(i|m)_vector_init_from is simply the well-known map function, specialized to return a particular vector representation. In the current implementation, vectors cannot be subclassed.

\begin{center}\vbox{\input{include/array.tex}
}\end{center} In interval.cecil:

template object interval isa i_indexed[int];
 field step(@:interval):int;
method in_range(s@:interval, i:int):bool;
method length(s@:interval):int;
method do(s@:interval, c:&(int):void):void;
method do_associations(s@:interval, c:&(int,int):void):void;
method fetch(s@:interval, k:int, if_absent:&():int):int;
method includes(s@:interval, i:int):bool;
method print_string(s@:interval):string;
method collection_name(@:interval):string;
method new_interval(start:int, stop:int):interval;
method new_interval(start:int, stop:int, step:int):interval;
intervals are immutable indexed collections representing a finite arithmetic sequence of integers. An interval returned by new_interval(start, stop) represents the integers in order from start to stop, inclusive; if stop is less than start then the sequence is empty. The interval may optionally specify a step value between start and stop. If the step is negative, then the sequence goes from start down to stop, inclusive; if stop is greater than start, then the sequence is empty.

method for(start:int, stop:int, body:&(int):void):void;
method for(start:int, stop:int, step:int, body:&(int):void):void;
Intervals can be used to implement regular for loops. For example,
    for i := 1 to 10 do ... end
can be expressed in Cecil as:
    new_interval(1, 10).do(&(i:int){
        ...
    });
The for methods provide a convenient interface for this idiom; they also currently implement this idiom more efficiently. (Recently, compiler optimizations have been implemented that greatly reduce the performance cost of the new_interval(...).do(...) version; if debug_support is disabled, there should be no difference in performance between new_interval(...).do(...) and for(...).)

In bit-vector.cecil:

template object bit_vector isa m_indexed[int];
  method length(t@:bit_vector):int;
method new_bit_vector(sz:int):bit_vector;
method copy(t@:bit_vector):bit_vector;
method resize(t@:bit_vector, new_bits:int):void;
method =(l@:bit_vector, r@:bit_vector):bool;
method =_or_zero(l@:bit_vector, r@:bit_vector):bool;
Bit vectors are a dense representation of a mutable indexed collection of zeros and ones. A new bit vector of zeros can be created with new_bit_vector. A bit vector can be resized in place; if expanded, then the new positions are filled in with zeros.

method bit_or(l@:bit_vector, r@:bit_vector):bit_vector;
method bit_or_in_place(l@:bit_vector, r@:bit_vector):bit_vector;
method bit_and(l@:bit_vector, r@:bit_vector):bit_vector;
method bit_and_in_place(l@:bit_vector, r@:bit_vector):bit_vector;
method bit_xor(l@:bit_vector, r@:bit_vector):bit_vector;
method bit_xor_in_place(l@:bit_vector, r@:bit_vector):bit_vector;
method bit_xnor(l@:bit_vector, r@:bit_vector):bit_vector;
method bit_xnor_in_place(l@:bit_vector, r@:bit_vector):bit_vector;
method bit_not(l@:bit_vector):bit_vector;
method bit_not_in_place(l@:bit_vector):bit_vector;
method bit_difference(l@:bit_vector, r@:bit_vector):bit_vector;
method bit_difference_in_place(l@:bit_vector, r@:bit_vector):bit_vector;
method includes_all(l@:bit_vector, r@:bit_vector):bool;
Bit vectors can be or'd, and'd, xor'd, subtracted, and negated, all bitwise, to compute new bit vectors from old.

method is_disjoint(l@:bit_vector, r@:bit_vector):bool;
method fetch(v@:bit_vector, bit:int, if_absent:&():int):int;
method store(v@:bit_vector, bit:int, value:int, if_absent:&():void):void;
method set_all_bits(v@:bit_vector):void;
method clear_all_bits(v@:bit_vector):void;
method is_all_zeros(v@:bit_vector):bool;
method is_all_ones(v@:bit_vector):bool;
A bit vector can be mutated to be all zeros (clear_all_bits) or all ones (set_all_bits) or tested for those conditions. The is_disjoint method returns true if its arguments share no set bits; is_disjoint(a,b) is equivalent to is_all_zeros(bit_and(a,b)).

method do_ones(v@:bit_vector, cl:&(int):void):void;
method collection_name(@:bit_vector):string;
method elem_separator(@:bit_vector):string;
The do_ones control structure iterates over all the set positions in the bit vector; this operation runs faster than a regular do loop containing a test in each iteration. In byte-vector.cecil:

abstract object byte_vector isa indexed[int];
field len(@:byte_vector):none prim rep wordInt length;
var field elems(@:byte_vector):none prim rep int1 array of len;
method as_byte_vector(v@:byte_vector):byte_vector;
method length(v@:byte_vector):int;
method fetch(v@:byte_vector, index:int, if_absent:&():int):int;
object i_byte_vector isa byte_vector, i_indexed[int];
method new_i_byte_vector(size@:int, filler_oop@:int):i_byte_vector;
method new_i_byte_vector_init(size@:int, cl:&(int):int):i_byte_vector;
method new_i_byte_vector_init_from(c@:indexed[`T],
                                cl:&(T):int):i_byte_vector;
method new_i_byte_vector_init_from(c@:ordered_collection[`T],
                                cl:&(T):int):i_byte_vector;
method as_i_byte_vector(v@:i_byte_vector):i_byte_vector;
method copy(v@:i_byte_vector):i_byte_vector;
method collection_name(@:i_byte_vector):string;
object m_byte_vector isa byte_vector, m_indexed[int];
method store(v@:m_byte_vector, index:int, x_oop:int, if_absent:&():void):void;
method new_m_byte_vector(size@:int):m_byte_vector;
method new_m_byte_vector(size@:int, filler_oop@:int):m_byte_vector;
method new_m_byte_vector_init(size@:int, cl:&(int):int):m_byte_vector;
method new_m_byte_vector_init_from(c@:indexed[`T], cl:&(T):int
                                   ):m_byte_vector;
method new_m_byte_vector_init_from(c@:ordered_collection[`T],
                                    cl:&(T):int):m_byte_vector;
method as_m_byte_vector(v@:m_byte_vector):m_byte_vector;
method copy(v@:m_byte_vector):m_byte_vector;
method collection_name(@:m_byte_vector):string;
In short-vector.cecil:

abstract object short_vector isa indexed[int];
field len(@:short_vector):none prim rep wordInt length;
var field elems(@:short_vector):none prim rep int2 array of len;
method as_short_vector(v@:short_vector):short_vector;
method length(v@:short_vector):int;
method fetch(v@:short_vector, index:int, if_absent:&():int):int;
object i_short_vector isa short_vector, i_indexed[int];
method new_i_short_vector(size@:int, filler_oop@:int):i_short_vector;
method new_i_short_vector_init(size@:int, cl:&(int):int):i_short_vector;
method new_i_short_vector_init_from(c@:indexed[`T],
                                cl:&(T):int):i_short_vector;
method new_i_short_vector_init_from(c@:ordered_collection[`T],
                                cl:&(T):int):i_short_vector;
method as_i_short_vector(v@:i_short_vector):i_short_vector;
method copy(v@:i_short_vector):i_short_vector;
method collection_name(@:i_short_vector):string;
object m_short_vector isa short_vector, m_indexed[int];
method store(v@:m_short_vector, index:int, x_oop:int, if_absent:&():void):void;
method new_m_short_vector(size@:int):m_short_vector;
method new_m_short_vector(size@:int, filler_oop@:int):m_short_vector;
method new_m_short_vector_init(size@:int, cl:&(int):int):m_short_vector;
method new_m_short_vector_init_from(c@:indexed[`T], cl:&(T):int
                                   ):m_short_vector;
method new_m_short_vector_init_from(c@:ordered_collection[`T],
                                    cl:&(T):int):m_short_vector;
method as_m_short_vector(v@:m_short_vector):m_short_vector;
method copy(v@:m_short_vector):m_short_vector;
method collection_name(@:m_short_vector):string;
In word-vector.cecil:

abstract object word_vector isa indexed[int];
method as_word_vector(v@:word_vector):word_vector;
let num_word_bits:int;
method length(v@:word_vector):int;
method fetch(v@:word_vector, index:int, if_absent:&():int):int;
extend i_word_vector isa word_vector, i_indexed[int];
method new_i_word_vector(size@:int, filler_oop@:int):i_word_vector;
method new_i_word_vector_init(size@:int, cl:&(int):int):i_word_vector;
method new_i_word_vector_init_from(c@:indexed[`T],
                                cl:&(T):int):i_word_vector;
method new_i_word_vector_init_from(c@:ordered_collection[`T],
                                cl:&(T):int):i_word_vector;
method as_i_word_vector(v@:i_word_vector):i_word_vector;
method copy(v@:i_word_vector):i_word_vector;
method collection_name(@:i_word_vector):string;
extend m_word_vector isa word_vector, m_indexed[int];
method store(v@:m_word_vector, index:int, x:int, if_absent:&():void):void;
method new_m_word_vector(size@:int):m_word_vector;
method new_m_word_vector(size@:int, filler_oop@:int):m_word_vector;
method new_m_word_vector_init(size@:int, cl:&(int):int):m_word_vector;
method new_m_word_vector_init_from(c@:indexed[`T], cl:&(T):int
                                   ):m_word_vector;
method new_m_word_vector_init_from(c@:ordered_collection[`T],
                                    cl:&(T):int):m_word_vector;
method as_m_word_vector(v@:m_word_vector):m_word_vector;
method copy(v@:m_word_vector):m_word_vector;
method collection_name(@:m_word_vector):string;
In float-vector.cecil:

abstract object float_vector isa indexed[float];
method as_float_vector(v@:float_vector):float_vector;
method length(v@:float_vector):int;
method fetch(v@:float_vector, index:int, if_absent:&():float):float;
extend i_float_vector isa float_vector, i_indexed[float];
method new_i_float_vector(size@:int, filler_oop@:float):i_float_vector;
method new_i_float_vector_init(size@:int, cl:&(int):float):i_float_vector;
method new_i_float_vector_init_from(c@:indexed[`T],
                                cl:&(T):float):i_float_vector;
method new_i_float_vector_init_from(c@:ordered_collection[`T],
                                cl:&(T):float):i_float_vector;
method as_i_float_vector(v@:i_float_vector):i_float_vector;
method copy(v@:i_float_vector):i_float_vector;
method collection_name(@:i_float_vector):string;
extend m_float_vector isa float_vector, m_indexed[float];
method store(v@:m_float_vector, index:int, x:float, if_absent:&():void):void;
method new_m_float_vector(size@:int):m_float_vector;
method new_m_float_vector(size@:int, filler_oop@:float):m_float_vector;
method new_m_float_vector_init(size@:int, cl:&(int):float):m_float_vector;
method new_m_float_vector_init_from(c@:indexed[`T], cl:&(T):float
                                   ):m_float_vector;
method new_m_float_vector_init_from(c@:ordered_collection[`T],
                                    cl:&(T):float):m_float_vector;
method as_m_float_vector(v@:m_float_vector):m_float_vector;
method copy(v@:m_float_vector):m_float_vector;
method collection_name(@:m_float_vector):string;


next up previous index
Next: Strings Up: Indexed collections: vector, array, Previous: Indexed collections: vector, array,   Index

Cecil/Vortex Project