next up previous index
Next: Implementations Up: Collections Previous: Ordered collections and sequences   Index

Indexed collections: vector, array, string, list, ...

In indexed.cecil:

abstract object indexed[T] isa sequence[T], table[int,T];
extend type indexed[`T] subtypes indexed[`S >= T];
method !(t@:indexed[`T], key:int): T;
method fetch(t@:indexed[`T], key:int): T;
method do(a@:indexed[`T], c:&(T):void):void;
method do(a1@:indexed[`T1], a2@:indexed[`T2], c:&(T1,T2):void):void;
method do(a1@:indexed[`T1], a2@:indexed[`T2], a3@:indexed[`T3],
method do(a1@:indexed[`T1], a2@:indexed[`T2], a3@:indexed[`T3],
          a4@:indexed[`T4], c:&(T1,T2,T3,T4):void):void;
method reverse_do(a@:indexed[`T], c:&(T):void):void;
method reverse_do(a1@:indexed[`T1], a2@:indexed[`T2],
method reverse_do(a1@:indexed[`T1], a2@:indexed[`T2], a3@:indexed[`T3],
method reverse_do(a1@:indexed[`T1], a2@:indexed[`T2], a3@:indexed[`T3],
                  a4@:indexed[`T4], c:&(T1,T2,T3,T4):void):void;
method do_associations(a@:indexed[`T], c:&(int,T):void):void;
Indexed collections are indexed sequences. They support the behavior of keyed tables, where the integers from 0 to c.length-1 serve as the keys. Indexed collections inherit: length, is_empty, do, pick_any, includes, find, copy, etc., from collections; reverse_do, flatten, ||, etc., from sequences; fetch, !, do_associations, keys_do, etc., from tables.

method range_do(a@:indexed[`T], start:int, stop:int,
method includes_key(a@:indexed[`T], key:int):bool;
method keys(t@:indexed[`T]):interval;
method ||(s1@:indexed[`T], s2@:indexed[`T]):indexed[T];
range_do evaluates c on all elements in [max(start,0)..min(stop,len)) (note half-open interval!)

method includes_index(a@:indexed[`T], i:int):bool;
method find_index(a@:indexed[`T <= comparable[T]], value:T):int;
method find_index(a@:indexed[`T <= comparable[T]], value:T,
method elems_print_string(c@:indexed[`T]):string;
method elems_print(c@:indexed[`T]):void;
method =(c1@:indexed[`T <= comparable[T]], c2@:indexed[T]):bool;
method <(c1@:indexed[`T <= ordered[T]], c2@:indexed[T]):bool;
method <=(c1@:indexed[`T <= ordered[T]], c2@:indexed[T]):bool;
signature copy(indexed[`T]):indexed[T];
The includes_index and find_index methods are simply renamings of the standard includes_key and find_key methods.

abstract object i_indexed[T] isa indexed[T], i_table[int,T];
extend type i_indexed[`T] subtypes i_indexed[`S >= T];
abstract object m_indexed[T] isa indexed[T], m_table[int,T];
method as_m_indexed(t@:m_indexed[`T]):m_indexed[T];
signature copy(m_indexed[`T]):m_indexed[T];
As usual, there are immutable and mutable varieties of indexed collections. Mutable collections support changing bindings of indices to values through the store or set_! methods inherited from m_table.

method set_first (a@:m_indexed[`T], x:T):void;
method set_second(a@:m_indexed[`T], x:T):void;
method set_third (a@:m_indexed[`T], x:T):void;
method set_fourth(a@:m_indexed[`T], x:T):void;
method set_last  (a@:m_indexed[`T], x:T):void;
There are convenient ways of assigning into the beginning and end of a collection. They can be invoked using the assignment message sugar, e.g., first(c) := x.

method swap(c@:m_indexed[`T], i:int, j:int):void;
The swap method exchanges the indices of two collection elements.

method slide_elems(t@:m_indexed[`T], from:int, to:int):void;
method slide_elems_by(t@:m_indexed[`T], from:int, to:int, amount:int):void;
The slide_elems[_by](from,to[,amount]) methods copy elements in the range [], inclusive, up by amount positions (where amount defaults to 1), sliding down if amount is negative.

method sort(c@:m_indexed[`T <= ordered[T]]):void;
method sort_by(c@:m_indexed[`T], pred:&(T,T):bool):void;
method sort_by(c@:m_indexed[`T], pred:&(T,T):bool,
               first_index:int, last_index:int):void;
The sort method sorts a collection in place, using either the element type's natural comparison operation (<=) or a user-supplied comparator function. Sorting uses the quicksort algorithm and attempts to be a reasonably stable sort.

method pos(s1:indexed[`T <= comparable[T]], s2@:indexed[T]):int;
method pos(s1@:indexed[`T <= comparable[T]], s2@:indexed[T],
method has_subsequence(s1@:indexed[`T <= comparable[T]], s2@:indexed[T]):bool;
method count_subsequences(s1@:indexed[`T <= comparable[T]],
The pos method returns the index at which the first collection occurs in the second collection (invoking the if_absent closure if not found), using the Knuth-Morris-Pratt string-matching algorithm. The has_subsequence method returns whether the second collection is found in the first collection, and the count_subsequences method returns the number of non-overlapping occurrences of the second collection in the first. [Note that the order of collection arguments in pos is opposite to that in the subsequence methods!]

next up previous index
Next: Implementations Up: Collections Previous: Ordered collections and sequences   Index

Cecil/Vortex Project