Mon, 13 Nov 2017 15:54:17 +0100
toc for examples
264
24f5484bae97
web doc has now proper titles
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
1 | --- |
24f5484bae97
web doc has now proper titles
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
2 | title: Modules |
24f5484bae97
web doc has now proper titles
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
3 | --- |
259 | 4 | |
5 | UCX provides several modules for data structures and algorithms. | |
6 | You may choose to use specific modules by inclueding the corresponding header | |
7 | file. | |
8 | Please note, that some modules make use of other UCX modules. | |
9 | For instance, the [Allocator](#allocator) module is used by many other modules | |
10 | to allow flexible memory allocation. | |
11 | By default the header files are placed into an `ucx` directory within your | |
12 | systems include directory. In this case you can use an module by including it | |
13 | via `#include <ucx/MODULENAME.h>`. | |
14 | Required modules are included automatically. | |
15 | ||
16 | <a name="allocator"></a> | |
17 | ||
18 | ## Allocator | |
19 | ||
20 | *Header file:* [allocator.h](api/allocator_8h.html) | |
21 | *Required modules:* None. | |
22 | ||
23 | A UCX allocator consists of a pointer to the memory area / pool and four | |
24 | function pointers to memory management functions operating on this memory | |
25 | area / pool. These functions shall behave equivalent to the standard libc | |
26 | functions `malloc`, `calloc`, `realloc` and `free`. | |
27 | ||
28 | The signature of the memory management functions is based on the signature | |
29 | of the respective libc function but each of them takes the pointer to the | |
30 | memory area / pool as first argument. | |
31 | ||
32 | As the pointer to the memory area / pool can be arbitrarily chosen, any data | |
33 | can be provided to the memory management functions. One example is the | |
34 | [UCX Memory Pool](#mempool). | |
35 | ||
36 | <a name="avl"></a> | |
37 | ||
38 | ## AVL Tree | |
39 | ||
40 | *Header file:* [avl.h](api/avl_8h.html) | |
41 | *Required modules:* [Allocator](#allocator) | |
42 | ||
43 | This binary search tree implementation allows average O(1) insertion and | |
44 | removal of elements (excluding binary search time). | |
45 | All common binary tree operations are implemented. Furthermore, this module | |
46 | provides search functions via lower and upper bounds. | |
47 | ||
48 | <a name="buffer"></a> | |
49 | ||
50 | ## Buffer | |
51 | ||
52 | *Header file:* [buffer.h](api/buffer_8h.html) | |
53 | *Required modules:* None. | |
54 | ||
55 | Instances of this buffer implementation can be used to read from or to write to | |
56 | memory like you would do with a stream. This allows the use of | |
57 | `ucx_stream_copy` from the [Utilities](#utils) module to copy contents from one | |
58 | buffer to another or from file or network streams to the buffer and | |
59 | vice-versa. | |
60 | ||
61 | More features for convenient use of the buffer can be enabled, like automatic | |
62 | memory management and automatic resizing of the buffer space. | |
63 | See the documentation of the macro constants in the header file for more | |
64 | information. | |
65 | ||
66 | <a name="list"></a> | |
67 | ||
68 | ## List | |
69 | ||
70 | *Header file:* [list.h](api/list_8h.html) | |
71 | *Required modules:* [Allocator](#allocator) | |
72 | ||
73 | This module provides the data structure and several functions for a doubly | |
74 | linked list. Among the common operations like insert, remove, search and sort, | |
75 | we allow convenient iteration via a special `UCX_FOREACH` macro. | |
76 | ||
77 | <a name="logging"></a> | |
78 | ||
79 | ## Logging | |
80 | ||
81 | *Header file:* [logging.h](api/logging_8h.html) | |
82 | *Required modules:* [Map](#map), [String](#string) | |
83 | ||
84 | The logging module comes with some predefined log levels and allows some more | |
85 | customization. You may choose if you want to get timestamps or source file and | |
86 | line number logged automatically when outputting a message. | |
87 | ||
88 | ||
89 | <a name="map"></a> | |
90 | ||
91 | ## Map | |
92 | ||
93 | *Header file:* [map.h](api/map_8h.html) | |
94 | *Required modules:* [Allocator](#allocator), [String](#string) | |
95 | ||
96 | This module provides a hash map implementation using murmur hash 2 and separate | |
97 | chaining with linked lists. Similarly to the list module, we provide a | |
98 | `UCX_MAP_FOREACH` macro to conveniently iterate through the key/value pairs. | |
99 | ||
100 | <a name="mempool"></a> | |
101 | ||
102 | ## Memory Pool | |
103 | ||
104 | *Header file:* [mempool.h](api/mempool_8h.html) | |
105 | *Required modules:* [Allocator](#allocator) | |
106 | ||
107 | Here we have a concrete allocator implementation in the sense of a memory pool. | |
108 | This pool allows you to register destructor functions for the allocated memory, | |
109 | which are automatically called on the destruction of the pool. | |
110 | But you may also register *independent* destructor functions within a pool in | |
111 | case, some external library allocated memory for you, which you wish to be | |
112 | destroyed together with this pool. | |
113 | ||
114 | <a name="properties"></a> | |
115 | ||
116 | ## Properties | |
117 | ||
118 | *Header file:* [properties.h](api/properties_8h.html) | |
119 | *Required modules:* [Map](#map) | |
120 | ||
121 | This module provides load and store function for `*.properties` files. | |
122 | The key/value pairs are stored within an UCX Map. | |
123 | ||
124 | <a name="stack"></a> | |
125 | ||
126 | ## Stack | |
127 | ||
128 | *Header file:* [stack.h](api/stack_8h.html) | |
129 | *Required modules:* [Allocator](#allocator) | |
130 | ||
131 | This concrete implementation of an UCX Allocator allows you to grab some amount | |
132 | of memory which is then handled as a stack. | |
133 | Please note, that the term *stack* only refers to the behavior of this | |
134 | allocator. You may still choose if you want to use stack or heap memory | |
135 | for the underlying space. | |
136 | ||
137 | A typical use case is an algorithm where you need to allocate and free large | |
138 | amounts of memory very frequently. | |
139 | ||
140 | <a name="string"></a> | |
141 | ||
142 | ## String | |
143 | ||
144 | *Header file:* [string.h](api/string_8h.html) | |
145 | *Required modules:* [Allocator](#allocator) | |
146 | ||
147 | This module provides a safe implementation of bounded string. | |
148 | Usually C strings do not carry a length. While for zero-terminated strings you | |
149 | can easily get the length with `strlen`, this is not generally possible for | |
150 | arbitrary strings. | |
151 | The `sstr_t` type of this module always carries the string and its length to | |
152 | reduce the risk of buffer overflows dramatically. | |
153 | ||
154 | <a name="test"></a> | |
155 | ||
156 | ## Testing | |
157 | ||
158 | *Header file:* [test.h](api/test_8h.html) | |
159 | *Required modules:* None. | |
160 | ||
161 | This module provides a testing framework which allows you to execute test cases | |
162 | within test suites. | |
163 | To avoid code duplication within tests, we also provide the possibility to | |
164 | define test subroutines. | |
165 | ||
166 | <a name="utils"></a> | |
167 | ||
168 | ## Utilities | |
169 | ||
170 | *Header file:* [utils.h](api/utils_8h.html) | |
171 | *Required modules:* [Allocator](#allocator), [String](#string) | |
172 | ||
173 | In this module we provide very general utility function for copy and compare | |
174 | operations. | |
175 | We also provide several `printf` variants to conveniently print formatted data | |
176 | to streams or strings. | |
177 |