-
Notifications
You must be signed in to change notification settings - Fork 5
/
toolbox-tree.h
84 lines (67 loc) · 2.39 KB
/
toolbox-tree.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// ~~~~~~~~~~~~~~~ C Toolbox ~~~~~~~~~~~~~~~~
// portable data manipulation functions
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// toolbox-tree.h
//
// Copyright (c) 2015 Francois Oligny-Lemieux
// All rights reserved
//
// Created: 12.Apr.2015
//
// Description:
// Single-Threaded binairy tree
// Elements are stored as a btree_T *
//
// Limitations:
// WARNING: Not multi-thread safe, protect by mutex.
//
// License: Yipp Dual Personal Open Source License and Business Monetary License
// http://yipp.ca/licenses/dual-personal-open-source-business-monetary-license/
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#ifndef __C_TOOLBOX_GENERIC_TREE__
#define __C_TOOLBOX_GENERIC_TREE__
#ifdef __cplusplus
extern "C" {
#endif
#include "toolbox-errors.h"
#include "toolbox-basic-types.h" // for uint64_t
#include "toolbox-flexstring.h"
struct genericTree_S;
typedef struct treeItem_S
{
flexString_T name;
struct genericTree_S * tree;
void * client;
struct treeItem_S * parent;
struct treeItem_S * next;
struct treeItem_S * prev;
struct treeItem_S * childs;
uint64_t unique_id;
uint64_t flags;
} treeItem_T;
typedef struct genericTree_S
{
treeItem_T top; // top name should be a directory with no siblings, just childs
int should_always_be_0xAFAF7878;
int accept_duplicate_names;
int accept_duplicate_unique_ids;
int allow_zero_unique_ids; // usually when passing a 0 unique_id, a random one will be generated. Settings this on will keep 0 as the unique id
int max_name_length; // 0 for unlimited, see constructor for default
treeItem_T * current_iterator;
uint64_t next_unique_id;
int characterEncoding; //of type gnucTextEncoding_E
int itemAmount;
} genericTree_T;
int genericTree_Constructor(genericTree_T * genericTree);
int genericTree_Insert(genericTree_T * genericTree, treeItem_T * insert_on_this_level, const char * name, uint64_t unique_id, void * client, treeItem_T ** new_element);
// will delete node and its child, but not free the client void *
int genericTree_Remove(genericTree_T * genericTree, treeItem_T * removeItem);
// will delete node and its child, but not free the client void *
int genericTree_Delete(genericTree_T * genericTree, treeItem_T * removeItem);
int genericTree_Destructor(genericTree_T * genericTree);
#ifdef __cplusplus
}
#endif
#endif