Changeset 363 for trunk/src


Ignore:
Timestamp:
Oct 21, 2011, 1:08:28 AM (13 years ago)
Author:
katerina
Message:

Change zAVL implementation to allow integer keys.

Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cutest_zAVLTree.c

    r17 r363  
    4444  CuAssertTrue(tc, NULL == ptr);
    4545
    46   ztest_tree = zAVLAllocTree (ztest_key);
     46  ztest_tree = zAVLAllocTree (ztest_key, zAVL_KEY_STRING);
    4747  CuAssertPtrNotNull(tc, ztest_tree);
    4848
  • trunk/src/sh_files.c

    r362 r363  
    897897  if (zfileList == NULL)
    898898    {
    899       zfileList = zAVLAllocTree (zdirstack_key);
     899      zfileList = zAVLAllocTree (zdirstack_key, zAVL_KEY_STRING);
    900900      if (zfileList == NULL)
    901901        {
     
    975975          if (zglobList == NULL)
    976976            {
    977               zglobList = zAVLAllocTree (zdirstack_key);
     977              zglobList = zAVLAllocTree (zdirstack_key, zAVL_KEY_STRING);
    978978              if (zglobList == NULL)
    979979                {
     
    14561456  if (tree == NULL)
    14571457    {
    1458       tree = zAVLAllocTree (zdirstack_key);
     1458      tree = zAVLAllocTree (zdirstack_key, zAVL_KEY_STRING);
    14591459      if (tree == NULL)
    14601460        {
  • trunk/src/sh_forward.c

    r342 r363  
    20882088  if (all_clients == NULL)
    20892089    {
    2090       all_clients = zAVLAllocTree (sh_avl_key);
     2090      all_clients = zAVLAllocTree (sh_avl_key, zAVL_KEY_STRING);
    20912091      if (all_clients == NULL)
    20922092        {
  • trunk/src/sh_log_evalrule.c

    r357 r363  
    11221122    {
    11231123      DEBUG("debug: allocate new counterlist AVL tree\n");
    1124       rule->counterlist = zAVLAllocTree(sh_eval_getkey);
     1124      rule->counterlist = zAVLAllocTree(sh_eval_getkey, zAVL_KEY_STRING);
    11251125    }
    11261126
  • trunk/src/sh_log_mark.c

    r272 r363  
    7777  if (!(marklist))
    7878    {
    79       marklist = zAVLAllocTree(sh_log_mark_getkey);
     79      marklist = zAVLAllocTree(sh_log_mark_getkey, zAVL_KEY_STRING);
    8080    }
    8181
  • trunk/src/sh_nmail.c

    r304 r363  
    957957    }
    958958
    959   mailkeys = zAVLAllocTree (sh_nmail_getkey);
     959  mailkeys = zAVLAllocTree (sh_nmail_getkey, zAVL_KEY_STRING);
    960960  goto start;
    961961}
  • trunk/src/sh_utmp.c

    r332 r363  
    558558
    559559#if defined(HAVE_PTHREAD)
    560 static sh_watches inotify_watch;
     560static sh_watches inotify_watch = SH_INOTIFY_INITIALIZER;
    561561#endif
    562562
  • trunk/src/zAVLTree.c

    r16 r363  
    5353#define ZAVL_NO 0
    5454
     55/* The comparison function. Was a macro, but this allows for more
     56 * flexibility (non-string keys). The key is a (void *) now, and
     57 * the type is stored in the zAVLTree struct. Oct 21, 2011, rw
     58 */
     59static int zAVLKey_cmp(const zAVLTree * tree, zAVLKey a, zAVLKey b)
     60{
     61  if (tree->keytype == zAVL_KEY_STRING)
     62    {
     63      return (strcmp((char*)a, (char *)b));
     64    }
     65  else /* zAVL_KEY_INT */
     66    {
     67      int x = *((int *)a);
     68      int y = *((int *)b);
     69
     70      if      (x > y) return  1;
     71      else if (x < y) return -1;
     72      else return 0;
     73    }
     74}
    5575
    5676/*
     
    6282 * was a malloc failure, then NULL is returned.
    6383 */
    64 zAVLTree *zAVLAllocTree (zAVLKey (*getkey)(void const *item))
     84zAVLTree *zAVLAllocTree (zAVLKey (*getkey)(void const *item), int keytype)
    6585{
    6686  zAVLTree *rc;
     
    7393  rc->count = 0;
    7494  rc->getkey = getkey;
     95  rc->keytype = keytype;
    7596  return rc;
    7697}
Note: See TracChangeset for help on using the changeset viewer.