Enhanced C#
Language of your choice: library documentation
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:

Public fields

Node _currentNode
 
InternalList< Node > _stack
 
uint _hc
 
int _i
 

Properties

Current [get]
 
object System.Collections.IEnumerator. Current [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 ()
 

Static Public Member Functions

static void SetCurrentValueCore (ref T slot, T value, IEqualityComparer< T > comparer)
 

Member Function Documentation

◆ RemoveCurrent()

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).

◆ SetCurrentValue()

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.