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.HashSet< T > Class Template Reference

A set collection class based on linear hashing More...

Inheritance diagram for C5.HashSet< T >:
C5.CollectionBase< T > C5.ICollection< T > C5.CollectionValueBase< T > C5.IExtensible< T > C5.EnumerableBase< T > C5.ICollectionValue< T > C5.IShowable C5.ICollectionValue< T > C5.IShowable C5.IShowable

Public Member Functions

 HashSet ()
 Create a hash set with natural item equalityComparer and default fill threshold (66%) and initial table size (16). More...
 
 HashSet (SCG.IEqualityComparer< T > itemequalityComparer)
 Create a hash set with external item equalityComparer and default fill threshold (66%) and initial table size (16). More...
 
 HashSet (int capacity, SCG.IEqualityComparer< T > itemequalityComparer)
 Create a hash set with external item equalityComparer and default fill threshold (66%) More...
 
 HashSet (int capacity, double fill, SCG.IEqualityComparer< T > itemequalityComparer)
 Create a hash set with external item equalityComparer. More...
 
virtual bool Contains (T item)
 Check if an item is in the set More...
 
virtual bool Find (ref T item)
 Check if an item (collection equal to a given one) is in the set and if so report the actual item object found. More...
 
virtual bool Update (T item)
 Check if an item (collection equal to a given one) is in the set and if so replace the item object in the set with the supplied one. More...
 
virtual bool Update (T item, out T olditem)
 Check if an item (collection equal to a given one) is in the set and if so replace the item object in the set with the supplied one. More...
 
virtual bool FindOrAdd (ref T item)
 Check if an item (collection equal to a given one) is in the set. If found, report the actual item object in the set, else add the supplied one. More...
 
virtual bool UpdateOrAdd (T item)
 Check if an item (collection equal to a supplied one) is in the set and if so replace the item object in the set with the supplied one; else add the supplied one. More...
 
virtual bool UpdateOrAdd (T item, out T olditem)
 Check if an item (collection equal to a supplied one) is in the set and if so replace the item object in the set with the supplied one; else add the supplied one. More...
 
virtual bool Remove (T item)
 Remove an item from the set More...
 
virtual bool Remove (T item, out T removeditem)
 Remove an item from the set, reporting the actual matching item object. More...
 
virtual void RemoveAll (SCG.IEnumerable< T > items)
 Remove all items in a supplied collection from this set. More...
 
virtual void Clear ()
 Remove all items from the set, resetting internal table to initial size. More...
 
virtual void RetainAll (SCG.IEnumerable< T > items)
 Remove all items not in a supplied collection from this set. More...
 
virtual bool ContainsAll (SCG.IEnumerable< T > items)
 Check if all items in a supplied collection is in this set (ignoring multiplicities). More...
 
override T[] ToArray ()
 Create an array containing all items in this set (in enumeration order). More...
 
virtual int ContainsCount (T item)
 Count the number of times an item is in this set (either 0 or 1). More...
 
virtual ICollectionValue< T > UniqueItems ()
 
virtual ICollectionValue< KeyValuePair< T, int > > ItemMultiplicities ()
 
virtual void RemoveAllCopies (T item)
 Remove all (at most 1) copies of item from this set. More...
 
override T Choose ()
 Choose some item of this collection. More...
 
override SCG.IEnumerator< T > GetEnumerator ()
 Create an enumerator for this set. More...
 
virtual bool Add (T item)
 Add an item to this set. More...
 
virtual void AddAll (SCG.IEnumerable< T > items)
 Add the elements from another collection with a more specialized item type to this collection. Since this collection has set semantics, only items not already in the collection will be added. More...
 
virtual bool Check ()
 Test internal structure of data (invariants) More...
 
ISortedDictionary< int, int > BucketCostDistribution ()
 Produce statistics on distribution of bucket sizes. Current implementation is incomplete. More...
 
- Public Member Functions inherited from C5.CollectionBase< T >
virtual int GetUnsequencedHashCode ()
 Get the unsequenced collection hash code of this collection: from the cached value if present and up to date, else (re)compute. More...
 
virtual bool UnsequencedEquals (ICollection< T > otherCollection)
 Check if the contents of otherCollection is equal to the contents of this in the unsequenced sense. Uses the item equality comparer of this collection More...
 
- Public Member Functions inherited from C5.CollectionValueBase< T >
virtual void CopyTo (T[] array, int index)
 Copy the items of this collection to part of an array. More...
 
virtual void Apply (Action< T > action)
 Apply an single argument action, T:Action`1 to this enumerable More...
 
virtual bool Exists (Func< T, bool > predicate)
 Check if there exists an item that satisfies a specific predicate in this collection. More...
 
virtual 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...
 
virtual bool All (Func< T, bool > predicate)
 Check if all items in this collection satisfies a specific predicate. More...
 
virtual SCG.IEnumerable< T > Filter (Func< T, bool > predicate)
 Create an enumerable, enumerating the items of this collection that satisfies a certain condition. More...
 
virtual bool Show (System.Text.StringBuilder stringbuilder, ref int rest, IFormatProvider formatProvider)
 
virtual string ToString (string format, IFormatProvider formatProvider)
 
override string ToString ()
 
- Public Member Functions inherited from C5.IShowable
bool Show (StringBuilder stringbuilder, ref int rest, IFormatProvider formatProvider)
 Format More...
 
- Public Member Functions inherited from C5.ICollection< T >
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...
 

Properties

static Feature Features [get]
 Show which implementation features was chosen at compilation time More...
 
override EventTypeEnum ListenableEvents [get]
 
virtual Speed ContainsSpeed [get]
 The complexity of the Contains operation More...
 
virtual bool AllowsDuplicates [get]
 Report if this is a set collection. More...
 
virtual bool DuplicatesByCounting [get]
 By convention this is true for any collection with set semantics. More...
 
- Properties inherited from C5.CollectionBase< T >
virtual bool IsReadOnly [get]
 
override int Count [get]
 
override 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...
 
virtual SCG.IEqualityComparer< T > EqualityComparer [get]
 
override bool IsEmpty [get]
 
- Properties inherited from C5.CollectionValueBase< T >
virtual EventTypeEnum ListenableEvents [get]
 
virtual EventTypeEnum ActiveEvents [get]
 A flag bitmap of the events currently subscribed to by this collection. More...
 
virtual CollectionChangedHandler< T > CollectionChanged
 The change event. Will be raised for every change operation on the collection. More...
 
virtual CollectionClearedHandler< T > CollectionCleared
 The clear event. Will be raised for every Clear operation on the collection. More...
 
virtual ItemsAddedHandler< T > ItemsAdded
 The item added event. Will be raised for every individual addition to the collection. More...
 
virtual ItemsRemovedHandler< T > ItemsRemoved
 The item removed event. Will be raised for every individual removal from the collection. More...
 
virtual ItemInsertedHandler< T > ItemInserted
 The item added event. Will be raised for every individual addition to the collection. More...
 
virtual ItemRemovedAtHandler< T > ItemRemovedAt
 The item removed event. Will be raised for every individual removal from the collection. More...
 
abstract bool IsEmpty [get]
 Check if collection is empty. More...
 
abstract int Count [get]
 The number of items in this collection. More...
 
abstract 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.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.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...
 

Additional Inherited Members

- Static Public Member Functions inherited from C5.CollectionBase< T >
static int ComputeHashCode (ICollectionValue< T > items, SCG.IEqualityComparer< T > itemequalityComparer)
 Compute the unsequenced hash code of a collection More...
 
static bool StaticEquals (ICollection< T > collection1, ICollection< T > collection2, SCG.IEqualityComparer< T > itemequalityComparer)
 Examine if collection1 and collection2 are equal as unsequenced collections using the specified item equalityComparer (assumed compatible with the two collections). More...
 
- Protected Member Functions inherited from C5.CollectionBase< T >
 CollectionBase (SCG.IEqualityComparer< T > itemequalityComparer)
 
void checkRange (int start, int count)
 Utility method for range checking. More...
 
virtual void modifycheck (int thestamp)
 Check if the collection has been modified since a specified time, expressed as a stamp value. More...
 
virtual void updatecheck ()
 Check if it is valid to perform update operations, and if so increment stamp. More...
 
- Protected Member Functions inherited from C5.CollectionValueBase< T >
virtual void raiseCollectionChanged ()
 Fire the CollectionChanged event More...
 
virtual void raiseCollectionCleared (bool full, int count)
 Fire the CollectionCleared event More...
 
virtual void raiseCollectionCleared (bool full, int count, int?offset)
 Fire the CollectionCleared event More...
 
virtual void raiseItemsAdded (T item, int count)
 Fire the ItemsAdded event More...
 
virtual void raiseItemsRemoved (T item, int count)
 Fire the ItemsRemoved event More...
 
virtual void raiseItemInserted (T item, int index)
 Fire the ItemInserted event More...
 
virtual void raiseItemRemovedAt (T item, int index)
 Fire the ItemRemovedAt event More...
 
virtual void raiseForSetThis (int index, T value, T item)
 
virtual void raiseForInsert (int i, T item)
 
void raiseForRemove (T item)
 
void raiseForRemove (T item, int count)
 
void raiseForRemoveAt (int index, T item)
 
virtual void raiseForUpdate (T newitem, T olditem)
 
virtual void raiseForUpdate (T newitem, T olditem, int count)
 
virtual void raiseForAdd (T item)
 
virtual void raiseForRemoveAll (ICollectionValue< T > wasRemoved)
 
- Static Protected Member Functions inherited from C5.EnumerableBase< T >
static int countItems (SCG.IEnumerable< T > items)
 Count the number of items in an enumerable by enumeration More...
 
- Protected Attributes inherited from C5.CollectionBase< T >
bool isReadOnlyBase = false
 The underlying field of the ReadOnly property More...
 
int stamp
 The current stamp value More...
 
int size
 The number of items in the collection More...
 
readonly SCG.IEqualityComparer< T > itemequalityComparer
 The item equalityComparer of the collection More...
 
- 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 set collection class based on linear hashing

Constructor & Destructor Documentation

C5.HashSet< T >.HashSet ( )

Create a hash set with natural item equalityComparer and default fill threshold (66%) and initial table size (16).

C5.HashSet< T >.HashSet ( SCG.IEqualityComparer< T >  itemequalityComparer)

Create a hash set with external item equalityComparer and default fill threshold (66%) and initial table size (16).

Parameters
itemequalityComparerThe external item equalitySCG.Comparer
C5.HashSet< T >.HashSet ( int  capacity,
SCG.IEqualityComparer< T >  itemequalityComparer 
)

Create a hash set with external item equalityComparer and default fill threshold (66%)

Parameters
capacityInitial table size (rounded to power of 2, at least 16)
itemequalityComparerThe external item equalitySCG.Comparer
C5.HashSet< T >.HashSet ( int  capacity,
double  fill,
SCG.IEqualityComparer< T >  itemequalityComparer 
)

Create a hash set with external item equalityComparer.

Parameters
capacityInitial table size (rounded to power of 2, at least 16)
fillFill threshold (in range 10% to 90%)
itemequalityComparerThe external item equalitySCG.Comparer

Member Function Documentation

virtual bool C5.HashSet< T >.Add ( item)
virtual

Add an item to this set.

Parameters
itemThe item to add.
Returns
True if item was added (i.e. not found)

Implements C5.ICollection< T >.

virtual void C5.HashSet< T >.AddAll ( SCG.IEnumerable< T >  items)
virtual

Add the elements from another collection with a more specialized item type to this collection. Since this collection has set semantics, only items not already in the collection will be added.

Parameters
itemsThe items to add

Implements C5.IExtensible< T >.

ISortedDictionary<int, int> C5.HashSet< T >.BucketCostDistribution ( )

Produce statistics on distribution of bucket sizes. Current implementation is incomplete.

Returns
Histogram data.
virtual bool C5.HashSet< T >.Check ( )
virtual

Test internal structure of data (invariants)

Returns
True if pass

Implements C5.IExtensible< T >.

override T C5.HashSet< T >.Choose ( )
virtual

Choose some item of this collection.

Exceptions
NoSuchItemExceptionif collection is empty.
Returns

Implements C5.CollectionValueBase< T >.

virtual void C5.HashSet< T >.Clear ( )
virtual

Remove all items from the set, resetting internal table to initial size.

Implements C5.ICollection< T >.

virtual bool C5.HashSet< T >.Contains ( item)
virtual

Check if an item is in the set

Parameters
itemThe item to look for
Returns
True if set contains item

Implements C5.ICollection< T >.

virtual bool C5.HashSet< T >.ContainsAll ( SCG.IEnumerable< T >  items)
virtual

Check if all items in a supplied collection is in this set (ignoring multiplicities).

Parameters
itemsThe items to look for.
Returns
True if all items are found.

Implements C5.ICollection< T >.

virtual int C5.HashSet< T >.ContainsCount ( item)
virtual

Count the number of times an item is in this set (either 0 or 1).

Parameters
itemThe item to look for.
Returns
1 if item is in set, 0 else

Implements C5.ICollection< T >.

virtual bool C5.HashSet< T >.Find ( ref T  item)
virtual

Check if an item (collection equal to a given one) is in the set and if so report the actual item object found.

Parameters
itemOn entry, the item to look for. On exit the item found, if any
Returns
True if set contains item

Implements C5.ICollection< T >.

virtual bool C5.HashSet< T >.FindOrAdd ( ref T  item)
virtual

Check if an item (collection equal to a given one) is in the set. If found, report the actual item object in the set, else add the supplied one.

Parameters
itemOn entry, the item to look for or add. On exit the actual object found, if any.
Returns
True if item was found

Implements C5.ICollection< T >.

override SCG.IEnumerator<T> C5.HashSet< T >.GetEnumerator ( )
virtual

Create an enumerator for this set.

Returns
The enumerator

Implements C5.CollectionBase< T >.

virtual ICollectionValue<KeyValuePair<T, int> > C5.HashSet< T >.ItemMultiplicities ( )
virtual

Returns

Implements C5.ICollection< T >.

virtual bool C5.HashSet< T >.Remove ( item)
virtual

Remove an item from the set

Parameters
itemThe item to remove
Returns
True if item was (found and) removed

Implements C5.ICollection< T >.

virtual bool C5.HashSet< T >.Remove ( item,
out T  removeditem 
)
virtual

Remove an item from the set, reporting the actual matching item object.

Parameters
itemThe value to remove.
removeditemThe removed value.
Returns
True if item was found.

Implements C5.ICollection< T >.

virtual void C5.HashSet< T >.RemoveAll ( SCG.IEnumerable< T >  items)
virtual

Remove all items in a supplied collection from this set.

Parameters
itemsThe items to remove.

Implements C5.ICollection< T >.

virtual void C5.HashSet< T >.RemoveAllCopies ( item)
virtual

Remove all (at most 1) copies of item from this set.

Parameters
itemThe item to remove

Implements C5.ICollection< T >.

virtual void C5.HashSet< T >.RetainAll ( SCG.IEnumerable< T >  items)
virtual

Remove all items not in a supplied collection from this set.

Parameters
itemsThe items to retain

Implements C5.ICollection< T >.

override T [] C5.HashSet< T >.ToArray ( )
virtual

Create an array containing all items in this set (in enumeration order).

Returns
The array

Reimplemented from C5.CollectionValueBase< T >.

virtual ICollectionValue<T> C5.HashSet< T >.UniqueItems ( )
virtual

Returns

Implements C5.ICollection< T >.

virtual bool C5.HashSet< T >.Update ( item)
virtual

Check if an item (collection equal to a given one) is in the set and if so replace the item object in the set with the supplied one.

Parameters
itemThe item object to update with
Returns
True if item was found (and updated)

Implements C5.ICollection< T >.

virtual bool C5.HashSet< T >.Update ( item,
out T  olditem 
)
virtual

Check if an item (collection equal to a given one) is in the set and if so replace the item object in the set with the supplied one.

Parameters
itemThe item object to update with
olditem
Returns
True if item was found (and updated)

Implements C5.ICollection< T >.

virtual bool C5.HashSet< T >.UpdateOrAdd ( item)
virtual

Check if an item (collection equal to a supplied one) is in the set and if so replace the item object in the set with the supplied one; else add the supplied one.

Parameters
itemThe item to look for and update or add
Returns
True if item was updated

Implements C5.ICollection< T >.

virtual bool C5.HashSet< T >.UpdateOrAdd ( item,
out T  olditem 
)
virtual

Check if an item (collection equal to a supplied one) is in the set and if so replace the item object in the set with the supplied one; else add the supplied one.

Parameters
itemThe item to look for and update or add
olditem
Returns
True if item was updated

Implements C5.ICollection< T >.

Property Documentation

virtual bool C5.HashSet< T >.AllowsDuplicates
get

Report if this is a set collection.

Always false

virtual Speed C5.HashSet< T >.ContainsSpeed
get

The complexity of the Contains operation

Always returns Speed.Constant

virtual bool C5.HashSet< T >.DuplicatesByCounting
get

By convention this is true for any collection with set semantics.

True if only one representative of a group of equal items is kept in the collection together with the total count.

Feature C5.HashSet< T >.Features
staticget

Show which implementation features was chosen at compilation time

override EventTypeEnum C5.HashSet< T >.ListenableEvents
get


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