ucx/avl.c

changeset 255
bf19378aed58
parent 128
649eb328674a
child 314
8722a668fb2a
--- a/ucx/avl.c	Fri Nov 18 13:39:20 2016 +0100
+++ b/ucx/avl.c	Fri Nov 18 15:27:45 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -29,6 +29,8 @@
 #include "avl.h"
 
 #define ptrcast(ptr) ((void*)(ptr))
+#define alloc_tree(al) (UcxAVLTree*) almalloc((al), sizeof(UcxAVLTree))
+#define alloc_node(al) (UcxAVLNode*) almalloc((al), sizeof(UcxAVLNode))
 
 static void ucx_avl_connect(UcxAVLTree *tree,
         UcxAVLNode *node, UcxAVLNode *child, intptr_t nullkey) {
@@ -107,7 +109,7 @@
 }
 
 UcxAVLTree *ucx_avl_new_a(cmp_func cmpfunc, UcxAllocator *allocator) {
-    UcxAVLTree *tree = almalloc(allocator, sizeof(UcxAVLTree));
+    UcxAVLTree* tree = alloc_tree(allocator);
     if (tree) {
         tree->allocator = allocator;
         tree->cmpfunc = cmpfunc;
@@ -167,7 +169,7 @@
         }
 
         if (cmpresult) {
-            UcxAVLNode *e = almalloc(tree->allocator, sizeof(UcxAVLNode));
+            UcxAVLNode* e = alloc_node(tree->allocator);
             if (e) {
                 e->key = key; e->value = value; e->height = 1;
                 e->parent = e->left = e->right = NULL;
@@ -185,7 +187,7 @@
             return 0;
         }
     } else {
-        tree->root = almalloc(tree->allocator, sizeof(UcxAVLNode));
+        tree->root = alloc_node(tree->allocator);
         if (tree->root) {
             tree->root->key = key; tree->root->value = value;
             tree->root->height = 1;

mercurial