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
Public fields | Properties | Public Member Functions | Static Public Member Functions | List of all members
Loyc.Collections.Impl.InternalSet< T >.Enumerator Struct Reference

Source file:
Inheritance diagram for Loyc.Collections.Impl.InternalSet< T >.Enumerator:
Loyc.Collections.Impl.InternalSet< T >

Public fields

Node _currentNode
 
InternalList< Node > _stack
 
uint _hc
 
int _i
 
- Public fields inherited from Loyc.Collections.Impl.InternalSet< T >
const int BitsPerLevel = 4
 
const int FanOut = 1 << BitsPerLevel
 
const int Mask = FanOut - 1
 
const int MaxDepth = 7
 
const uint FlagMask = (uint)((1L << FanOut) - 1)
 
const int CounterPerChild = FanOut << 1
 
const short OverflowFlag = 1 << 12
 
Node _root
 

Properties

Current [get]
 
object
System.Collections.IEnumerator. 
Current [get]
 
- Properties inherited from Loyc.Collections.Impl.InternalSet< T >
bool IsRootFrozen [get]
 
bool HasRoot [get]
 

Public Member Functions

 Enumerator (InternalSet< T > set)
 
void Reset (InternalSet< T > set)
 
bool MoveNext ()
 
void SetCurrentValue (T value, ref InternalSet< T > set, IEqualityComparer< T > comparer)
 Changes the value associated with the current key. More...
 
bool RemoveCurrent (ref InternalSet< T > set)
 Removes the current item from the set, and moves to the next item. More...
 
void IDisposable. Dispose ()
 
void
System.Collections.IEnumerator. 
Reset ()
 
- Public Member Functions inherited from Loyc.Collections.Impl.InternalSet< T >
 InternalSet (IEnumerable< T > list, IEqualityComparer< T > comparer, out int count)
 
 InternalSet (IEnumerable< T > list, IEqualityComparer< T > comparer)
 
int GetSetHashCode (IEqualityComparer< T > comparer)
 
InternalSet< T > CloneFreeze ()
 Freezes the hashtrie so that any further changes require paths in the tree to be copied. More...
 
void Thaw ()
 Thaws a frozen root node by duplicating it, or creates the root node if the set doesn't have one. More...
 
bool Add (ref T item, IEqualityComparer< T > comparer, bool replaceIfPresent)
 Tries to add an item to the set, and retrieves the existing item if present. More...
 
bool Remove (ref T item, IEqualityComparer< T > comparer)
 Removes an item from the set. More...
 
delegate bool OnFoundExisting (ref Node slots, int i, T item)
 
bool Find (ref T item, IEqualityComparer< T > comparer)
 
Enumerator GetEnumerator ()
 
IEnumerator< T > IEnumerable< T >. GetEnumerator ()
 
System.Collections.IEnumerator
System.Collections.IEnumerable. 
GetEnumerator ()
 
void CopyTo (T[] array, int arrayIndex)
 
void Clear ()
 
bool Contains (T item, IEqualityComparer< T > comparer)
 
int Count ()
 
int UnionWith (IEnumerable< T > other, IEqualityComparer< T > thisComparer, bool replaceIfPresent)
 Adds the contents of 'other' to this set. More...
 
int UnionWith (InternalSet< T > other, IEqualityComparer< T > thisComparer, bool replaceIfPresent)
 
int IntersectWith (InternalSet< T > other, IEqualityComparer< T > otherComparer)
 Removes all items from this set that are not present in 'other'. More...
 
int IntersectWith (ISet< T > other)
 
int IntersectWith (IEnumerable< T > other, IEqualityComparer< T > comparer)
 Removes all items from this set that are not present in 'other'. More...
 
int ExceptWith (IEnumerable< T > other, IEqualityComparer< T > thisComparer)
 Removes all items from this set that are present in 'other'. More...
 
int ExceptWith (InternalSet< T > other, IEqualityComparer< T > thisComparer)
 
int SymmetricExceptWith (InternalSet< T > other, IEqualityComparer< T > thisComparer)
 
int SymmetricExceptWith (IEnumerable< T > other, IEqualityComparer< T > comparer, bool xorDuplicates=true)
 Modifies the current set to contain only elements that were present either in this set or in the other collection, but not both. More...
 
bool IsSubsetOf (ISet< T > other, int myMinCount)
 Returns true if all items in this set are present in the other set. More...
 
bool IsSubsetOf (InternalSet< T > other, IEqualityComparer< T > otherComparer)
 
bool IsSubsetOf (IEnumerable< T > other, IEqualityComparer< T > comparer, int myMinCount=0)
 
bool IsSupersetOf (IEnumerable< T > other, IEqualityComparer< T > thisComparer, int myMaxCount=int.MaxValue)
 Returns true if all items in the other set are present in this set. More...
 
bool IsSupersetOf (InternalSet< T > other, IEqualityComparer< T > thisComparer)
 
bool Overlaps (IEnumerable< T > other, IEqualityComparer< T > thisComparer)
 Returns true if this set contains at least one item from 'other'. More...
 
bool Overlaps (InternalSet< T > other, IEqualityComparer< T > thisComparer)
 
bool IsProperSubsetOf (ISet< T > other, int myExactCount)
 Returns true if all items in this set are present in the other set, and the other set has at least one item that is not in this set. More...
 
bool IsProperSubsetOf (IEnumerable< T > other, IEqualityComparer< T > comparer, int myExactCount)
 Returns true if all items in this set are present in the other set, and the other set has at least one item that is not in this set. More...
 
bool IsProperSupersetOf (ISet< T > other, IEqualityComparer< T > thisComparer, int myExactCount)
 Returns true if all items in the other set are present in this set, and this set has at least one item that is not in the other set. More...
 
bool IsProperSupersetOf (IEnumerable< T > other, IEqualityComparer< T > comparer, int myExactCount)
 Returns true if all items in the other set are present in this set, and this set has at least one item that is not in the other set. More...
 
bool SetEquals (ISet< T > other, int myExactCount)
 Returns true if this set and the other set have the same items. More...
 
bool SetEquals (IEnumerable< T > other, IEqualityComparer< T > comparer, int myExactCount)
 Returns true if this set and the other set have the same items. More...
 
int CountMemory (int sizeOfT)
 Measures the total size of all objects allocated to this collection, in bytes, including the size of InternalSet{T} itself (which is one word). More...
 
int CountMemory (int sizeOfT, out InternalSetStats stats)
 Measures the total size of all objects allocated to this collection, in bytes, and counts the number of nodes of different types. More...
 

Static Public Member Functions

static void SetCurrentValueCore (ref T slot, T value, IEqualityComparer< T > comparer)
 
- Static Public Member Functions inherited from Loyc.Collections.Impl.InternalSet< T >
static Node FrozenEmptyRoot ()
 
static int Adj (int i, int n)
 
static bool Equals (T value, ref T item, IEqualityComparer< T > comparer)
 
static uint GetHashCode (T item, IEqualityComparer< T > comparer)
 
static void PropagateFrozenFlag (Node parent, Node child)
 
static void ReplaceChild (ref Node slots, int iHome, Node newChild)
 
static bool TryRemoveChild (ref Node slots, int iHome, Node child)
 
static bool _IgnoreExisting_ (ref Node slots, int i, T item)
 
static bool _ReplaceExisting_ (ref Node slots, int i, T item)
 
static bool _DeleteExisting_ (ref Node slots, int i, T item)
 
static bool AddOrRemove (ref Node slots, ref T item, uint hc, IEqualityComparer< T > comparer, OnFoundExisting mode)
 
static bool OnFoundInOverflow (ref Node slots, int i, ref T item, OnFoundExisting mode, T existing)
 
static int SelectBucketToSpill (Node slots, int i0, IEqualityComparer< T > comparer)
 
static void Spill (Node parent, int i0, IEqualityComparer< T > comparer)
 
static Enumerator SetOperationEnumerator ()
 

Additional Inherited Members

- Public static fields inherited from Loyc.Collections.Impl.InternalSet< T >
static readonly InternalSet< T > Empty = new InternalSet<T> { _root = FrozenEmptyRoot() }
 An empty set. More...
 
static readonly
IEqualityComparer< T > 
DefaultComparer = typeof(IReferenceComparable).IsAssignableFrom(typeof(T)) ? null : EqualityComparer<T>.Default
 This is EqualityComparer{T}.Default, or null if T implements IReferenceComparable. More...
 
static readonly OnFoundExisting AddIfNotPresent = _IgnoreExisting_
 
static readonly OnFoundExisting AddOrReplace = _ReplaceExisting_
 
static readonly OnFoundExisting RemoveMode = _DeleteExisting_
 
static Enumerator _setOperationEnumerator
 

Member Function Documentation

bool Loyc.Collections.Impl.InternalSet< T >.Enumerator.RemoveCurrent ( ref InternalSet< T >  set)
inline

Removes the current item from the set, and moves to the next item.

Returns
As with MoveNext, returns true if there is another item after the current one and false if not.

Efficiency note: a normal Remove operation can delete a child node when there are still two items left in the child (the items can be transferred to the parent node). RemoveCurrent, however, only deletes child nodes that become completely empty, because it would be very difficult to implement MoveNext() correctly (meaning, it would be very difficult to enumerate every item exactly once) if the tree were "rebalanced" like this during enumeration.

Therefore, in rare cases, a set whose size decreases via this method will use significantly more memory than necessary. And in general, adding new items later will not re-use the mostly-empty nodes unless the new items used to be in the set (or have similar hashcodes).

void Loyc.Collections.Impl.InternalSet< T >.Enumerator.SetCurrentValue ( value,
ref InternalSet< T >  set,
IEqualityComparer< T >  comparer 
)
inline

Changes the value associated with the current key.

Parameters
comparerOptional. If comparer!=null, it is used to verify that the new value is equal to the old value.
Exceptions
ArgumentExceptionAccording to the comparer provided, the new value is not "equal" to the old value.

The new value must compare equal to the old value, since the new value is placed at the same location in the trie. If a value is placed in the wrong location, it becomes irretrievable (except via enumerator), as search methods will be looking elsewhere for it.