// ---------------------------------------------------------------- void lhmsv_remove(lhmsv_t* pmap, char* key) { int index = lhmsv_find_index_for_key(pmap, key); lhmsve_t* pe = &pmap->entries[index]; if (pmap->states[index] == OCCUPIED) { pe->ideal_index = -1; pe->key = NULL; pe->pvvalue = NULL; pmap->states[index] = DELETED; if (pe == pmap->phead) { if (pe == pmap->ptail) { pmap->phead = NULL; pmap->ptail = NULL; } else { pmap->phead = pe->pnext; } } else { pe->pprev->pnext = pe->pnext; pe->pnext->pprev = pe->pprev; } pmap->num_freed++; pmap->num_occupied--; return; } else if (pmap->states[index] == EMPTY) { return; } else { fprintf(stderr, "lhmsv_find_index_for_key did not find end of chain.\n"); exit(1); } }
static void lhmsv_put_no_enlarge(lhmsv_t* pmap, char* key, void* pvvalue, char free_flags) { int ideal_index = 0; int index = lhmsv_find_index_for_key(pmap, key, &ideal_index); lhmsve_t* pe = &pmap->entries[index]; if (pmap->states[index] == OCCUPIED) { // Existing key found in chain; put value. pe->pvvalue = pvvalue; } else if (pmap->states[index] == EMPTY) { // End of chain. pe->ideal_index = ideal_index; pe->key = key; pe->pvvalue = pvvalue; pe->free_flags = free_flags; pmap->states[index] = OCCUPIED; if (pmap->phead == NULL) { pe->pprev = NULL; pe->pnext = NULL; pmap->phead = pe; pmap->ptail = pe; } else { pe->pprev = pmap->ptail; pe->pnext = NULL; pmap->ptail->pnext = pe; pmap->ptail = pe; } pmap->num_occupied++; } else { fprintf(stderr, "%s: lhmsv_find_index_for_key did not find end of chain.\n", MLR_GLOBALS.argv0); exit(1); } }
// ---------------------------------------------------------------- int lhmsv_has_key(lhmsv_t* pmap, char* key) { int index = lhmsv_find_index_for_key(pmap, key); if (pmap->states[index] == OCCUPIED) return TRUE; else if (pmap->states[index] == EMPTY) return FALSE; else { fprintf(stderr, "lhmsv_find_index_for_key did not find end of chain.\n"); exit(1); } }
// ---------------------------------------------------------------- void* lhmsv_get(lhmsv_t* pmap, char* key) { int index = lhmsv_find_index_for_key(pmap, key); lhmsve_t* pe = &pmap->entries[index]; if (pmap->states[index] == OCCUPIED) return pe->pvvalue; else if (pmap->states[index] == EMPTY) return NULL; else { fprintf(stderr, "lhmsv_find_index_for_key did not find end of chain.\n"); exit(1); } }
// ---------------------------------------------------------------- int lhmsv_has_key(lhmsv_t* pmap, char* key) { int ideal_index = 0; int index = lhmsv_find_index_for_key(pmap, key, &ideal_index); if (pmap->states[index] == OCCUPIED) return TRUE; else if (pmap->states[index] == EMPTY) return FALSE; else { fprintf(stderr, "%s: lhmsv_find_index_for_key did not find end of chain.\n", MLR_GLOBALS.argv0); exit(1); } }
static void lhmsv_put_no_enlarge(lhmsv_t* pmap, char* key, void* pvvalue) { int index = lhmsv_find_index_for_key(pmap, key); lhmsve_t* pe = &pmap->entries[index]; if (pmap->states[index] == OCCUPIED) { // Existing key found in chain; put value. if (streq(pe->key, key)) { pe->pvvalue = pvvalue; } } else if (pmap->states[index] == EMPTY) { // End of chain. pe->ideal_index = mlr_canonical_mod(mlr_string_hash_func(key), pmap->array_length); // xxx comment all malloced. pe->key = strdup(key); pe->pvvalue = pvvalue; pmap->states[index] = OCCUPIED; if (pmap->phead == NULL) { pe->pprev = NULL; pe->pnext = NULL; pmap->phead = pe; pmap->ptail = pe; } else { pe->pprev = pmap->ptail; pe->pnext = NULL; pmap->ptail->pnext = pe; pmap->ptail = pe; } pmap->num_occupied++; } else { fprintf(stderr, "lhmsv_find_index_for_key did not find end of chain.\n"); exit(1); } }