public:
DSHashTable(unsigned int newBuckets=100,unsigned int newPrimeA=89258459,unsigned int newPrimeB=252584539);
Create a HashTable.
Name Description newBuckets Specify the number of buckets to be used in the HashTable. The more buckets, the more memory is required; but the faster data access will be on large datasets. You may wish to increase the default for areas involving large quantities of data. newPrimeA Specify a large prime number to be used in hashing. You only need to do this if it's important to you to have a different hashing algorithm between two HashTables. newPrimeB Specify a large prime number to be used in hashing. You only need to do this if it's important to you to have a different hashing algorithm between two HashTables.
public:
void close();
Purges all data from the HashTable. Leaves the HashTable intact for subsequent use if desired.
public:
void delItem(unsigned int Key);
Removes one or more entries from the HashTable that have the specified numeric key.
Name Description Key A numeric key corresponding to the item(s) to be removed from the HashTable.
public:
void delItem(const char* Key);
Removes one or more entries from the HashTable that have the specified string key.
Name Description Key A string key corresponding to the item(s) to be removed from the HashTable.
public:
void forEach(void (*callback)(char *, char *, void *), void * extra);
Iterates through the HashTable calling a function for each entry found. This can be useful for doing bulk operations on data in a HashTable; but if you find yourself calling this frequently, consider using a different data structure.
Name Description callback A function to be called for each entry found in the HashTable. The function will be given a pointer to the key, a pointer to the value, and extra, discussed below. extra A pointer to any additional data to be passed to the function for every item encountered. Can be NULL.
public:
unsigned int getBuckets();
Returns the number of buckets in the HashTable.
Result: The number of buckets in this HashTable.public:
DSListElement* getElement(unsigned int Key);
Returns an element matching a specified Key, if such an element exists. Note that this returns a pointer to the raw ListElement object, and this can be used to modify details relating to this particular item. For this reason, use with caution.
Result: The ListElement requested, or NULL, if the element could not be found.
Name Description Key A numeric key matching the element requested.
public:
DSListElement* getElement(const char* Key);
Returns an element matching a specified Key, if such an element exists. Note that this returns a pointer to the raw ListElement object, and this can be used to modify details relating to this particular item. For this reason, use with caution.
Result: The ListElement requested, or NULL, if the element could not be found.
Name Description Key A string key matching the element requested.
public:
DSList* getList();
Returns a list of data corresponding to the data in the entire HashTable, in no particular order.
Result: A list of items in the HashTable. This list is dynamically created, remember to delete it when you're finished.)public:
DSList* getList(unsigned int bucket);
Returns a list of data at a particular bucket. Please avoid using this function, it exposes the internal workings of the HashTable. If you need bulk access to data, consider using forEach.
Result: A list of items at this bucket (or NULL, if there are no entries in this bucket.)
Name Description bucket Specifies the bucket number to be retrieved.
public:
unsigned int getNumericValue(const char* Key);
Returns the data matching a specified Key, if such an element exists.
Result: The element's data, or NULL, if the element could not be found.
Name Description Key A string key matching the element requested.
public:
unsigned int getNumericValue(unsigned int Key);
Returns the data matching a specified Key, if such an element exists.
Result: The element's data, or NULL, if the element could not be found.
Name Description Key A numeric key matching the element requested.
public:
void* getPtrValue(const char* Key);
Returns the data matching a specified Key, if such an element exists. Note that this returns a pointer to the data, and this can be used to modify details relating to this particular item. For this reason, use with caution.
Result: A pointer to the element's data, or NULL, if the element could not be found.
Name Description Key A string key matching the element requested.
public:
void* getPtrValue(unsigned int Key);
Returns the data matching a specified Key, if such an element exists. Note that this returns a pointer to the data, and this can be used to modify details relating to this particular item. For this reason, use with caution.
Result: A pointer to the element's data, or NULL, if the element could not be found.
Name Description Key A numeric key matching the element requested.
public:
unsigned int hash(unsigned char * Key);
Hashes the key to generate the bucket that the specified Key would be located in, if it were to be entered.
Result: The bucket which the key corresponds to.
Name Description Key A string key.
public:
unsigned int hash(unsigned int value);
Hashes the key to generate the bucket that the specified Key would be located in, if it were to be entered.
Result: The bucket which the key corresponds to.
Name Description Key A numeric key.
public:
void init(unsigned int newBuckets=100,unsigned int newPrimeA=89258459,unsigned int newPrimeB=252584539);
Create a HashTable. This function is only provided to allow initiation of a HashTable that has been created by malloc. It should not be used in any other way. The use of malloc is strongly discouraged and new should be used instead. This function may be removed at some point in the future.
Name Description newBuckets Specify the number of buckets to be used in the HashTable. The more buckets, the more memory is required; but the faster data access will be on large datasets. You may wish to increase the default for areas involving large quantities of data. newPrimeA Specify a large prime number to be used in hashing. You only need to do this if it's important to you to have a different hashing algorithm between two HashTables. newPrimeB Specify a large prime number to be used in hashing. You only need to do this if it's important to you to have a different hashing algorithm between two HashTables.
public:
void insert(char * Key, void * value, int cleanup=0);
Inserts the specified data into the HashTable.
Name Description Key A string key. Note that this pointer will be inserted into the HashTable. The HashTable will not copy the data associated with it, so unless the data is permanent, you need to allocate your own memory and set the value of cleanup accordingly. value A pointer value. Note that this pointer will be inserted into the HashTable. The HashTable will not copy the data associated with it, so unless the data is permanent, you need to allocate your own memory and set the value of cleanup accordingly. cleanup A bitwise combination of flags telling the HashTable what memory it should deallocate if the item is removed. The default is to perform no cleanup, and to leave it to the application. The permissable flags are documented in the ListElement class.
public:
void insert(unsigned int Key, void * value, int cleanup=0);
Inserts the specified data into the HashTable.
Name Description Key A numeric key. value A pointer value. Note that this pointer will be inserted into the HashTable. The HashTable will not copy the data associated with it, so unless the data is permanent, you need to allocate your own memory and set the value of cleanup accordingly. cleanup A bitwise combination of flags telling the HashTable what memory it should deallocate if the item is removed. The default is to perform no cleanup, and to leave it to the application. The permissable flags are documented in the ListElement class.
public:
void insert(char * Key, unsigned int value, int cleanup=0);
Inserts the specified data into the HashTable.
Name Description Key A string key. Note that this pointer will be inserted into the HashTable. The HashTable will not copy the data associated with it, so unless the data is permanent, you need to allocate your own memory and set the value of cleanup accordingly. value A numeric value. cleanup A bitwise combination of flags telling the HashTable what memory it should deallocate if the item is removed. The default is to perform no cleanup, and to leave it to the application. The permissable flags are documented in the ListElement class.
public:
void insert(unsigned int Key, unsigned int value, int cleanup=0);
Inserts the specified data into the HashTable.
Name Description Key A numeric key. value A numeric value. cleanup A bitwise combination of flags telling the HashTable what memory it should deallocate if the item is removed. This value is not relevant for this form of insert, and should be set to 0.
public:
unsigned int occurenceCount(const char * key);
Counts the number of times the specified Key occurs in the HashTable.
Result: The number of times the specified Key occurs in the HashTable.
Name Description Key A string Key.
public:
void print();
Dumps the contents of the HashTable to stdout for debugging. Should be removed soon.
public:
BOOL setValue(const char* Key, void * data);
Attempts to modify the data of an item matching the specified key, if one exists. This will not modify the cleanup flags of the element.
Result: TRUE if the value was successfully updated; FALSE if the operation could not be completed.
Name Description Key A string key matching the element requested. data A pointer to the data to be used. Note that this pointer is used directly and will be cleaned up in accordance with the cleanup value of the element.
public:
BOOL setValue(const char* Key, unsigned int data);
Attempts to modify the data of an item matching the specified key, if one exists. This will not modify the cleanup flags of the element.
Result: TRUE if the value was successfully updated; FALSE if the operation could not be completed.
Name Description Key A string key matching the element requested. data A piece of numeric data to be used.
public:
BOOL setValue(unsigned int Key, void * data);
Attempts to modify the data of an item matching the specified key, if one exists. This will not modify the cleanup flags of the element.
Result: TRUE if the value was successfully updated; FALSE if the operation could not be completed.
Name Description Key A numeric key matching the element requested. data A pointer to the data to be used. Note that this pointer is used directly and will be cleaned up in accordance with the cleanup value of the element.
public:
BOOL setValue(unsigned int Key, unsigned int data);
Attempts to modify the data of an item matching the specified key, if one exists. This will not modify the cleanup flags of the element.
Result: TRUE if the value was successfully updated; FALSE if the operation could not be completed.
Name Description Key A numeric key matching the element requested. data A piece of numeric data to be used.
public:
~DSHashTable();
Destroy a HashTable.
Generated with HeaderDoc - © 2000 Apple Computer, Inc. (Last Updated 9/29/2003)