From 260ad16e93223ad63f3cf57b96399191568b81a8 Mon Sep 17 00:00:00 2001 From: werkt Date: Wed, 5 Jan 2005 06:03:48 +0000 Subject: [PATCH] Fixes for ecore_hash_goto_first and ecore_hash_next SVN revision: 12767 --- legacy/ecore/src/lib/ecore/Ecore_Data.h | 1 - legacy/ecore/src/lib/ecore/ecore_hash.c | 29 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/legacy/ecore/src/lib/ecore/Ecore_Data.h b/legacy/ecore/src/lib/ecore/Ecore_Data.h index 29a466dfd2..d2fa69da15 100644 --- a/legacy/ecore/src/lib/ecore/Ecore_Data.h +++ b/legacy/ecore/src/lib/ecore/Ecore_Data.h @@ -277,7 +277,6 @@ extern "C" { int nodes; /* The number of nodes currently in the hash */ int index; /* The current index into the bucket table */ - Ecore_Hash_Node *current; /* the current node in the current bucket */ Ecore_Compare_Cb compare; /* The function used to compare node values */ Ecore_Hash_Cb hash_func; /* The function used to compare node values */ diff --git a/legacy/ecore/src/lib/ecore/ecore_hash.c b/legacy/ecore/src/lib/ecore/ecore_hash.c index 2aa2504e5d..971aacbfed 100644 --- a/legacy/ecore/src/lib/ecore/ecore_hash.c +++ b/legacy/ecore/src/lib/ecore/ecore_hash.c @@ -207,18 +207,24 @@ void ecore_hash_destroy(Ecore_Hash *hash) */ Ecore_Hash_Node *ecore_hash_goto_first(Ecore_Hash *hash) { + Ecore_Hash_Node *node = NULL; + CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE); hash->index = 0; ECORE_READ_LOCK(hash); - if( hash->buckets[hash->index] ) - ecore_list_goto_first( hash->buckets[hash->index] ); + while( hash->index < ecore_prime_table[hash->index] && + !hash->buckets[hash->index] ) + hash->index++; + + if( hash->index < ecore_prime_table[hash->index] ) + node = ecore_list_goto_first( hash->buckets[hash->index] ); ECORE_READ_UNLOCK(hash); - return hash->current; + return node; } /** @@ -235,16 +241,19 @@ Ecore_Hash_Node *ecore_hash_next(Ecore_Hash *hash) ECORE_READ_LOCK(hash); - if( hash->index < ecore_prime_table[hash->size] && - hash->buckets[hash->index] ) { + while( hash->index < ecore_prime_table[hash->size] && + !hash->buckets[hash->index] ) { + hash->index++; + if( hash->index < ecore_prime_table[hash->size] && + hash->buckets[hash->index] ) + ecore_list_goto_first( hash->buckets[hash->index] ); + } + + if( hash->index < ecore_prime_table[hash->size] ) { node = ecore_list_next( hash->buckets[hash->index] ); if( !node ) { hash->index++; - while( hash->index < ecore_prime_table[hash->size] && - !hash->buckets[hash->index] ) - hash->index++; - if( hash->index < ecore_prime_table[hash->size] ) - node = ecore_list_goto_first( hash->buckets[hash->index] ); + node = ecore_hash_next(hash); } }