next up previous index
Next: Sets Up: Collections Previous: Basic collections   Index

Unordered collections

In unordered.cecil:

abstract object unordered_collection[T] isa collection[T];
  extend type unordered_collection[`T] subtypes unordered_collection[`S >= T];
An unordered_collection is a group of elements in no particular order. It supports collection operations such as length, is_empty, do, pick_any, includes, find, and copy.

  extend unordered_collection[`T <= comparable[T]]
                isa comparable[unordered_collection[T]];
  method =(c1@:unordered_collection[`T <= comparable[T]],
           c2@:unordered_collection[T]):bool;
  extend unordered_collection[`T <= hashable[T]]
                isa hashable[unordered_collection[T]];
  method hash(c@:unordered_collection[`T <= hashable[T]], range:int):int;
  signature copy_empty(unordered_collection[`T]):m_unordered_collection[T];
If the elements of the collection are comparable, then so is the collection. Two such collections are equal (=) if they have the same elements (with the same number of occurrences), independent of order. (By contrast, two ordered collections are equal only if they contain the same elements in the same order.) If the elements of the collection are hashable, then so is the collection.

Unordered collections support several functional set-operations which, given argument collections, return a new collection.

method union(m1@:unordered_collection[`T <= comparable[T]],
             m2@:unordered_collection[T]
             ):m_unordered_collection[T];
union: form the collection whose element counts are the maximum of the element counts of the argument collections

method intersection(m1@:unordered_collection[`T <= comparable[T]],
                    m2@:unordered_collection[T]
                    ):m_unordered_collection[T];
intersection: form the collection whose element counts are the minumum of the element counts of the argument collections

method difference(m1@:unordered_collection[`T <= comparable[T]],
                  m2@:unordered_collection[T]
                  ):m_unordered_collection[T];
difference: form the collection whose element counts are the element counts of the first collection minus the element counts of the second collection (with a minimum count of 0)

method is_disjoint(m1@:unordered_collection[`T <= comparable[T]],
                   m2@:unordered_collection[T]):bool;
is_disjoint: are there no elements in common?

method overlaps(m1@:unordered_collection[`T <= comparable[T]],
                m2@:unordered_collection[T]):bool;
overlaps: are there any elements in common?

method is_subset(m1@:unordered_collection[`T <= comparable[T]],
                 m2@:unordered_collection[T]):bool;
is_subset: is the number of elements of elements of m1 <= the number of those elements in m2?

Two refinements of unordered_collection indicate whether the collection is known to be immutable (i_unordered_collection) or mutable (m_unordered_collection).

abstract object i_unordered_collection[T] isa unordered_collection[T];
  extend type i_unordered_collection[`T]
                subtypes i_unordered_collection[`S >= T];
  method copy(c@:`T <= i_unordered_collection[`T1]):T;
An immutable unordered collection of some type T is a subtype of any immutable unordered collection of a supertype of T. In contrast, a mutable unordered collection of a type T has no subtyping relation to a mutable unordered collection of a different type. Both kinds are subtypes or a generic unordered collection of T or transitively any supertype of T.

abstract object m_unordered_collection[T]
        isa unordered_collection[T], extensible_collection[T];
  method copy(c@:`T <= m_unordered_collection[`T1]):`T2
                                        where signature copy_empty(T):T2;
Mutable collections provide remove, add, and other operations of extensible_collection. Method copy_empty always returns an empty mutable collection with a type like that of its argument.



Subsections
next up previous index
Next: Sets Up: Collections Previous: Basic collections   Index

Cecil/Vortex Project