示例#1
0
/*
 * Remove record r
 */
void strmap_erase(strmap_t *hmap, strmap_rec_t *r) {
  assert(strmap_find(hmap, r->key) == r);

  string_decref(r->key);
  r->key = DELETED_KEY;
  hmap->nelems --;
  hmap->ndeleted ++;
  if (hmap->ndeleted > hmap->cleanup_threshold) {
    strmap_cleanup(hmap);
  }
}
示例#2
0
/*
 * Delete: call decref on all keys
 */
void delete_strmap(strmap_t *hmap) {
  uint32_t i, n;
  char *key;

  n = hmap->size;
  for (i=0; i<n; i++) {
    key = hmap->data[i].key;
    if (valid_key(key)) {
      string_decref(key);
    }
  }

  safe_free(hmap->data);
  hmap->data = NULL;
}
示例#3
0
/*
 * Empty the table
 */
void reset_strmap(strmap_t *hmap) {
  uint32_t i, n;
  char *key;

  n = hmap->size;
  for (i=0; i<n; i++) {
    key = hmap->data[i].key;
    hmap->data[i].key = NULL;
    if (valid_key(key)) {
      string_decref(key);
    }
  }

  hmap->nelems = 0;
  hmap->ndeleted = 0;
}
/*
 * All names in sym_table are built with clone_string.
 * Finalizer: decrement the refcount for a string.
 */
static void finalize(stbl_rec_t *r) {
  string_decref(r->string);
}