Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
SplayTree.h
Go to the documentation of this file.
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Embedded Web-Server
10 ****************************************************************************
11 * HEADER
12 *
13 * $Id: SplayTree.h 5978 2026-09-11 16:13:48Z wini $
14 *
15 * COPYRIGHT: Real Time Logic, 2004 - 2026
16 *
17 * This software is copyrighted by and is the sole property of Real
18 * Time Logic LLC. All rights, title, ownership, or other interests in
19 * the software remain the property of Real Time Logic LLC. This
20 * software may only be used in accordance with the terms and
21 * conditions stipulated in the corresponding license agreement under
22 * which the software has been supplied. Any unauthorized use,
23 * duplication, transmission, distribution, or disclosure of this
24 * software is expressly forbidden.
25 *
26 * This Copyright notice may not be removed or modified without prior
27 * written consent of Real Time Logic LLC.
28 *
29 * Real Time Logic LLC. reserves the right to modify this software
30 * without notice.
31 *
32 * http://www.realtimelogic.com
33 ****************************************************************************
34 *
35 */
36
39#ifndef __SplayTree_h
40#define __SplayTree_h
41
42#include <TargConfig.h>
43
46typedef const void* SplayTreeKey;
47
51typedef struct SplayTreeNode
52{
53#ifdef __cplusplus
54 void *operator new(size_t s) { return ::baMalloc(s); }
55 void operator delete(void* d) { if(d) ::baFree(d); }
56 void *operator new(size_t, void *place) { return place; }
57 void operator delete(void*, void *) { }
59 SplayTreeNode(){} /* Dummy constructor */
65#endif
66 struct SplayTreeNode* left;
67 struct SplayTreeNode* right;
68 SplayTreeKey key;
70
71#ifdef __cplusplus
72extern "C" {
73#endif
81#define SplayTreeNode_getKey(o) (o)->key
82
83#ifdef __cplusplus
84}
86 SplayTreeNode_constructor(this, key); }
88 return SplayTreeNode_getKey(this); }
89#endif
90
97
103typedef int (*SplayTree_Iter)(void* o, SplayTreeNode* n);
104
108typedef struct SplayTree
109{
110#ifdef __cplusplus
112 SplayTree(){} /* Dummy constructor */
119 int insert(SplayTreeNode* n);
127 int remove(SplayTreeNode* n);
130 private:
131#endif
132 SplayTreeNode* root;
133 SplayTree_Compare compare;
135
136#ifdef __cplusplus
137extern "C" {
138#endif
142#define SplayTree_constructor(o, compareCB) do { \
143 (o)->compare = compareCB; \
144 (o)->root = 0; \
145} while(0)
165#define SplayTree_getRoot(o) (o)->root
173BA_API int SplayTree_iterate(SplayTree* o, void* userObj, SplayTree_Iter i);
174#ifdef __cplusplus
175}
177 SplayTree_constructor(this, compare); }
179 return SplayTree_insert(this, n); }
181 return SplayTree_find(this, key); }
183 return SplayTree_remove(this, n); }
185 return SplayTree_getRoot(this); }
186#endif
187
188
189#endif
const void * SplayTreeKey
Borrowed key interpreted by SplayTree_Compare.
Definition: SplayTree.h:46
int(* SplayTree_Iter)(void *o, SplayTreeNode *n)
Visit a node during SplayTree_iterate.
Definition: SplayTree.h:103
BA_API SplayTreeNode * SplayTree_find(SplayTree *o, SplayTreeKey key)
Search and adjust the tree, even when no matching key is found.
BA_API int SplayTree_iterate(SplayTree *o, void *userObj, SplayTree_Iter i)
Visit nodes in root-left-right order, not sorted key order.
BA_API void SplayTreeNode_constructor(SplayTreeNode *o, SplayTreeKey key)
Initialize a node without allocating storage.
struct SplayTreeNode SplayTreeNode
Intrusive tree node.
int(* SplayTree_Compare)(SplayTreeNode *n, SplayTreeKey k)
Compare a search key with a node's key.
Definition: SplayTree.h:96
#define SplayTree_constructor(o, compareCB)
Initialize an empty tree without allocating storage.
Definition: SplayTree.h:142
BA_API int SplayTree_remove(SplayTree *o, SplayTreeNode *n)
Unlink a node and clear its left and right links.
BA_API int SplayTree_insert(SplayTree *o, SplayTreeNode *n)
Insert a node.
struct SplayTree SplayTree
Self-adjusting tree of caller-owned nodes, with unique keys.
#define SplayTreeNode_getKey(o)
Read a node's key.
Definition: SplayTree.h:81
#define SplayTree_getRoot(o)
Read the current root without reshaping the tree.
Definition: SplayTree.h:165
void * baMalloc(size_t size)
Allocate uninitialized storage using the target's configured allocator.
void baFree(void *p)
Release storage using the target's configured allocator.
Intrusive tree node.
Definition: SplayTree.h:52
SplayTreeNode()
Leave storage uninitialized; call SplayTreeNode_constructor before use.
Definition: SplayTree.h:59
SplayTreeKey getKey()
Definition: SplayTree.h:87
Self-adjusting tree of caller-owned nodes, with unique keys.
Definition: SplayTree.h:109
SplayTreeNode * getRoot()
Definition: SplayTree.h:184
int insert(SplayTreeNode *n)
Insert a node without allocating memory.
Definition: SplayTree.h:178
SplayTree()
Leave storage uninitialized; call SplayTree_constructor before use.
Definition: SplayTree.h:112
int remove(SplayTreeNode *n)
Unlink a node without freeing it.
Definition: SplayTree.h:182
SplayTreeNode * find(SplayTreeKey key)
Find a node and adjust the tree.
Definition: SplayTree.h:180