Mon, 18 May 2015 20:39:04 +0200
added 1 assert in ucx_avl_remove tests and fixed source code formatting
192
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2015 Olaf Wintermann. All rights reserved. |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
30 | /** |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
31 | * @file avl.h |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
32 | * |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
33 | * AVL tree implementation. |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
34 | * |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
35 | * This binary search tree implementation allows average O(1) insertion and |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
36 | * removal of elements. |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
37 | * |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
38 | * @author Mike Becker |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
39 | * @author Olaf Wintermann |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
40 | */ |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
41 | |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
42 | #ifndef UCX_AVL_H |
194
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
43 | #define UCX_AVL_H |
192
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
44 | |
193
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
45 | #include "ucx.h" |
194
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
46 | #include "allocator.h" |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
47 | #include <stdint.h> |
193
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
48 | |
192
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
49 | #ifdef __cplusplus |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
50 | extern "C" { |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | #endif |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | |
193
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
53 | /** |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
54 | * UCX AVL Node type. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
55 | * |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
56 | * @see UcxAVLNode |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
57 | */ |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
58 | typedef struct UcxAVLNode UcxAVLNode; |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
59 | |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
60 | /** |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
61 | * UCX AVL Node. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
62 | */ |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
63 | struct UcxAVLNode { |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
64 | /** |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
65 | * The key for this node. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
66 | */ |
194
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
67 | intptr_t key; |
193
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
68 | /** |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
69 | * Data contained by this node. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
70 | */ |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
71 | void *value; |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
72 | /** |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
73 | * The height of this (sub)-tree. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
74 | */ |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
75 | size_t height; |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
76 | /** |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
77 | * Parent node. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
78 | */ |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
79 | UcxAVLNode *parent; |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
80 | /** |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
81 | * Root node of left subtree. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
82 | */ |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
83 | UcxAVLNode *left; |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
84 | /** |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
85 | * Root node of right subtree. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
86 | */ |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
87 | UcxAVLNode *right; |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
88 | }; |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
89 | |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
90 | /** |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
91 | * UCX AVL Tree. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
92 | */ |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
93 | typedef struct { |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
94 | /** |
194
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
95 | * The UcxAllocator that shall be used to manage the memory for node data. |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
96 | */ |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
97 | UcxAllocator *allocator; |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
98 | /** |
193
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
99 | * Root node of the tree. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
100 | */ |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
101 | UcxAVLNode *root; |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
102 | /** |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
103 | * Compare function that shall be used to compare the UcxAVLNode keys. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
104 | * @see UcxAVLNode.key |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
105 | */ |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
106 | cmp_func cmpfunc; |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
107 | /** |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
108 | * Custom user data. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
109 | * This data will also be provided to the cmpfunc. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
110 | */ |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
111 | void *userdata; |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
112 | } UcxAVLTree; |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
113 | |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
114 | /** |
194
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
115 | * Initializes a new UcxAVLTree with a default allocator. |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
116 | * |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
117 | * @param cmpfunc the compare function that shall be used |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
118 | * @return a new UcxAVLTree object |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
119 | * @see ucx_avl_new_a() |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
120 | */ |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
121 | UcxAVLTree *ucx_avl_new(cmp_func cmpfunc); |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
122 | |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
123 | /** |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
124 | * Initializes a new UcxAVLTree with the specified allocator. |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
125 | * |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
126 | * The cmpfunc should be capable of comparing two keys within this AVL tree. |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
127 | * So if you want to use null terminated strings as keys, you could use the |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
128 | * ucx_strcmp() function here. |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
129 | * |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
130 | * @param cmpfunc the compare function that shall be used |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
131 | * @param allocator the UcxAllocator that shall be used |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
132 | * @return a new UcxAVLTree object |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
133 | */ |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
134 | UcxAVLTree *ucx_avl_new_a(cmp_func cmpfunc, UcxAllocator *allocator); |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
135 | |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
136 | /** |
196
1b4cdafef2eb
added free() to AVL tree implementation + use UcxAllocator
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
137 | * Destroys an UcxAVLTree. |
1b4cdafef2eb
added free() to AVL tree implementation + use UcxAllocator
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
138 | * @param tree the tree to destroy |
1b4cdafef2eb
added free() to AVL tree implementation + use UcxAllocator
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
139 | */ |
1b4cdafef2eb
added free() to AVL tree implementation + use UcxAllocator
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
140 | void ucx_avl_free(UcxAVLTree *tree); |
1b4cdafef2eb
added free() to AVL tree implementation + use UcxAllocator
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
141 | |
1b4cdafef2eb
added free() to AVL tree implementation + use UcxAllocator
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
142 | /** |
194
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
143 | * Macro for initializing a new UcxAVLTree with the default allocator and a |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
144 | * ucx_ptrcmp() compare function. |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
145 | * |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
146 | * @return a new default UcxAVLTree object |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
147 | */ |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
148 | #define ucx_avl_default_new() ucx_avl_new_a(ucx_ptrcmp, ucx_default_allocator()) |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
149 | |
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
150 | /** |
193
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
151 | * Gets the value from the tree, that is associated with the specified key. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
152 | * @param tree the UcxAVLTree |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
153 | * @param key the key |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
154 | * @return the value (or <code>NULL</code>, if the key is not present) |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
155 | */ |
194
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
156 | void *ucx_avl_get(UcxAVLTree *tree, intptr_t key); |
193
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
157 | |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
158 | /** |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
159 | * Puts a key/value pair into the tree. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
160 | * @param tree the UcxAVLTree |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
161 | * @param key the key |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
162 | * @param value the new value |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
163 | * @return the replaced value (or <code>NULL</code>, if the key is new to the |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
164 | * tree) |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
165 | */ |
194
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
166 | void* ucx_avl_put(UcxAVLTree *tree, intptr_t key, void *value); |
193
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
167 | |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
168 | /** |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
169 | * Removes an element from the AVL tree. |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
170 | * @param tree the UcxAVLTree |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
171 | * @param key the key |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
172 | * @return the removed value (or <code>NULL</code>, if the key was not present) |
fb05d315a0ba
defined AVL tree functional interface
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
173 | */ |
194
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
193
diff
changeset
|
174 | void* ucx_avl_remove(UcxAVLTree *tree, intptr_t key); |
192
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
175 | |
199 | 176 | /** |
177 | * Counts the nodes in the specified UcxAVLTree. | |
178 | * @param tree the AVL tree | |
179 | * @return the node count | |
180 | */ | |
181 | size_t ucx_avl_count(UcxAVLTree *tree); | |
192
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
182 | |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
183 | #ifdef __cplusplus |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
184 | } |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
185 | #endif |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
186 | |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
187 | #endif /* UCX_AVL_H */ |
1e51558b9d09
updated copyright notice + added files for upcoming AVL tree implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
188 |