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.

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...
Public Member Functions  
T  FindMin () 
Find the current least item of this sorted collection. More...  
T  DeleteMin () 
Remove the least item from this sorted collection. More...  
T  FindMax () 
Find the current largest item of this sorted collection. More...  
T  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...  
T  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...  
T  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...  
T  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...  
T  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...  
T  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 (worstcase 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 (worstcase 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...  
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
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.
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.
ArgumentException  if the enumerated items turns out not to be in increasing order. 
items  The 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
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 signchange condition, the result of this call is undefined.
cutFunction  The cut function T
int
CompareTo
IComparable<T>

low  Returns the largest item in the collection, where the cut function is positive (if any). 
lowIsValid  Returns true if the cut function is positive somewhere on this collection. 
high  Returns the least item in the collection, where the cut function is negative (if any). 
highIsValid  Returns true if the cut function is negative 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.
NoSuchItemException  if the collection is empty. 
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.
NoSuchItemException  if the collection is empty. 
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.
NoSuchItemException  if the collection is empty. 
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.
NoSuchItemException  if the collection is empty. 
Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.SortedArray< T >, and C5.GuardedSorted< T >.
T C5.ISorted< T >.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.
NoSuchItemException  if no such element exists (the supplied value is less than or equal to the minimum of this collection.) 
item  The item to find the predecessor for. 
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.
Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.
IDirectedEnumerable<T> C5.ISorted< T >.RangeFrom  (  T  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.
bot  The lower bound (inclusive). 
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  (  T  bot, 
T  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.
bot  The lower bound (inclusive). 
top  The upper bound (exclusive). 
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  (  T  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.
top  The upper bound (exclusive). 
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  (  T  low  ) 
Remove all items of this collection above or at a supplied threshold.
low  The lower threshold (inclusive). 
Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.
void C5.ISorted< T >.RemoveRangeFromTo  (  T  low, 
T  hi  
) 
Remove all items of this collection between two supplied thresholds.
low  The lower threshold (inclusive). 
hi  The upper threshold (exclusive). 
Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.
void C5.ISorted< T >.RemoveRangeTo  (  T  hi  ) 
Remove all items of this collection below a supplied threshold.
hi  The upper threshold (exclusive). 
Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.
T C5.ISorted< T >.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.
NoSuchItemException  if no such element exists (the supplied value is greater than or equal to the maximum of this collection.) 
item  The item to find the successor for. 
Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.
bool C5.ISorted< T >.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.
item  The item to find the predecessor for. 
res  The predecessor, if any; otherwise the default value for T. 
Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.
bool C5.ISorted< T >.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.
item  The item to find the successor for. 
res  The successor, if any; otherwise the default value for T. 
Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.
bool C5.ISorted< T >.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.
item  The item to find the weak predecessor for. 
res  The weak predecessor, if any; otherwise the default value for T. 
Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.
bool C5.ISorted< T >.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.
item  The item to find the weak successor for. 
res  The weak successor, if any; otherwise the default value for T. 
Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.
T C5.ISorted< T >.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.
NoSuchItemException  if no such element exists (the supplied value is less than the minimum of this collection.) 
item  The item to find the weak predecessor for. 
Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.
T C5.ISorted< T >.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.
NoSuchItemException  if 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.
Implemented in C5.TreeBag< T >, C5.TreeSet< T >, C5.GuardedSorted< T >, and C5.SortedArray< T >.

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