1 | /* $Id: nodetree.h,v 1.10 2011/06/28 00:13:48 sbajic Exp $ */ |
---|
2 | |
---|
3 | /* |
---|
4 | DSPAM |
---|
5 | COPYRIGHT (C) 2002-2012 DSPAM PROJECT |
---|
6 | |
---|
7 | This program is free software: you can redistribute it and/or modify |
---|
8 | it under the terms of the GNU Affero General Public License as |
---|
9 | published by the Free Software Foundation, either version 3 of the |
---|
10 | License, or (at your option) any later version. |
---|
11 | |
---|
12 | This program is distributed in the hope that it will be useful, |
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | GNU Affero General Public License for more details. |
---|
16 | |
---|
17 | You should have received a copy of the GNU Affero General Public License |
---|
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | |
---|
20 | */ |
---|
21 | |
---|
22 | #include <stdio.h> |
---|
23 | #include <string.h> |
---|
24 | #ifdef HAVE_UNISTD_H |
---|
25 | # include <unistd.h> |
---|
26 | #endif |
---|
27 | |
---|
28 | #ifndef _NODETREE_H |
---|
29 | #define _NODETREE_H |
---|
30 | |
---|
31 | /* Nodetree: An ordered dynamic data collection structure |
---|
32 | * |
---|
33 | * Nodetree is designed to provide an ordered collective dynamic data |
---|
34 | * structure for arrays of unknown size, where it is impractical to |
---|
35 | * overallocate space. Nodetree allows the user to allocate memory for |
---|
36 | * new items as needed, and provides simple management and iteration |
---|
37 | * functionality. It is a linked list on steroids. |
---|
38 | * |
---|
39 | * Nodetree types: |
---|
40 | * |
---|
41 | * NT_CHAR Character Nodetree |
---|
42 | * Treats the passed pointer as a const char * and creates |
---|
43 | * new storage space for each string |
---|
44 | * |
---|
45 | * NT_PTR Pointer Nodetree |
---|
46 | * Does not perform string conversion, instead just stores |
---|
47 | * the pointer's location in the nodetree. Prior to adding |
---|
48 | * an item, the user should malloc storage for the new |
---|
49 | * structure and pass the pointer to the nodetree functions. |
---|
50 | * |
---|
51 | * NT_INDEX Pointer Index |
---|
52 | * Same as Pointer Nodetree, only does not free() the ptr |
---|
53 | * objects upon deletion |
---|
54 | */ |
---|
55 | |
---|
56 | #define NT_CHAR 0x00 |
---|
57 | #define NT_PTR 0x01 |
---|
58 | #define NT_INDEX 0x02 |
---|
59 | |
---|
60 | struct nt_node |
---|
61 | { |
---|
62 | void *ptr; |
---|
63 | struct nt_node *next; |
---|
64 | }; |
---|
65 | |
---|
66 | struct nt |
---|
67 | { |
---|
68 | struct nt_node *first; |
---|
69 | struct nt_node *insert; /* Next insertion point */ |
---|
70 | int items; |
---|
71 | int nodetype; |
---|
72 | }; |
---|
73 | |
---|
74 | struct nt_c |
---|
75 | { |
---|
76 | struct nt_node *iter_index; |
---|
77 | }; |
---|
78 | |
---|
79 | struct nt_node * nt_add (struct nt *nt, void *data); |
---|
80 | struct nt_node * c_nt_first (struct nt *nt, struct nt_c *c); |
---|
81 | struct nt_node * c_nt_next (struct nt *nt, struct nt_c *c); |
---|
82 | struct nt * nt_create (int node_type); |
---|
83 | void nt_destroy (struct nt *nt); |
---|
84 | struct nt_node * nt_node_create (void *data); |
---|
85 | |
---|
86 | #endif /* _NODETREE_H */ |
---|
87 | |
---|