SourceMod SDK  1.7
KTrie< K > Class Template Reference

Public Member Functions

void clear ()
 Clears all set objects in the trie.
 
bool remove (const char *key)
 Removes a key from the trie. More...
 
K * retrieve (const char *key)
 Retrieves a pointer to the object stored at a given key. More...
 
bool retrieve (const char *key, K *result)
 Wrapper around retrieve(key) for a cleaner API. More...
 
bool replace (const char *key, const K &obj)
 Inserts or updates the object stored at a key. More...
 
bool insert (const char *key, const K &obj)
 Inserts an object at a key. More...
 
void bad_iterator (char *buffer, size_t maxlength, void *data, void(*func)(KTrie *, const char *, K &obj, void *data))
 Iterates over the trie returning all known values. More...
 
void run_destructor (void(*dtor)(K *ptr))
 
size_t mem_usage ()
 
size_t size ()
 

Member Function Documentation

template<typename K >
void KTrie< K >::bad_iterator ( char *  buffer,
size_t  maxlength,
void *  data,
void(*)(KTrie< K > *, const char *, K &obj, void *data)  func 
)
inline

Iterates over the trie returning all known values.

Note: This function is for debugging. Do not use it as a production iterator since it's inefficient. Iteration is guaranteed to be sorted ascendingly.

The callback function takes: (KTrie) - Pointer to this Trie (const char *) - String containing key name. (K &) - By-reference object at the key. (data) - User pointer.

Parameters
bufferBuffer to use as a key name cache.
maxlengthMaximum length of the key name buffer.
dataUser pointer for passing to the iterator.
funcIterator callback function.
template<typename K >
bool KTrie< K >::insert ( const char *  key,
const K &  obj 
)
inline

Inserts an object at a key.

Parameters
keyKey to insert at.
objObject to store at the key.
Returns
True on success, false if the key is already set or insertion otherwise failed.

Empty strings are a special case, since there are no productions. We could probably rework it to use BASE[0] but this hack is easier.

template<typename K >
bool KTrie< K >::remove ( const char *  key)
inline

Removes a key from the trie.

Parameters
keyKey to remove.
Returns
True on success, false if key was never set.
template<typename K >
bool KTrie< K >::replace ( const char *  key,
const K &  obj 
)
inline

Inserts or updates the object stored at a key.

Parameters
keyKey to update or insert.
objObject to store at the key.
Returns
True on success, false on failure.
template<typename K >
K* KTrie< K >::retrieve ( const char *  key)
inline

Retrieves a pointer to the object stored at a given key.

Parameters
keyKey to retrieve.
Returns
Pointer to object, or NULL if key was not found or not set.
template<typename K >
bool KTrie< K >::retrieve ( const char *  key,
K *  result 
)
inline

Wrapper around retrieve(key) for a cleaner API.

Parameters
keyKey to retrieve.
resultPointer to store the result, must be non-NULL.
Returns
True if found, false otherwise.

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