Enhanced C#
Language of your choice: library documentation

Documentation moved to ecsharp.net

GitHub doesn't support HTTP redirects, so you'll be redirected in 3 seconds.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Properties | Public Member Functions | Static Public Member Functions | List of all members
Loyc.Collections.MSet< T > Class Template Reference

A mutable set. More...


Source file:
Inheritance diagram for Loyc.Collections.MSet< T >:
Loyc.Collections.ISinkCollection< T > Loyc.ICloneable< out T > Loyc.Collections.ISetImm< T, SetT > Loyc.Collections.ISetImm< T >

Remarks

A mutable set.

This class is based on Impl.InternalSet{T}; see its documentation for technical details about the implementation.

Assuming T is a reference type, this class uses less memory than HashSet{T} and, under certain conditions, is faster. Specifically,

This class may be slower than HashSet{T} if the comparison method for T is slow; up to four comparisons are required per add/remove operation.

You can convert MSet{T} to Set{T} and back in O(1) time using a C# cast operator.

Performance warning: GetHashCode() XORs the hashcodes of all items in the set, while Equals() is a synonym for SetEquals(). Be aware that these methods are very slow for large sets.

Properties

bool IsEmpty [get]
 
InternalSet< T > FrozenInternalSet [get]
 
IEqualityComparer< T > Comparer [get]
 
int Count [get]
 
bool IsReadOnly [get]
 
- Properties inherited from Loyc.Collections.ISetImm< T, SetT >
bool IsInverted [get]
 Returns true if the set is inverted, which means that the enumerator returns all the items that are not in the set, and the IReadOnlyCollection{T}.Count returns the number of items that are not in the set. More...
 

Public Member Functions

 MSet (IEnumerable< T > copy)
 
 MSet (IEnumerable< T > copy, IEqualityComparer< T > comparer)
 
 MSet (IEqualityComparer< T > comparer)
 
 MSet (InternalSet< T > set, IEqualityComparer< T > comparer)
 
void AddUnique (T item)
 Adds the specified item to the set, or throws an exception if a matching item is already present. More...
 
bool Find (ref T item)
 Searches for an item. If the item is found, the copy in the set is returned in the 'item' parameter. Note: there is no reason to call this method in a set of completely immutable; in such cases, call Contains instead. More...
 
bool AddOrFind (ref T item, bool replaceIfPresent)
 Adds the specified item to the set, and retrieves an existing copy of the item if one existed. Note: there is no reason to call this method in a set of singletons (e.g. Symbol) because if an item is found, it will always be the exact same object that you searched for. More...
 
bool Add (T item, bool replaceIfPresent)
 Adds the specified item to the set. More...
 
virtual MSet< T > Clone ()
 Fast-clones the set in O(1) time. More...
 
override bool Equals (object obj)
 
override int GetHashCode ()
 
bool Add (T item)
 Adds the specified item to the set if it is not present. More...
 
int AddRange (IEnumerable< T > items)
 
void Clear ()
 
bool Contains (T item)
 
void CopyTo (T[] array, int arrayIndex)
 
bool Remove (T item)
 
bool Remove (ref T item)
 
InternalSet< T >.Enumerator GetEnumerator ()
 
int UnionWith (IEnumerable< T > other, bool replaceIfPresent=false)
 
int UnionWith (Set< T > other, bool replaceIfPresent=false)
 
int UnionWith (MSet< T > other, bool replaceIfPresent=false)
 
int ExceptWith (IEnumerable< T > other)
 
int ExceptWith (Set< T > other)
 
int ExceptWith (MSet< T > other)
 
int IntersectWith (IEnumerable< T > other)
 
int IntersectWith (Set< T > other)
 Removes all items from this set that are not present in 'other'. More...
 
int IntersectWith (MSet< T > other)
 Removes all items from this set that are not present in 'other'. More...
 
int IntersectWith (ISet< T > other)
 Removes all items from this set that are not present in 'other'. More...
 
int SymmetricExceptWith (IEnumerable< T > other)
 Modifies the current set to contain only elements that were present either in this set or in the other collection, but not both. More...
 
int SymmetricExceptWith (IEnumerable< T > other, bool xorDuplicates)
 
int SymmetricExceptWith (Set< T > other)
 
int SymmetricExceptWith (MSet< T > other)
 
bool IsSubsetOf (IEnumerable< T > other)
 Returns true if all items in this set are present in the other set. More...
 
bool IsSubsetOf (Set< T > other)
 
bool IsSubsetOf (MSet< T > other)
 
bool IsSubsetOf (ISet< T > other)
 
bool IsSupersetOf (IEnumerable< T > other)
 Returns true if all items in the other set are present in this set. More...
 
bool IsSupersetOf (Set< T > other)
 
bool IsSupersetOf (MSet< T > other)
 
bool Overlaps (IEnumerable< T > other)
 Returns true if this set contains at least one item from 'other'. More...
 
bool Overlaps (Set< T > other)
 
bool Overlaps (MSet< T > other)
 
bool IsProperSubsetOf (Set< T > other)
 
bool IsProperSubsetOf (MSet< T > other)
 
bool IsProperSubsetOf (ISet< T > other)
 
bool IsProperSubsetOf (IEnumerable< T > other)
 
bool IsProperSupersetOf (Set< T > other)
 
bool IsProperSupersetOf (MSet< T > other)
 
bool IsProperSupersetOf (ISet< T > other)
 
bool IsProperSupersetOf (IEnumerable< T > other)
 
bool SetEquals (Set< T > other)
 
bool SetEquals (MSet< T > other)
 
bool SetEquals (ISet< T > other)
 
bool SetEquals (IEnumerable< T > other)
 
MSet< T > With (T item)
 
MSet< T > Without (T item)
 
MSet< T > Union (Set< T > other, bool replaceWithValuesFromOther=false)
 
MSet< T > Union (MSet< T > other)
 
MSet< T > Union (MSet< T > other, bool replaceWithValuesFromOther)
 
MSet< T > Union (IEnumerable< T > other, bool replaceWithValuesFromOther=false)
 
MSet< T > Intersect (Set< T > other)
 
MSet< T > Intersect (MSet< T > other)
 
MSet< T > Intersect (IEnumerable< T > other)
 
MSet< T > Except (Set< T > other)
 
MSet< T > Except (MSet< T > other)
 
MSet< T > Except (IEnumerable< T > other)
 
MSet< T > Xor (Set< T > other)
 
MSet< T > Xor (MSet< T > other)
 
MSet< T > Xor (IEnumerable< T > other)
 
Set< T > AsImmutable ()
 
int RemoveWhere (Predicate< T > match)
 Removes all elements that match the conditions defined by the specified predicate from this collection. More...
 
bool Toggle (T item)
 Toggle's an object's presence in the set. More...
 
void ThawRoot ()
 
long CountMemory (int sizeOfT)
 Measures the total size of all objects allocated to this collection, in bytes, including the size of this object itself; see Impl.InternalSet{T}.CountMemory. More...
 
- Public Member Functions inherited from Loyc.Collections.ISetOperations< in T, in InSetT, out OutSetT >
OutSetT Union (InSetT other)
 
OutSetT Intersect (InSetT other)
 
OutSetT Except (InSetT other)
 
OutSetT Xor (InSetT other)
 

Static Public Member Functions

static MSet< T > operator& (MSet< T > a, MSet< T > b)
 
static MSet< T > operator& (MSet< T > a, Set< T > b)
 
static MSet< T > operator| (MSet< T > a, MSet< T > b)
 
static MSet< T > operator| (MSet< T > a, Set< T > b)
 
static MSet< T > operator- (MSet< T > a, MSet< T > b)
 
static MSet< T > operator- (MSet< T > a, Set< T > b)
 
static MSet< T > operator^ (MSet< T > a, MSet< T > b)
 
static MSet< T > operator^ (MSet< T > a, Set< T > b)
 
static MSet< T > operator+ (T item, MSet< T > a)
 
static MSet< T > operator+ (MSet< T > a, T item)
 
static MSet< T > operator- (MSet< T > a, T item)
 
static MSet< T > operator^ (MSet< T > a, T item)
 
static operator Set< T > (MSet< T > a)
 

Member Function Documentation

bool Loyc.Collections.MSet< T >.Add ( item,
bool  replaceIfPresent 
)
inline

Adds the specified item to the set.

Parameters
replaceIfPresentIf true, and a matching item is already present in the set, the specified item replaces the existing copy. If false, the existing copy is left alone. This parameter has no effect in a set of singletons (e.g. Symbol).
Returns
true if the item was new, false if it was already present.
bool Loyc.Collections.MSet< T >.Add ( item)
inline

Adds the specified item to the set if it is not present.

Returns
true if the item was new, false if it was not added because it was already present.

Implements Loyc.Collections.IAdd< in T >.

bool Loyc.Collections.MSet< T >.AddOrFind ( ref T  item,
bool  replaceIfPresent 
)
inline

Adds the specified item to the set, and retrieves an existing copy of the item if one existed. Note: there is no reason to call this method in a set of singletons (e.g. Symbol) because if an item is found, it will always be the exact same object that you searched for.

Parameters
itemAn object to search for. If this method returns false, this parameter is changed to the existing value that was found in the collection.
replaceIfPresentIf true, and a matching item exists in the set, that item will be replaced with the specified new item. The old value will be returned in the 'item' parameter.
Returns
True if a new item was added, false if the item already existed in the set.
void Loyc.Collections.MSet< T >.AddUnique ( item)
inline

Adds the specified item to the set, or throws an exception if a matching item is already present.

Exceptions
ArgumentExceptionThe item already exists in the set.
virtual MSet<T> Loyc.Collections.MSet< T >.Clone ( )
inlinevirtual

Fast-clones the set in O(1) time.

Once the set is cloned, modifications to both sets take longer because portions of the set must be duplicated. See Impl.InternalSet{T} for details about the fast- cloning technique.

Implements Loyc.ICloneable< out T >.

long Loyc.Collections.MSet< T >.CountMemory ( int  sizeOfT)
inline

Measures the total size of all objects allocated to this collection, in bytes, including the size of this object itself; see Impl.InternalSet{T}.CountMemory.

bool Loyc.Collections.MSet< T >.Find ( ref T  item)
inline

Searches for an item. If the item is found, the copy in the set is returned in the 'item' parameter. Note: there is no reason to call this method in a set of completely immutable; in such cases, call Contains instead.

Returns
true if the item was found, false if not.
int Loyc.Collections.MSet< T >.IntersectWith ( Set< T >  other)
inline

Removes all items from this set that are not present in 'other'.

int Loyc.Collections.MSet< T >.IntersectWith ( MSet< T >  other)
inline

Removes all items from this set that are not present in 'other'.

int Loyc.Collections.MSet< T >.IntersectWith ( ISet< T >  other)
inline

Removes all items from this set that are not present in 'other'.

bool Loyc.Collections.MSet< T >.IsSubsetOf ( IEnumerable< T >  other)
inline

Returns true if all items in this set are present in the other set.

bool Loyc.Collections.MSet< T >.IsSupersetOf ( IEnumerable< T >  other)
inline

Returns true if all items in the other set are present in this set.

bool Loyc.Collections.MSet< T >.Overlaps ( IEnumerable< T >  other)
inline

Returns true if this set contains at least one item from 'other'.

int Loyc.Collections.MSet< T >.RemoveWhere ( Predicate< T >  match)
inline

Removes all elements that match the conditions defined by the specified predicate from this collection.

Returns
The number of elements that were removed from the set.
int Loyc.Collections.MSet< T >.SymmetricExceptWith ( IEnumerable< T >  other)
inline

Modifies the current set to contain only elements that were present either in this set or in the other collection, but not both.

References Loyc.Collections.MSet< T >.SymmetricExceptWith().

Referenced by Loyc.Collections.MSet< T >.SymmetricExceptWith().

bool Loyc.Collections.MSet< T >.Toggle ( item)
inline

Toggle's an object's presence in the set.

Returns
true if the item was added, false if the item was removed.

References Loyc.Collections.Remove.