Changeset 452 for trunk/src/zAVLTree.c
- Timestamp:
- Jun 26, 2014, 8:01:54 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/zAVLTree.c
r383 r452 33 33 #include "zAVLTree.h" 34 34 35 /* Interface for handling "string only" items rw 2014-06-26 36 */ 37 static zAVLKey zstring_key (void const * arg) 38 { 39 return (zAVLKey) arg; 40 } 41 static void zfree_string (void * inptr) 42 { 43 char * str = (char *) inptr; 44 str[0] = '\0'; 45 free (str); 46 return; 47 } 48 void zAVL_string_reset (zAVLTree * tree) 49 { 50 if (tree) 51 zAVLFreeTree (tree, zfree_string); 52 return; 53 } 54 int zAVL_string_set (zAVLTree ** tree, const char * key) 55 { 56 if (tree && key) 57 { 58 zAVLTree * itree = (*tree); 59 if (!itree) 60 { 61 itree = zAVLAllocTree (zstring_key, zAVL_KEY_STRING); 62 if (!itree) 63 { 64 return -1; 65 } 66 } 67 *tree = itree; 68 return zAVLInsert (itree, strdup(key)); 69 } 70 return -1; 71 } 72 char * zAVL_string_get (zAVLTree * tree, char * key) 73 { 74 /* zAVLSearch() checks for NULL tree 75 */ 76 if (key) 77 { 78 return ((char *) zAVLSearch (tree, key)); 79 } 80 return NULL; 81 } 82 83 35 84 /* Wed Nov 23 17:57:42 CET 2005 rw: introduce third argument in 36 85 * zAVLCloseSearchNode() to avoid redundant strcmp … … 86 135 zAVLTree *rc; 87 136 88 rc = malloc(sizeof(zAVLTree));137 rc = calloc(1, sizeof(zAVLTree)); 89 138 if (rc == NULL) 90 139 return NULL; … … 130 179 int ok; 131 180 132 newnode = malloc(sizeof(zAVLNode));181 newnode = calloc(1, sizeof(zAVLNode)); 133 182 if (newnode == NULL) 134 183 return -1;
Note:
See TracChangeset
for help on using the changeset viewer.