@@ -112,6 +112,8 @@ extern void HashMapInsert(HashMap *map, JSONValue *entry)
112112 bool collision = hashMapEntriesInsert (map -> entries , index , entry );
113113 if (collision )
114114 {
115+ // printf("COLLISION!\n");
116+ // fflush(stdout);
115117 map -> collision_count ++ ;
116118 }
117119 else
@@ -137,30 +139,49 @@ static bool hashMapEntriesInsert(JSONValue **entries, u_int32_t index, JSONValue
137139 entries [index ] = entry ;
138140 return false;
139141 }
142+ // printf("%s -> %s\n", collision->key, entry->key);
140143 // If duplicate key, update (in future could maybe make this a feature flag for the init function)
141- if (collision -> key != NULL && strcmp ( collision -> key , entry -> key ) == 0 )
144+ if (collision -> key != NULL )
142145 {
143- entry -> next = collision -> next ;
144- collision -> next = NULL ;
145- freeHashMapEntrySingle (collision , true);
146- entries [index ] = entry ;
147- return true;
146+ size_t collision_key_len = strlen (collision -> key );
147+ size_t entry_key_len = strlen (entry -> key );
148+ if (collision_key_len == entry_key_len )
149+ {
150+ if (strncmp (collision -> key , entry -> key , entry_key_len ) == 0 )
151+ {
152+ entry -> next = collision -> next ;
153+ collision -> next = NULL ;
154+ freeHashMapEntrySingle (collision , true);
155+ entries [index ] = entry ;
156+ return true;
157+ }
158+ }
148159 }
149160 JSONValue * iterator_prev = collision ;
150161 JSONValue * iterator = collision -> next ;
151162 while (iterator != NULL )
152163 {
153- if (iterator -> key != NULL && entry -> key != NULL && strcmp ( iterator -> key , entry -> key ) == 0 )
164+ if (iterator -> key != NULL && entry -> key != NULL )
154165 {
155- iterator_prev -> next = entry ;
156- entry -> next = iterator -> next ;
157- iterator -> next = NULL ;
158- freeHashMapEntrySingle (iterator , true); // FIXME
159- return true;
166+ size_t collision_key_len = strlen (collision -> key );
167+ size_t entry_key_len = strlen (entry -> key );
168+ if (collision_key_len == entry_key_len )
169+ {
170+ if (strncmp (iterator -> key , entry -> key , collision_key_len ) == 0 )
171+ {
172+ iterator_prev -> next = entry ;
173+ entry -> next = iterator -> next ;
174+ iterator -> next = NULL ;
175+ freeHashMapEntrySingle (iterator , true);
176+ return true;
177+ }
178+ }
160179 }
180+
161181 iterator_prev = iterator ;
162182 iterator = iterator -> next ;
163183 }
184+ entry -> next = NULL ;
164185 iterator_prev -> next = entry ;
165186 return true;
166187}
@@ -351,7 +372,6 @@ static void printHashMapEntry(JSONValue *entry)
351372 printf ("\"%s\": " , iterator -> key );
352373 PrintJSONValue (iterator );
353374 }
354-
355375 iterator = iterator -> next ;
356376 if (iterator != NULL )
357377 {
@@ -363,6 +383,8 @@ static void printHashMapEntry(JSONValue *entry)
363383// JOSH
364384static void hashMapResize (HashMap * map )
365385{
386+ // printf("hashMapResize\n");
387+ // fflush(stdout);
366388 if (map == NULL )
367389 {
368390 return ;
0 commit comments