Skip to content

Commit 9653458

Browse files
fix growat/shrinkat of hashmap
1 parent b8fff1f commit 9653458

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/hashmap.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ struct hashmap *hashmap_new_with_allocator(
118118
return NULL;
119119
}
120120
memset(map->buckets, 0, map->bucketsz*map->nbuckets);
121-
map->growat = map->nbuckets * 2;
122-
map->shrinkat = map->nbuckets * 1;
123-
map->malloc = _malloc;
121+
map->growat = map->nbuckets*0.75;
122+
map->shrinkat = map->nbuckets*0.10;
123+
map->malloc = _malloc;
124124
map->realloc = _realloc;
125125
map->free = _free;
126126
return map;
@@ -192,16 +192,16 @@ void hashmap_clear(struct hashmap *map, bool update_cap) {
192192
}
193193
memset(map->buckets, 0, map->bucketsz*map->nbuckets);
194194
map->mask = map->nbuckets-1;
195-
map->growat = map->nbuckets * 2;
196-
map->shrinkat = map->nbuckets * 1;
195+
map->growat = map->nbuckets*0.75;
196+
map->shrinkat = map->nbuckets*0.10;
197197
}
198198

199199

200200
static bool resize(struct hashmap *map, size_t new_cap) {
201201
struct hashmap *map2 = hashmap_new_with_allocator(map->malloc, map->realloc, map->free,
202-
map->elsize, new_cap, map->seed0,
203-
map->seed1, map->hash, map->compare,
204-
map->elfree, map->udata);
202+
map->elsize, new_cap, map->seed0,
203+
map->seed1, map->hash, map->compare,
204+
map->elfree, map->udata);
205205
if (!map2) {
206206
return false;
207207
}
@@ -277,7 +277,6 @@ void *hashmap_set(struct hashmap *map, const void *item) {
277277
memcpy(map->spare, bucket, map->bucketsz);
278278
memcpy(bucket, entry, map->bucketsz);
279279
memcpy(entry, map->spare, map->bucketsz);
280-
return NULL;
281280
}
282281
i = (i + 1) & map->mask;
283282
entry->dib += 1;

src/ubasic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ struct ubasic_ctx* ubasic_init(const char *program, console* cons, uint32_t pid,
203203
*error = "Out of memory";
204204
return NULL;
205205
}
206-
ctx->lines = hashmap_new(sizeof(ub_line_ref), 1000, time(NULL) , 4583058, line_hash, line_compare, NULL, NULL);
206+
ctx->lines = hashmap_new(sizeof(ub_line_ref), 0, 5923530135432, 458397058, line_hash, line_compare, NULL, NULL);
207207

208208
// Clean extra whitespace from the program
209209
ctx->program_ptr = clean_basic(program, ctx->program_ptr);

0 commit comments

Comments
 (0)