src/hash_map.c

changeset 962
cd418898af5c
parent 890
54565fd74e74
equal deleted inserted replaced
961:bc8b7c5f55fb 962:cd418898af5c
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "cx/hash_map.h" 29 #include "cx/hash_map.h"
30 #include "cx/utils.h"
31 30
32 #include <string.h> 31 #include <string.h>
33 #include <assert.h> 32 #include <assert.h>
34 33
35 struct cx_hash_map_element_s { 34 struct cx_hash_map_element_s {
43 char data[]; 42 char data[];
44 }; 43 };
45 44
46 static void cx_hash_map_clear(struct cx_map_s *map) { 45 static void cx_hash_map_clear(struct cx_map_s *map) {
47 struct cx_hash_map_s *hash_map = (struct cx_hash_map_s *) map; 46 struct cx_hash_map_s *hash_map = (struct cx_hash_map_s *) map;
48 cx_for_n(i, hash_map->bucket_count) { 47 for (size_t i = 0; i < hash_map->bucket_count; i++) {
49 struct cx_hash_map_element_s *elem = hash_map->buckets[i]; 48 struct cx_hash_map_element_s *elem = hash_map->buckets[i];
50 if (elem != NULL) { 49 if (elem != NULL) {
51 do { 50 do {
52 struct cx_hash_map_element_s *next = elem->next; 51 struct cx_hash_map_element_s *next = elem->next;
53 // invoke the destructor 52 // invoke the destructor
439 if (new_buckets == NULL) { 438 if (new_buckets == NULL) {
440 return 1; 439 return 1;
441 } 440 }
442 441
443 // iterate through the elements and assign them to their new slots 442 // iterate through the elements and assign them to their new slots
444 cx_for_n(slot, hash_map->bucket_count) { 443 for (size_t slot = 0; slot < hash_map->bucket_count; slot++) {
445 struct cx_hash_map_element_s *elm = hash_map->buckets[slot]; 444 struct cx_hash_map_element_s *elm = hash_map->buckets[slot];
446 while (elm != NULL) { 445 while (elm != NULL) {
447 struct cx_hash_map_element_s *next = elm->next; 446 struct cx_hash_map_element_s *next = elm->next;
448 size_t new_slot = elm->key.hash % new_bucket_count; 447 size_t new_slot = elm->key.hash % new_bucket_count;
449 448

mercurial