summaryrefslogtreecommitdiff
path: root/numlib/aatree.h
blob: 2a6df842a82aa27d399362756f52aa123a750348 (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
#ifndef AATREE_H
#define AATREE_H

/*
  Andersson binary balanced tree library

    > Created (Julienne Walker): September 10, 2005

  This code is in the public domain. Anyone may
  use it or change it in any way that they see
  fit. The author assumes no responsibility for 
  damages incurred through use of the original
  code or any variations thereof.

  It is requested, but not required, that due
  credit is given to the original author and
  anyone who has modified the code through
  a header comment, such as this one.
*/

#ifdef __cplusplus
#include <cstddef>

using std::size_t;

extern "C" {
#else
#include <stddef.h>
#endif

/* Opaque types */
typedef struct aat_atree aat_atree_t;
typedef struct aat_atrav aat_atrav_t;

/* User-defined item handling */
typedef int   (*cmp_f) ( const void *p1, const void *p2 );

/* Andersson tree functions */
aat_atree_t *aat_anew ( cmp_f cmp );
void         aat_adelete ( aat_atree_t *tree );
void        *aat_afind ( aat_atree_t *tree, void *data );
int          aat_ainsert ( aat_atree_t *tree, void *data );
int          aat_aerase ( aat_atree_t *tree, void *data );
size_t       aat_asize ( aat_atree_t *tree );

/* Traversal functions */
aat_atrav_t *aat_atnew ( void );
void         aat_atdelete ( aat_atrav_t *trav );
void        *aat_atfirst ( aat_atrav_t *trav, aat_atree_t *tree );
void        *aat_atlast ( aat_atrav_t *trav, aat_atree_t *tree );
void        *aat_atnext ( aat_atrav_t *trav );
void        *aat_atprev ( aat_atrav_t *trav );

#ifdef __cplusplus
}
#endif

#endif	/* AATREE */