File: nodetree.h

package info (click to toggle)
dspam 3.10.1+dfsg-11
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,656 kB
  • sloc: ansic: 26,034; sh: 12,546; perl: 5,469; makefile: 690; sql: 379
file content (87 lines) | stat: -rw-r--r-- 2,502 bytes parent folder | download
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
85
86
87
/* $Id: nodetree.h,v 1.10 2011/06/28 00:13:48 sbajic Exp $ */

/*
 DSPAM
 COPYRIGHT (C) 2002-2011 DSPAM PROJECT

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as
 published by the Free Software Foundation, either version 3 of the
 License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#   include <unistd.h>
#endif

#ifndef _NODETREE_H
#define _NODETREE_H

/* Nodetree: An ordered dynamic data collection structure
 *
 *  Nodetree is designed to provide an ordered collective dynamic data
 *  structure for arrays of unknown size, where it is impractical to
 *  overallocate space.  Nodetree allows the user to allocate memory for
 *  new items as needed, and provides simple management and iteration
 *  functionality.  It is a linked list on steroids.
 *
 *  Nodetree types:
 *
 *  NT_CHAR	Character Nodetree
 *		Treats the passed pointer as a const char * and creates
 * 		new storage space for each string
 *
 *  NT_PTR	Pointer Nodetree
 *		Does not perform string conversion, instead just stores
 *		the pointer's location in the nodetree.  Prior to adding
 *              an item, the user should malloc storage for the new
 *              structure and pass the pointer to the nodetree functions.
 *
 *  NT_INDEX	Pointer Index
 *              Same as Pointer Nodetree, only does not free() the ptr
 *              objects upon deletion
 */

#define NT_CHAR		0x00
#define NT_PTR		0x01
#define NT_INDEX	0x02

struct nt_node
{
  void *ptr;
  struct nt_node *next;
};

struct nt
{
  struct nt_node *first;
  struct nt_node *insert;	/* Next insertion point */
  int items;
  int nodetype;
};

struct nt_c
{
  struct nt_node *iter_index;
};

struct nt_node *	nt_add		(struct nt *nt, void *data);
struct nt_node *	c_nt_first	(struct nt *nt, struct nt_c *c);
struct nt_node *	c_nt_next	(struct nt *nt, struct nt_c *c);
struct nt *		nt_create	(int node_type);
void			nt_destroy	(struct nt *nt);
struct nt_node *	nt_node_create	(void *data);

#endif /* _NODETREE_H */