1
0
Fork 0

(svn r20888) -Codechange: Make Hash_FindNode a method.

release/1.1
alberth 2010-10-02 19:48:45 +00:00
parent 6802527e02
commit 0c08955f4d
2 changed files with 10 additions and 9 deletions

View File

@ -393,29 +393,29 @@ void Hash::Clear(bool free_values)
* bucket, or NULL if it is empty. prev can also be NULL, in which case it is * bucket, or NULL if it is empty. prev can also be NULL, in which case it is
* not used for output. * not used for output.
*/ */
static HashNode *Hash_FindNode(const Hash *h, uint key1, uint key2, HashNode** prev_out) HashNode *Hash::FindNode(uint key1, uint key2, HashNode** prev_out) const
{ {
uint hash = h->hash(key1, key2); uint hash = this->hash(key1, key2);
HashNode *result = NULL; HashNode *result = NULL;
#ifdef HASH_DEBUG #ifdef HASH_DEBUG
debug("Looking for %u, %u", key1, key2); debug("Looking for %u, %u", key1, key2);
#endif #endif
/* Check if the bucket is empty */ /* Check if the bucket is empty */
if (!h->buckets_in_use[hash]) { if (!this->buckets_in_use[hash]) {
if (prev_out != NULL) *prev_out = NULL; if (prev_out != NULL) *prev_out = NULL;
result = NULL; result = NULL;
/* Check the first node specially */ /* Check the first node specially */
} else if (h->buckets[hash].key1 == key1 && h->buckets[hash].key2 == key2) { } else if (this->buckets[hash].key1 == key1 && this->buckets[hash].key2 == key2) {
/* Save the value */ /* Save the value */
result = h->buckets + hash; result = this->buckets + hash;
if (prev_out != NULL) *prev_out = NULL; if (prev_out != NULL) *prev_out = NULL;
#ifdef HASH_DEBUG #ifdef HASH_DEBUG
debug("Found in first node: %p", result); debug("Found in first node: %p", result);
#endif #endif
/* Check all other nodes */ /* Check all other nodes */
} else { } else {
HashNode *prev = h->buckets + hash; HashNode *prev = this->buckets + hash;
HashNode *node; HashNode *node;
for (node = prev->next; node != NULL; node = node->next) { for (node = prev->next; node != NULL; node = node->next) {
@ -446,7 +446,7 @@ void *Hash::DeleteValue(uint key1, uint key2)
{ {
void *result; void *result;
HashNode *prev; // Used as output var for below function call HashNode *prev; // Used as output var for below function call
HashNode *node = Hash_FindNode(this, key1, key2, &prev); HashNode *node = this->FindNode(key1, key2, &prev);
if (node == NULL) { if (node == NULL) {
/* not found */ /* not found */
@ -492,7 +492,7 @@ void *Hash::DeleteValue(uint key1, uint key2)
void *Hash::Set(uint key1, uint key2, void *value) void *Hash::Set(uint key1, uint key2, void *value)
{ {
HashNode *prev; HashNode *prev;
HashNode *node = Hash_FindNode(this, key1, key2, &prev); HashNode *node = this->FindNode(key1, key2, &prev);
if (node != NULL) { if (node != NULL) {
/* Found it */ /* Found it */
@ -526,7 +526,7 @@ void *Hash::Set(uint key1, uint key2, void *value)
*/ */
void *Hash::Get(uint key1, uint key2) const void *Hash::Get(uint key1, uint key2) const
{ {
HashNode *node = Hash_FindNode(this, key1, key2, NULL); HashNode *node = this->FindNode(key1, key2, NULL);
#ifdef HASH_DEBUG #ifdef HASH_DEBUG
debug("Found node: %p", node); debug("Found node: %p", node);

View File

@ -108,6 +108,7 @@ protected:
#ifdef HASH_STATS #ifdef HASH_STATS
void PrintStatistics() const; void PrintStatistics() const;
#endif #endif
HashNode *FindNode(uint key1, uint key2, HashNode** prev_out) const;
}; };
#endif /* QUEUE_H */ #endif /* QUEUE_H */