//sets the value for key key to value in d void dict_setitem(Dict *d, LispObject *key, LispObject *value) { int i; if(dict_find_index(d, key, &i)) d->values[i] = value; else if (i >= 0) { d->keys[i] = key; d->values[i] = value; d->size++; if(d->size > d->array_size / 2) dict_resize(d); } else error("dict full somehow\n"); }
void dict_add(dict_t dict, const char *key, int value) { int idx = dict_find_index(dict, key); if (idx != -1) { dict->entry[idx].value = value; return; } if (dict->len == dict->cap) { dict->cap *= 2; dict->entry = realloc(dict->entry, dict->cap * sizeof(dict_entry_s)); } dict->entry[dict->len].key = strdup(key); dict->entry[dict->len].value = value; dict->len++; }
int dict_find(dict_t dict, const char *key, int def) { int idx = dict_find_index(dict, key); return idx == -1 ? def : dict->entry[idx].value; }
//returns the value for key in d LispObject *dict_getitem(Dict *d, LispObject *key) { int i; if(!dict_find_index(d, key, &i)) return NULL; return d->values[i]; }