libctf: fix spurious error when rolling back to the first snapshot
[deliverable/binutils-gdb.git] / libctf / ctf-hash.c
index 03a398e06c95e4d8a5ee75f9d105dba597ee6a47..12bd6ef9b921ac077d05f25e4917c042fe2bae13 100644 (file)
@@ -193,6 +193,55 @@ ctf_dynhash_lookup (ctf_dynhash_t *hp, const void *key)
   return NULL;
 }
 
+typedef struct ctf_traverse_cb_arg
+{
+  ctf_hash_iter_f fun;
+  void *arg;
+} ctf_traverse_cb_arg_t;
+
+static int
+ctf_hashtab_traverse (void **slot, void *arg_)
+{
+  ctf_helem_t *helem = *((ctf_helem_t **) slot);
+  ctf_traverse_cb_arg_t *arg = (ctf_traverse_cb_arg_t *) arg_;
+
+  arg->fun (helem->key, helem->value, arg->arg);
+  return 1;
+}
+
+void
+ctf_dynhash_iter (ctf_dynhash_t *hp, ctf_hash_iter_f fun, void *arg_)
+{
+  ctf_traverse_cb_arg_t arg = { fun, arg_ };
+  htab_traverse (hp->htab, ctf_hashtab_traverse, &arg);
+}
+
+typedef struct ctf_traverse_remove_cb_arg
+{
+  struct htab *htab;
+  ctf_hash_iter_remove_f fun;
+  void *arg;
+} ctf_traverse_remove_cb_arg_t;
+
+static int
+ctf_hashtab_traverse_remove (void **slot, void *arg_)
+{
+  ctf_helem_t *helem = *((ctf_helem_t **) slot);
+  ctf_traverse_remove_cb_arg_t *arg = (ctf_traverse_remove_cb_arg_t *) arg_;
+
+  if (arg->fun (helem->key, helem->value, arg->arg))
+    htab_clear_slot (arg->htab, slot);
+  return 1;
+}
+
+void
+ctf_dynhash_iter_remove (ctf_dynhash_t *hp, ctf_hash_iter_remove_f fun,
+                         void *arg_)
+{
+  ctf_traverse_remove_cb_arg_t arg = { hp->htab, fun, arg_ };
+  htab_traverse (hp->htab, ctf_hashtab_traverse_remove, &arg);
+}
+
 void
 ctf_dynhash_destroy (ctf_dynhash_t *hp)
 {
This page took 0.023056 seconds and 4 git commands to generate.