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 Member Functions | Protected Member Functions | Static Protected Member Functions | Protected static fields | List of all members
Loyc.Collections.CPTrie< T > Class Template Reference

Compact patricia tree class that stores keys as byte arrays. This class is intended to be use as a base class; a derived class can give meaning to the byte arrays, e.g. CPStringTrie encodes strings into byte arrays so they can be placed in the trie. More...


Source file:
Inheritance diagram for Loyc.Collections.CPTrie< T >:
Loyc.Collections.CPStringTrie< TValue > Loyc.Collections.Impl.CPByteTrie< TValue > Loyc.Collections.Impl.CPIntTrie< TValue > Loyc.Collections.CPStringTrie< TValue >.Enumerator Loyc.Collections.CPStringTrie< TValue >.Enumerator Loyc.Collections.CPStringTrie< TValue >.KeyCollection Loyc.Collections.CPStringTrie< TValue >.KeyEnumerator Loyc.Collections.CPStringTrie< TValue >.KeyEnumerator Loyc.Collections.Impl.CPByteTrie< TValue >.Enumerator Loyc.Collections.Impl.CPByteTrie< TValue >.Enumerator Loyc.Collections.Impl.CPIntTrie< TValue >.IntEnumerator Loyc.Collections.Impl.CPIntTrie< TValue >.IntEnumerator Loyc.Collections.Impl.CPIntTrie< TValue >.LongEnumerator Loyc.Collections.Impl.CPIntTrie< TValue >.LongEnumerator

Remarks

Compact patricia tree class that stores keys as byte arrays. This class is intended to be use as a base class; a derived class can give meaning to the byte arrays, e.g. CPStringTrie encodes strings into byte arrays so they can be placed in the trie.

An article is available online the CPTrie data types.

Template Parameters
TType of values to be associated with the keys. CPTrie can save memory if many or all values are null; therefore, if you wish to store a set rather than a dictionary, set T=object and associate null with every key.

Public Member Functions

 CPTrie (CPTrie< T > copy)
 

Protected Member Functions

bool Find (ref KeyWalker key, CPEnumerator< T > e)
 
bool Find (ref KeyWalker key, ref T value)
 Retrieves the value associated with the specified key; does nothing if the key does not exist. More...
 
bool ContainsKey (ref KeyWalker key)
 
bool Set (ref KeyWalker key, ref T value, CPMode mode)
 Associates the specified value with the specified key. More...
 
bool Remove (ref KeyWalker key, ref T value)
 Removes the specified key and associated value. More...
 
bool Remove (ref KeyWalker key)
 
void Clear ()
 
int CountMemoryUsage (int sizeOfT)
 Calculates the memory usage of this object, assuming a 32-bit architecture. More...
 

Static Protected Member Functions

static StringBuilder BytesToStringBuilder (byte[] key, int keyLength)
 

Protected static fields

static Comparer< T > DefaultComparer = Comparer<T>.Default
 

Member Function Documentation

int Loyc.Collections.CPTrie< T >.CountMemoryUsage ( int  sizeOfT)
inlineprotected

Calculates the memory usage of this object, assuming a 32-bit architecture.

Parameters
sizeOfTSize of data type T. CountMemoryUsage doesn't use sizeof(T), as it would force the code to be marked "unsafe".
Returns
Estimated number of bytes used by this object
bool Loyc.Collections.CPTrie< T >.Find ( ref KeyWalker  key,
ref T  value 
)
inlineprotected

Retrieves the value associated with the specified key; does nothing if the key does not exist.

Returns
Returns true if the key was found.
bool Loyc.Collections.CPTrie< T >.Remove ( ref KeyWalker  key,
ref T  value 
)
inlineprotected

Removes the specified key and associated value.

Parameters
keyKey to find; if key.Offset > 0, bytes before that offset are ignored.
valueIf the key was found, its associated value is stored in this parameter; otherwise, the parameter is left unchanged.
Returns
Returns true if the specified key was found and removed.
bool Loyc.Collections.CPTrie< T >.Set ( ref KeyWalker  key,
ref T  value,
CPMode  mode 
)
inlineprotected

Associates the specified value with the specified key.

Parameters
keyA key to find or create; if key.Offset > 0, bytes before that offset are ignored.
valueValue to assign to the node, depending on the value of mode. On return, value is set to the previous value for the given key.
modeSpecifies whether to create an entry if the key is not present, and whether to change an existing entry. If mode is Find, Set() only retrieves an existing value; it does not change the trie.
Returns
Returns true if the specified key already existed and false if it did not.