juno.base.collections Module

Licence
See licence.txt for use and distribution terms.

template EqualityComparison(T)

bool delegate(T a, T b)

template Comparison(T)

int delegate(T a, T b)

template Predicate(T)

bool delegate(T obj)

template Converter(TInput,TOutput)

TOutput delegate(TInput input)

template Action(T)

void delegate(T obj)

interface IEqualityComparer(T);

Defines methods that compare two objects for equality.

bool equals(T a, T b);

Determines whether the specified objects are equal.

Parameters
T a
The first object to compare.
T b
The second object to compare.

Returns
true if the specified objects are equal; otherwise, false.

uint getHash(T value);

Retrieves a hash code for the specified object.

Parameters
T value
The object for which a hash code is to be retrieved.

Returns
The hash code for the specified object.

class EqualityComparer(T): IEqualityComparer!(T);

Provides a base class for implementations of the IEqualityComparer(T) interface.

EqualityComparer instance();

Property. Returns a default equality comparer for the type specified by the template parameter.

bool equals(T a, T b);

Determines whether the specified objects are equal.

Parameters
T a
The first object to compare.
T b
The second object to compare.

Returns
true if the specified objects are equal; otherwise, false.

uint getHash(T value);

Retrieves a hash code for the specified object.

Parameters
T value
The object for which a hash code is to be retrieved.

Returns
The hash code for the specified object.

interface IComparer(T);

Defines a method that compares two objects.

int compare(T a, T b);

Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.

Parameters
T a
The first object to compare.
T b
The second object to compare.

Returns
Value Condition
Less than zero a is less than b.
Zero a equals b.
Greater than zero a is greater than b.


class Comparer(T): IComparer!(T);

Provides a base class for implementations of the IComparer(T) interface.

Comparer instance();

Property. Retrieves a default comparer for the type specified by the template parameter.

int compare(T a, T b);

Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.

Parameters
T a
The first object to compare.
T b
The second object to compare.

Returns
Value Condition
Less than zero a is less than b.
Zero a equals b.
Greater than zero a is greater than b.


void sort(T, TIndex = int, TLength = TIndex)(T[] array, TIndex index, TLength length, int delegate(T, T) comparison = null);

Sorts the elements int a range of element in an array using the specified Comparison(T).

Parameters
array
The array to sort.
index
The starting index of the range to sort.
length
The number of elements in the range to sort.
comparison
The Comparison(T) to use when comparing element.

void sort(T)(T[] array, int delegate(T, T) comparison = null);



int binarySearch(T, TIndex = int, TLength = TIndex)(T[] array, TIndex index, TLength length, T value, int delegate(T, T) comparison = null);

Searches a range of elements in an array for a value using the specified Comparison(T).

Parameters
array
The array to search.
index
The starting index of the range to search.
length
The number of elements in the range to search.
comparison
The Comparison(T) to use when comparing elements.

void copy(T, TIndex = int, TLength = TIndex)(T[] source, TIndex sourceIndex, T[] target, TIndex targetIndex, TLength length);



interface ICollection(T): IEnumerable!(T);

Defines methods to manipulate collections.

void add(T item);

Adds an item to the collection.

Parameters
T item
The object to add.

bool remove(T item);

Removes the first occurence of the specified object from the collection.

Parameters
T item
The object to remove.

Returns
true if item was successfully removed; otherwise, false.

bool contains(T item);

Determines whether the collection contains the specified object.

Parameters
T item
The object to locate.

Returns
true if item was found; otherwise, false.

void clear();

Removes all items from the collection.

int count();

Property. Gets the number of elements in the collection.

interface IList(T): ICollection!(T);

Represents a collection of objects that can be accessed by index.

void insert(int index, T item);

Inserts an item at the specified index.

Parameters
int index
The index at which item should be inserted.
T item
The object to insert.

void removeAt(int index);

Removes the item at the specified index.

Parameters
int index
The index of the item to remove.

void opIndexAssign(T value, int index);
T opIndex(int index);

Gets or sets the object at the specified index.

Parameters
T value
The item at the specified index.
int index
The index of the item to get or set.

class List(T): IList!(T);

Represents a list of elements that can be accessed by index.

this(int capacity = 0);

Initializes a new instance with the specified capacity.

Parameters
capacity
The number of elements the new list can store.

this(T[] range);
this(IEnumerable!(T) range);

Initializes a new instance containing elements copied from the specified range.

Parameters
range
The range whose elements are copied to the new list.

void add(T item);

Adds an element to the end of the list.

Parameters
T item
The element to be added.

void addRange(T[] range);
void addRange(IEnumerable!(T) range);

Adds the elements in the specified range to the end of the list.

Parameters

void insert(int index, T item);

Inserts an element into the list at the specified index.

Parameters
int index
The index at which item should be inserted.
T item
The element to insert.

void insertRange(int index, T[] range);
void insertRange(int index, IEnumerable!(T) range);

Inserts the elements of a range into the list at the specified index.

Parameters
int index
The index at which the new elements should be inserted.
T[] range
The range whose elements should be inserted into the list.

bool remove(T item);



void removeRange(int index, int count);



bool contains(T item);



void clear();



int indexOf(T item);



int indexOf(T item, EqualityComparison!(T) comparison);



int lastIndexOf(T item, EqualityComparison!(T) comparison = null);



void sort(Comparison!(T) comparison = null);



int binarySearch(T item, Comparison!(T) comparison = null);



void copyTo(T[] array);



T[] toArray();



T find(Predicate!(T) match);



T findLast(Predicate!(T) match);



List findAll(Predicate!(T) match);



int findIndex(Predicate!(T) match);



int findLastIndex(Predicate!(T) match);



bool exists(Predicate!(T) match);



void forEach(Action!(T) action);



bool trueForAll(Predicate!(T) match);



List!(T) getRange(int index, int count);



template convert(TOutput)
int opApply(int delegate(ref int, ref T) action);



class ReadOnlyList(T): IList!(T);



class KeyNotFoundException: object.Exception;



struct KeyValuePair(K,V);



K key;



V value;



interface IDictionary(K,V): IEnumerable!(KeyValuePair!(K,V));



void add(K key, V value);



bool containsKey(K key);



bool remove(K key);



bool tryGetValue(K key, out V value);



void opIndexAssign(V value, K key);
V opIndex(K key);



class Dictionary(K,V): IDictionary!(K,V);



class KeyCollection: ICollection!(K);



int count();



class ValueCollection: ICollection!(V);



int count();



this(int capacity = 0, IEqualityComparer!(K) comparer = null);



this(IEqualityComparer!(K) comparer);



void add(K key, V value);



bool containsKey(K key);



bool containsValue(V value);



bool remove(K key);



void clear();



bool tryGetValue(K key, out V value);



KeyCollection keys();



ValueCollection values();



int count();



void opIndexAssign(V value, K key);
V opIndex(K key);



class Queue(T): IEnumerable!(T);



this(int capacity = 0);



this(T[] range);



this(IEnumerable!(T) range);



void enqueue(T item);



T dequeue();



T peek();



bool contains(T item);



void clear();



int count();

Property.