Пример #1
0
static void gt_rdb_stmt_mysql_delete(GtRDBStmt *st)
{
  GtRDBStmtMySQL *stm;
  if (!st) return;
  stm = gt_rdb_stmt_mysql_cast(st);
  if (stm->stmt) {
    mysql_stmt_free_result(stm->stmt);
    mysql_stmt_close(stm->stmt);
  }
  gt_free(stm->params);
  gt_free(stm->results);
  gt_hashtable_delete(stm->buffers);
  gt_hashtable_delete(stm->returned_strings);
  gt_str_delete(stm->query);
}
Пример #2
0
void gt_disc_distri_delete(GtDiscDistri *d)
{
  if (!d) return;
  gt_hashtable_delete(d->hashdist);
  gt_free(d);
}
Пример #3
0
void gt_hashmap_delete(GtHashmap *hm)
{
  gt_hashtable_delete((GtHashtable*) hm);
}
Пример #4
0
static int
gt_hashmap_test(GtHashType hash_type)
{
  char *s1 = "foo", *s2 = "bar";
  GT_UNUSED unsigned long ul1 = 1UL, ul2 = 2UL;
  GT_UNUSED unsigned long long ull1 = 3ULL, ull2 = 4ULL, *sptr = NULL,
                               *tptr = NULL;
  GtHashmap *hm;
  GtHashtable *ht;
  int had_err = 0;
  do {
    /* empty hash */
    hm = gt_hashmap_new(hash_type, NULL, NULL);
    gt_hashmap_delete(hm);

    /* empty hash with reset */
    hm = gt_hashmap_new(hash_type, NULL, NULL);
    gt_hashmap_reset(hm);
    gt_hashmap_delete(hm);

    /* hashes containing one element */
    hm = gt_hashmap_new(hash_type, NULL, NULL);
    gt_hashmap_add(hm, s1, s2);
    my_ensure(had_err, gt_hashmap_get(hm, s1) == s2);
    my_ensure(had_err, !gt_hashmap_get(hm, s2));
    gt_hashmap_delete(hm);

    /* hashes containing two elements */
    hm = gt_hashmap_new(hash_type, NULL, NULL);
    gt_hashmap_add(hm, s1, s2);
    gt_hashmap_add(hm, s2, s1);
    my_ensure(had_err, gt_hashmap_get(hm, s1) == s2);
    my_ensure(had_err, gt_hashmap_get(hm, s2) == s1);

    /* remove element A and ensure it's no longer present */
    gt_hashmap_remove(hm, s1);
    my_ensure(had_err, !gt_hashmap_get(hm, s1));
    my_ensure(had_err, gt_hashmap_get(hm, s2) == s1);
    gt_hashmap_delete(hm);

    /* hashes containing two elements (store key and value in
     * hashmap) where simple free is the correct way to get rid of them
     */
    if (hash_type == GT_HASH_STRING)
    {
      hm = gt_hashmap_new(hash_type, gt_free_func, gt_free_func);

      gt_hashmap_add(hm, gt_cstr_dup(s1), gt_cstr_dup(s2));
      gt_hashmap_add(hm, gt_cstr_dup(s2), gt_cstr_dup(s1));
      my_ensure(had_err, !strcmp(gt_hashmap_get(hm, s1), s2));
      my_ensure(had_err, !strcmp(gt_hashmap_get(hm, s2), s1));
      gt_hashmap_remove(hm, s1); /* remove first element */
      my_ensure(had_err, !gt_hashmap_get(hm, s1));
      my_ensure(had_err, !strcmp(gt_hashmap_get(hm, s2),  s1));
      gt_hashmap_delete(hm);
    }

    /* test direct modification of hash contents */
    ht = testul_testull_gt_hashmap_new();
    my_ensure(had_err, !sptr);
    sptr = testul_testull_gt_hashmap_add_and_return_storage(ht, ul1, ull1);
    my_ensure(had_err, *sptr == ull1);
    sptr = testul_testull_gt_hashmap_add_and_return_storage(ht, ul1, ull2);
    my_ensure(had_err, *sptr == ull2);
    (*sptr)++;
    tptr = testul_testull_gt_hashmap_get(ht, ul1);
    my_ensure(had_err, tptr == sptr);
    my_ensure(had_err, *tptr == ull2+1);
    gt_hashtable_delete(ht);

  } while (0);
  return had_err;
}