ucx/avl.h

changeset 194
0c1b7676e74c
parent 193
fb05d315a0ba
child 196
1b4cdafef2eb
     1.1 --- a/ucx/avl.h	Sun May 17 17:59:07 2015 +0200
     1.2 +++ b/ucx/avl.h	Sun May 17 18:32:41 2015 +0200
     1.3 @@ -40,10 +40,11 @@
     1.4   */
     1.5  
     1.6  #ifndef UCX_AVL_H
     1.7 -#define	UCX_AVL_H
     1.8 +#define UCX_AVL_H
     1.9  
    1.10  #include "ucx.h"
    1.11 -
    1.12 +#include "allocator.h"
    1.13 +#include <stdint.h>
    1.14  
    1.15  #ifdef	__cplusplus
    1.16  extern "C" {
    1.17 @@ -63,7 +64,7 @@
    1.18      /**
    1.19       * The key for this node.
    1.20       */
    1.21 -    void *key;
    1.22 +    intptr_t key;
    1.23      /**
    1.24       * Data contained by this node.
    1.25       */
    1.26 @@ -91,6 +92,10 @@
    1.27   */
    1.28  typedef struct {
    1.29      /**
    1.30 +     * The UcxAllocator that shall be used to manage the memory for node data.
    1.31 +     */
    1.32 +    UcxAllocator *allocator;
    1.33 +    /**
    1.34       * Root node of the tree.
    1.35       */
    1.36      UcxAVLNode *root;
    1.37 @@ -107,12 +112,42 @@
    1.38  } UcxAVLTree;
    1.39  
    1.40  /**
    1.41 + * Initializes a new UcxAVLTree with a default allocator.
    1.42 + * 
    1.43 + * @param cmpfunc the compare function that shall be used
    1.44 + * @return a new UcxAVLTree object
    1.45 + * @see ucx_avl_new_a()
    1.46 + */
    1.47 +UcxAVLTree *ucx_avl_new(cmp_func cmpfunc);
    1.48 +
    1.49 +/**
    1.50 + * Initializes a new UcxAVLTree with the specified allocator.
    1.51 + * 
    1.52 + * The cmpfunc should be capable of comparing two keys within this AVL tree.
    1.53 + * So if you want to use null terminated strings as keys, you could use the
    1.54 + * ucx_strcmp() function here.
    1.55 + * 
    1.56 + * @param cmpfunc the compare function that shall be used
    1.57 + * @param allocator the UcxAllocator that shall be used
    1.58 + * @return a new UcxAVLTree object
    1.59 + */
    1.60 +UcxAVLTree *ucx_avl_new_a(cmp_func cmpfunc, UcxAllocator *allocator);
    1.61 +
    1.62 +/**
    1.63 + * Macro for initializing a new UcxAVLTree with the default allocator and a
    1.64 + * ucx_ptrcmp() compare function.
    1.65 + * 
    1.66 + * @return a new default UcxAVLTree object
    1.67 + */
    1.68 +#define ucx_avl_default_new() ucx_avl_new_a(ucx_ptrcmp, ucx_default_allocator())
    1.69 +
    1.70 +/**
    1.71   * Gets the value from the tree, that is associated with the specified key.
    1.72   * @param tree the UcxAVLTree
    1.73   * @param key the key
    1.74   * @return the value (or <code>NULL</code>, if the key is not present)
    1.75   */
    1.76 -void *ucx_avl_get(UcxAVLTree *tree, void *key);
    1.77 +void *ucx_avl_get(UcxAVLTree *tree, intptr_t key);
    1.78  
    1.79  /**
    1.80   * Puts a key/value pair into the tree.
    1.81 @@ -122,7 +157,7 @@
    1.82   * @return the replaced value (or <code>NULL</code>, if the key is new to the
    1.83   * tree)
    1.84   */
    1.85 -void* ucx_avl_put(UcxAVLTree *tree, void *key, void *value);
    1.86 +void* ucx_avl_put(UcxAVLTree *tree, intptr_t key, void *value);
    1.87  
    1.88  /**
    1.89   * Removes an element from the AVL tree.
    1.90 @@ -130,7 +165,7 @@
    1.91   * @param key the key
    1.92   * @return the removed value (or <code>NULL</code>, if the key was not present)
    1.93   */
    1.94 -void* ucx_avl_remove(UcxAVLTree *tree, void *key);
    1.95 +void* ucx_avl_remove(UcxAVLTree *tree, intptr_t key);
    1.96  
    1.97  
    1.98  

mercurial