Appends `item` to the array table[key] (its count in counts[key]). */
| 245 | |
| 246 | /* Appends `item` to the array table[key] (its count in counts[key]). */ |
| 247 | static void ej_push(CBMArena *a, CBMHashTable *table, CBMHashTable *counts, const char *key, |
| 248 | const void *item, size_t size) { |
| 249 | intptr_t n = (intptr_t)cbm_ht_get(counts, key); |
| 250 | const char *old = cbm_ht_get(table, key); |
| 251 | char *v = cbm_arena_alloc(a, (size_t)(n + SKIP_ONE) * size); |
| 252 | const char *k = cbm_arena_strdup(a, key); |
| 253 | if (!v || !k) { |
| 254 | return; |
| 255 | } |
| 256 | if (n) { |
| 257 | memcpy(v, old, (size_t)n * size); |
| 258 | } |
| 259 | memcpy(v + (size_t)n * size, item, size); |
| 260 | cbm_ht_set(table, k, v); |
| 261 | cbm_ht_set(counts, k, (void *)(n + SKIP_ONE)); |
| 262 | } |
| 263 | |
| 264 | static const char *ej_id(ej_t *j, int64_t id) { |
| 265 | return cbm_arena_sprintf(&j->a, "%lld", (long long)id); |
no test coverage detected