docs/src/modules.md

Sat, 28 Oct 2017 15:43:51 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 28 Oct 2017 15:43:51 +0200
changeset 259
2f5dea574a75
parent 256
2c21b42cf11d
child 264
24f5484bae97
permissions
-rw-r--r--

modules documentation

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

mercurial