// a - b struct map *map_minus(struct map *a, const struct map *b) { if ((a == NULL) || (b == NULL)) return a; struct array *keys = map_keys(b); for (int i=0; i<keys->length; i++) { const void *key = array_get(keys, i); if (map_has(a, key)) { map_remove(a, key); } } array_del(keys); return a; }
// a + b; in case of intersection, a wins struct map *map_union(struct map *a, const struct map *b) { if (b == NULL) return a; if (a == NULL) return map_copy(b->context, b); struct array *keys = map_keys(b); for (int i=0; i<keys->length; i++) { const void *key = array_get(keys, i); if (!map_has(a, key)) { void *key2 = b->copyor(key, a->context); void *value = map_get(b, key); void *value2 = b->copyor(value, a->context); map_insert(a, key2, value2); } } array_del(keys); return a; }
int lrucache_has(LRUCACHE* lrucache, char* key) { return map_has(lrucache->map, key); }