blob: c6967bfd42a696cc862e9bb6e8a33177f1441682 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
libdtree
========
The last C datastructure library you will use. Provides a versatile
tree-like structure that can act as lists, sets and more! Many
features are still experimental and the API might change at any point
so be aware.
How to build
============
libdyntree is built with cmake. It has no external dependencies and
compilation has been tested with gcc 6+ on Linx systems. It was tested
with C99 but shouldbe able to compile with ANSI C as well.
```console
$> mkdir build; cd build
$> cmake ..
$> make -j 2
```
This will create a `.so` file. If you require a static object, you can
change the linking behaviour in the `CMakeLists.txt` file.
## How to use
Everything resolves around `dtree` objects and providing fields to API
functions. Generally, memory is managed for you by libdtree:
```C
dt_err err;
dtree *data;
err = dtree_malloc(&data);
```
Alternatively you can use the shortcut alloc functions provided:
```C
dtree *str_node = dtree_alloc_literal("My string in this node!");
dtree *num_node = dtree_alloc_numeral(1337);
dtree *key, *val;
dtree *pair_node = dtree *dtree_allocpair_new(&key, &val);
```
Nodes can change their type, provided they get reset before assigning
a different type of data to them first. The available types are listed
below:
- Unset
- Literal
- Numerical
- Recursive
- Pair
- Pointer
Some more advanced functions include a getter, a search, a keyed search as well as tree merge and split functions. Please consult the wiki for details on how to use some of these functions.
## License
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at
your option) any later version.
I hope you enjoy ♥
|