C5  2.4
The C5 Generic Collection Library for C# and CLI is a comprehensive collection library supporting lists, sets, bags, dictionaries, priority queues, (FIFO) queues, and (LIFO) stacks. C5 runs on .NET 3.5+, Silverlight 5, Windows Phone 8, Xamarin.iOS, Xamarin.Android, and Mono.
C5.ISorted< T > Interface Template Reference

A sorted collection, i.e. a collection where items are maintained and can be searched for in sorted order. Thus the sequence order is given as a sorting order. More...

Inheritance diagram for C5.ISorted< T >:
C5.ISequenced< T > C5.ICollection< T > C5.IDirectedCollectionValue< T > C5.IExtensible< T > C5.ICollectionValue< T > C5.IDirectedEnumerable< T > C5.ICollectionValue< T > C5.IShowable C5.IShowable C5.GuardedSorted< T > C5.IIndexedSorted< T > C5.IPersistentSorted< T > C5.GuardedIndexedSorted< T > C5.GuardedIndexedSorted< T > C5.SortedArray< T > C5.TreeBag< T > C5.TreeSet< T > C5.TreeBag< T > C5.TreeSet< T >

Public Member Functions

FindMin ()
 Find the current least item of this sorted collection. More...
 
DeleteMin ()
 Remove the least item from this sorted collection. More...
 
FindMax ()
 Find the current largest item of this sorted collection. More...
 
DeleteMax ()
 Remove the largest item from this sorted collection. More...
 
bool TryPredecessor (T item, out T res)
 Find the strict predecessor of item in the sorted collection, that is, the greatest item in the collection smaller than the item. More...
 
bool TrySuccessor (T item, out T res)
 Find the strict successor of item in the sorted collection, that is, the least item in the collection greater than the supplied value. More...
 
bool TryWeakPredecessor (T item, out T res)
 Find the weak predecessor of item in the sorted collection, that is, the greatest item in the collection smaller than or equal to the item. More...
 
bool TryWeakSuccessor (T item, out T res)
 Find the weak successor of item in the sorted collection, that is, the least item in the collection greater than or equal to the supplied value. More...
 
Predecessor (T item)
 Find the strict predecessor in the sorted collection of a particular value, that is, the largest item in the collection less than the supplied value. More...
 
Successor (T item)
 Find the strict successor in the sorted collection of a particular value, that is, the least item in the collection greater than the supplied value. More...
 
WeakPredecessor (T item)
 Find the weak predecessor in the sorted collection of a particular value, that is, the largest item in the collection less than or equal to the supplied value. More...
 
WeakSuccessor (T item)
 Find the weak successor in the sorted collection of a particular value, that is, the least item in the collection greater than or equal to the supplied value. More...
 
bool Cut (IComparable< T > cutFunction, out T low, out bool lowIsValid, out T high, out bool highIsValid)
 Given a "cut" function from the items of the sorted collection to More...
 
IDirectedEnumerable< T > RangeFrom (T bot)
 Query this sorted collection for items greater than or equal to a supplied value. More...
 
IDirectedEnumerable< T > RangeFromTo (T bot, T top)
 Query this sorted collection for items between two supplied values. More...
 
IDirectedEnumerable< T > RangeTo (T top)
 Query this sorted collection for items less than a supplied value. More...
 
IDirectedCollectionValue< T > RangeAll ()
 Create a directed collection with the same items as this collection. More...
 
void AddSorted (SCG.IEnumerable< T > items)
 Add all the items from another collection with an enumeration order that is increasing in the items. More...
 
void RemoveRangeFrom (T low)
 Remove all items of this collection above or at a supplied threshold. More...
 
void RemoveRangeFromTo (T low, T hi)
 Remove all items of this collection between two supplied thresholds. More...
 
void RemoveRangeTo (T hi)
 Remove all items of this collection below a supplied threshold. More...
 
- Public Member Functions inherited from C5.ISequenced< T >
int GetSequencedHashCode ()
 The hashcode is defined as More...
 
bool SequencedEquals (ISequenced< T > otherCollection)
 Compare this sequenced collection to another one in sequence order. More...
 
- Public Member Functions inherited from C5.ICollection< T >
new bool Add (T item)
 Add an item to this collection if possible. If this collection has set semantics, the item will be added if not already in the collection. If bag semantics, the item will always be added. More...
 
new void CopyTo (T[] array, int index)
 Copy the items of this collection to a contiguous part of an array. More...
 
int GetUnsequencedHashCode ()
 The unordered collection hashcode is defined as the sum of More...
 
bool UnsequencedEquals (ICollection< T > otherCollection)
 Compare the contents of this collection to another one without regards to the sequence order. The comparison will use this collection's itemequalityComparer to compare individual items. More...
 
new bool Contains (T item)
 Check if this collection contains (an item equivalent to according to the itemequalityComparer) a particular value. More...
 
int ContainsCount (T item)
 Count the number of items of the collection equal to a particular value. Returns 0 if and only if the value is not in the collection. More...
 
ICollectionValue< T > UniqueItems ()
 
ICollectionValue< KeyValuePair< T, int > > ItemMultiplicities ()
 
bool ContainsAll (SCG.IEnumerable< T > items)
 Check whether this collection contains all the values in another collection. If this collection has bag semantics ( More...
 
bool Find (ref T item)
 Check if this collection contains an item equivalent according to the itemequalityComparer to a particular value. If so, return in the ref argument (a binary copy of) the actual value found. More...
 
bool FindOrAdd (ref T item)
 Check if this collection contains an item equivalent according to the itemequalityComparer to a particular value. If so, return in the ref argument (a binary copy of) the actual value found. Else, add the item to the collection. More...
 
bool Update (T item)
 Check if this collection contains an item equivalent according to the itemequalityComparer to a particular value. If so, update the item in the collection with a (binary copy of) the supplied value. If the collection has bag semantics, it depends on the value of DuplicatesByCounting if this updates all equivalent copies in the collection or just one. More...
 
bool Update (T item, out T olditem)
 Check if this collection contains an item equivalent according to the itemequalityComparer to a particular value. If so, update the item in the collection with a (binary copy of) the supplied value. If the collection has bag semantics, it depends on the value of DuplicatesByCounting if this updates all equivalent copies in the collection or just one. More...
 
bool UpdateOrAdd (T item)
 Check if this collection contains an item equivalent according to the itemequalityComparer to a particular value. If so, update the item in the collection to with a binary copy of the supplied value; else add the value to the collection. More...
 
bool UpdateOrAdd (T item, out T olditem)
 Check if this collection contains an item equivalent according to the itemequalityComparer to a particular value. If so, update the item in the collection to with a binary copy of the supplied value; else add the value to the collection. More...
 
new bool Remove (T item)
 Remove a particular item from this collection. If the collection has bag semantics only one copy equivalent to the supplied item is removed. More...
 
bool Remove (T item, out T removeditem)
 Remove a particular item from this collection if found. If the collection has bag semantics only one copy equivalent to the supplied item is removed, which one is implementation dependent. If an item was removed, report a binary copy of the actual item removed in the argument. More...
 
void RemoveAllCopies (T item)
 Remove all items equivalent to a given value. More...
 
void RemoveAll (SCG.IEnumerable< T > items)
 Remove all items in another collection from this one. If this collection has bag semantics, take multiplicities into account. More...
 
new void Clear ()
 Remove all items from this collection. More...
 
void RetainAll (SCG.IEnumerable< T > items)
 Remove all items not in some other collection from this one. If this collection has bag semantics, take multiplicities into account. More...
 
- Public Member Functions inherited from C5.IExtensible< T >
void AddAll (SCG.IEnumerable< T > items)
 Add the elements from another collection with a more specialized item type to this collection. If this collection has set semantics, only items not already in the collection will be added. More...
 
bool Check ()
 Check the integrity of the internal data structures of this collection. This is only relevant for developers of the library More...
 
- Public Member Functions inherited from C5.ICollectionValue< T >
T[] ToArray ()
 Create an array with the items of this collection (in the same order as an enumerator would output them). More...
 
void Apply (Action< T > action)
 Apply a delegate to all items of this collection. More...
 
bool Exists (Func< T, bool > predicate)
 Check if there exists an item that satisfies a specific predicate in this collection. More...
 
bool Find (Func< T, bool > predicate, out T item)
 Check if there exists an item that satisfies a specific predicate in this collection and return the first one in enumeration order. More...
 
bool All (Func< T, bool > predicate)
 Check if all items in this collection satisfies a specific predicate. More...
 
Choose ()
 Choose some item of this collection. More...
 
SCG.IEnumerable< T > Filter (Func< T, bool > filter)
 Create an enumerable, enumerating the items of this collection that satisfies a certain condition. More...
 
- Public Member Functions inherited from C5.IShowable
bool Show (StringBuilder stringbuilder, ref int rest, IFormatProvider formatProvider)
 Format More...
 
- Public Member Functions inherited from C5.IDirectedCollectionValue< T >
new IDirectedCollectionValue< T > Backwards ()
 Create a collection containing the same items as this collection, but whose enumerator will enumerate the items backwards. The new collection will become invalid if the original is modified. Method typically used as in More...
 
bool FindLast (Func< T, bool > predicate, out T item)
 Check if there exists an item that satisfies a specific predicate in this collection and return the first one in enumeration order. More...
 

Properties

SCG.IComparer< T > Comparer [get]
 The comparer object supplied at creation time for this sorted collection. More...
 
- Properties inherited from C5.ICollection< T >
Speed ContainsSpeed [get]
 The value is symbolic indicating the type of asymptotic complexity in terms of the size of this collection (worst-case or amortized as relevant). More...
 
new int Count [get]
 
new bool IsReadOnly [get]
 If true any call of an updating operation will throw an More...
 
- Properties inherited from C5.IExtensible< T >
bool IsReadOnly [get]
 If true any call of an updating operation will throw an More...
 
bool AllowsDuplicates [get]
 
SCG.IEqualityComparer< T > EqualityComparer [get]
 (Here should be a discussion of the role of equalityComparers. Any ). More...
 
bool DuplicatesByCounting [get]
 By convention this is true for any collection with set semantics. More...
 
- Properties inherited from C5.ICollectionValue< T >
EventTypeEnum ListenableEvents [get]
 A flag bitmap of the events subscribable to by this collection. More...
 
EventTypeEnum ActiveEvents [get]
 A flag bitmap of the events currently subscribed to by this collection. More...
 
bool IsEmpty [get]
 
int Count [get]
 
Speed CountSpeed [get]
 The value is symbolic indicating the type of asymptotic complexity in terms of the size of this collection (worst-case or amortized as relevant). More...
 
- Properties inherited from C5.IDirectedEnumerable< T >
EnumerationDirection Direction [get]
 

Additional Inherited Members

- Events inherited from C5.ICollectionValue< T >
CollectionChangedHandler< T > CollectionChanged
 The change event. Will be raised for every change operation on the collection. More...
 
CollectionClearedHandler< T > CollectionCleared
 The change event. Will be raised for every clear operation on the collection. More...
 
ItemsAddedHandler< T > ItemsAdded
 The item added event. Will be raised for every individual addition to the collection. More...
 
ItemInsertedHandler< T > ItemInserted
 The item inserted event. Will be raised for every individual insertion to the collection. More...
 
ItemsRemovedHandler< T > ItemsRemoved
 The item removed event. Will be raised for every individual removal from the collection. More...
 
ItemRemovedAtHandler< T > ItemRemovedAt
 The item removed at event. Will be raised for every individual removal at from the collection. More...
 

Detailed Description

A sorted collection, i.e. a collection where items are maintained and can be searched for in sorted order. Thus the sequence order is given as a sorting order.

The sorting order is defined by a comparer, an object of type IComparer<T> (T:C5.IComparer`1). Implementors of this interface will normally let the user define the comparer as an argument to a constructor. Usually there will also be constructors without a comparer argument, in which case the comparer should be the defalt comparer for the item type, P:C5.Comparer`1.Default.

The comparer of the sorted collection is available as the SCG.Comparer property (P:C5.ISorted`1.Comparer).

The methods are grouped according to

  • Extrema: report or report and delete an extremal item. This is reminiscent of simplified priority queues.
  • Nearest neighbor: report predecessor or successor in the collection of an item. Cut belongs to this group.
  • Range: report a view of a range of elements or remove all elements in a range.
  • AddSorted: add a collection of items known to be sorted in the same order (should be faster) (to be removed?)

Since this interface extends ISequenced<T>, sorted collections will also have an item equalityComparer (P:C5.IExtensible`1.EqualityComparer). This equalityComparer will not be used in connection with the inner workings of the sorted collection, but will be used if the sorted collection is used as an item in a collection of unsequenced or sequenced collections, (T:C5.ICollection`1 and T:C5.ISequenced`1)

Note that code may check if two sorted collections has the same sorting order by checking if the Comparer properties are equal. This is done a few places in this library for optimization purposes.

Member Function Documentation

void C5.ISorted< T >.AddSorted ( SCG.IEnumerable< T >  items)

Add all the items from another collection with an enumeration order that is increasing in the items.

Exceptions
ArgumentExceptionif the enumerated items turns out not to be in increasing order.
Parameters
itemsThe collection to add.

Implemented in C5.GuardedSorted< T >, C5.TreeBag< T >, C5.TreeSet< T >, and C5.SortedArray< T >.

bool C5.ISorted< T >.Cut ( IComparable< T >  cutFunction,
out T  low,
out bool  lowIsValid,
out T  high,
out bool  highIsValid 
)

Given a "cut" function from the items of the sorted collection to

int whose only sign changes when going through items in increasing order can be

  • from positive to zero
  • from positive to negative
  • from zero to negative

The "cut" function is supplied as the CompareTo method of an object c implementing IComparable<T>. A typical example is the case where T is comparable and cutFunction is itself of type T.

This method performs a search in the sorted collection for the ranges in which the "cut" function is negative, zero respectively positive. If T is comparable and c is of type T, this is a safe way (no exceptions thrown) to find predecessor and successor of c.

If the supplied cut function does not satisfy the sign-change condition, the result of this call is undefined.

Parameters
cutFunctionThe cut function
T
to
int
, given by the
CompareTo
method of an object implementing
IComparable<T>
.
lowReturns the largest item in the collection, where the cut function is positive (if any).
lowIsValidReturns true if the cut function is positive somewhere on this collection.
highReturns the least item in the collection, where the cut function is negative (if any).
highIsValidReturns true if the cut function is negative somewhere on this collection.
Returns
True if the cut function is zero somewhere on this collection.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

T C5.ISorted< T >.DeleteMax ( )

Remove the largest item from this sorted collection.

Exceptions
NoSuchItemExceptionif the collection is empty.
Returns
The removed item.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.SortedArray< T >, and C5.GuardedSorted< T >.

T C5.ISorted< T >.DeleteMin ( )

Remove the least item from this sorted collection.

Exceptions
NoSuchItemExceptionif the collection is empty.
Returns
The removed item.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.SortedArray< T >, and C5.GuardedSorted< T >.

T C5.ISorted< T >.FindMax ( )

Find the current largest item of this sorted collection.

Exceptions
NoSuchItemExceptionif the collection is empty.
Returns
The largest item.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.SortedArray< T >, and C5.GuardedSorted< T >.

T C5.ISorted< T >.FindMin ( )

Find the current least item of this sorted collection.

Exceptions
NoSuchItemExceptionif the collection is empty.
Returns
The least item.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.SortedArray< T >, and C5.GuardedSorted< T >.

T C5.ISorted< T >.Predecessor ( item)

Find the strict predecessor in the sorted collection of a particular value, that is, the largest item in the collection less than the supplied value.

Exceptions
NoSuchItemExceptionif no such element exists (the supplied value is less than or equal to the minimum of this collection.)
Parameters
itemThe item to find the predecessor for.
Returns
The predecessor.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

IDirectedCollectionValue<T> C5.ISorted< T >.RangeAll ( )

Create a directed collection with the same items as this collection.

The returned collection is not a copy but a view into the collection.

The view is fragile in the sense that changes to the underlying collection will invalidate the view so that further operations on the view throws InvalidView exceptions.

Returns
The result directed collection.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

IDirectedEnumerable<T> C5.ISorted< T >.RangeFrom ( bot)

Query this sorted collection for items greater than or equal to a supplied value.

The returned collection is not a copy but a view into the collection.

The view is fragile in the sense that changes to the underlying collection will invalidate the view so that further operations on the view throws InvalidView exceptions.

Parameters
botThe lower bound (inclusive).
Returns
The result directed collection.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.IIndexedSorted< T >, C5.GuardedIndexedSorted< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

IDirectedEnumerable<T> C5.ISorted< T >.RangeFromTo ( bot,
top 
)

Query this sorted collection for items between two supplied values.

The returned collection is not a copy but a view into the collection.

The view is fragile in the sense that changes to the underlying collection will invalidate the view so that further operations on the view throws InvalidView exceptions.

Parameters
botThe lower bound (inclusive).
topThe upper bound (exclusive).
Returns
The result directed collection.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.IIndexedSorted< T >, C5.GuardedIndexedSorted< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

IDirectedEnumerable<T> C5.ISorted< T >.RangeTo ( top)

Query this sorted collection for items less than a supplied value.

The returned collection is not a copy but a view into the collection.

The view is fragile in the sense that changes to the underlying collection will invalidate the view so that further operations on the view throws InvalidView exceptions.

Parameters
topThe upper bound (exclusive).
Returns
The result directed collection.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.IIndexedSorted< T >, C5.GuardedIndexedSorted< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

void C5.ISorted< T >.RemoveRangeFrom ( low)

Remove all items of this collection above or at a supplied threshold.

Parameters
lowThe lower threshold (inclusive).

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

void C5.ISorted< T >.RemoveRangeFromTo ( low,
hi 
)

Remove all items of this collection between two supplied thresholds.

Parameters
lowThe lower threshold (inclusive).
hiThe upper threshold (exclusive).

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

void C5.ISorted< T >.RemoveRangeTo ( hi)

Remove all items of this collection below a supplied threshold.

Parameters
hiThe upper threshold (exclusive).

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

T C5.ISorted< T >.Successor ( item)

Find the strict successor in the sorted collection of a particular value, that is, the least item in the collection greater than the supplied value.

Exceptions
NoSuchItemExceptionif no such element exists (the supplied value is greater than or equal to the maximum of this collection.)
Parameters
itemThe item to find the successor for.
Returns
The successor.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

bool C5.ISorted< T >.TryPredecessor ( item,
out T  res 
)

Find the strict predecessor of item in the sorted collection, that is, the greatest item in the collection smaller than the item.

Parameters
itemThe item to find the predecessor for.
resThe predecessor, if any; otherwise the default value for T.
Returns
True if item has a predecessor; otherwise false.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

bool C5.ISorted< T >.TrySuccessor ( item,
out T  res 
)

Find the strict successor of item in the sorted collection, that is, the least item in the collection greater than the supplied value.

Parameters
itemThe item to find the successor for.
resThe successor, if any; otherwise the default value for T.
Returns
True if item has a successor; otherwise false.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

bool C5.ISorted< T >.TryWeakPredecessor ( item,
out T  res 
)

Find the weak predecessor of item in the sorted collection, that is, the greatest item in the collection smaller than or equal to the item.

Parameters
itemThe item to find the weak predecessor for.
resThe weak predecessor, if any; otherwise the default value for T.
Returns
True if item has a weak predecessor; otherwise false.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

bool C5.ISorted< T >.TryWeakSuccessor ( item,
out T  res 
)

Find the weak successor of item in the sorted collection, that is, the least item in the collection greater than or equal to the supplied value.

Parameters
itemThe item to find the weak successor for.
resThe weak successor, if any; otherwise the default value for T.
Returns
True if item has a weak successor; otherwise false.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

T C5.ISorted< T >.WeakPredecessor ( item)

Find the weak predecessor in the sorted collection of a particular value, that is, the largest item in the collection less than or equal to the supplied value.

Exceptions
NoSuchItemExceptionif no such element exists (the supplied value is less than the minimum of this collection.)
Parameters
itemThe item to find the weak predecessor for.
Returns
The weak predecessor.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

T C5.ISorted< T >.WeakSuccessor ( item)

Find the weak successor in the sorted collection of a particular value, that is, the least item in the collection greater than or equal to the supplied value.

Exceptions
NoSuchItemExceptionif no such element exists (the supplied value is greater than the maximum of this collection.)

param name="item">The item to find the weak successor for.

Returns
The weak successor.

Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

Property Documentation

SCG.IComparer<T> C5.ISorted< T >.Comparer
get

The comparer object supplied at creation time for this sorted collection.

The comparer


The documentation for this interface was generated from the following file: