Changeset 363


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

Change zAVL implementation to allow integer keys.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/sh_inotify.h

    r261 r363  
    66typedef struct
    77{
     8  /*
     9  void * list_of_watches;
     10  */
     11
    812  int    watch[SH_INOTIFY_MAX];
    913  int    flag[SH_INOTIFY_MAX];
    1014  char * file[SH_INOTIFY_MAX];
    11   int    count;
    1215
     16  int     count;
     17  int  max_count;
    1318} sh_watches;
     19
     20#define SH_INOTIFY_INITIALIZER { { 0 }, { 0 }, { NULL}, 0, 0 }
    1421
    1522int sh_inotify_wait_for_change(char * filename, sh_watches * watches,
  • trunk/include/zAVLTree.h

    r1 r363  
    3333
    3434/* typedef the keytype */
    35 typedef const char * zAVLKey;
     35typedef const void * zAVLKey;
    3636
    3737/* Comparison function for strings is strcmp(). */
    38 #define zAVLKey_cmp(tree, a, b) (strcmp((a), (b)))
     38/* #define zAVLKey_cmp(tree, a, b) (strcmp((a), (b))) */
     39
     40#define zAVL_KEY_STRING 0
     41#define zAVL_KEY_INT    1
    3942
    4043
     
    5356  long count;
    5457  zAVLKey (*getkey)(const void *item);
     58  int keytype;
    5559} zAVLTree;
    5660
     
    6266
    6367
    64 extern zAVLTree *zAVLAllocTree (zAVLKey (*getkey)(void const *item));
     68extern zAVLTree *zAVLAllocTree (zAVLKey (*getkey)(void const *item), int keytype);
    6569extern void zAVLFreeTree (zAVLTree *avltree, void (freeitem)(void *item));
    6670extern int zAVLInsert (zAVLTree *avltree, void *item);
  • 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.