1169695Skan/* ternary.h - Ternary Search Trees
2169695Skan   Copyright 2001 Free Software Foundation, Inc.
3169695Skan
4169695Skan   Contributed by Daniel Berlin (dan@cgsoftware.com)
5169695Skan
6169695Skan
7169695Skan   This program is free software; you can redistribute it and/or modify it
8169695Skan   under the terms of the GNU General Public License as published by the
9169695Skan   Free Software Foundation; either version 2, or (at your option) any
10169695Skan   later version.
11169695Skan
12169695Skan   This program is distributed in the hope that it will be useful,
13169695Skan   but WITHOUT ANY WARRANTY; without even the implied warranty of
14169695Skan   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15169695Skan   GNU General Public License for more details.
16169695Skan
17169695Skan   You should have received a copy of the GNU General Public License
18169695Skan   along with this program; if not, write to the Free Software
19169695Skan   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
20169695Skan   USA.  */
21169695Skan#ifndef TERNARY_H_
22169695Skan#define TERNARY_H_
23169695Skan/* Ternary search trees */
24169695Skan
25169695Skantypedef struct ternary_node_def *ternary_tree;
26169695Skan
27169695Skantypedef struct ternary_node_def
28169695Skan{
29169695Skan  char splitchar;
30169695Skan  ternary_tree lokid;
31169695Skan  ternary_tree eqkid;
32169695Skan  ternary_tree hikid;
33169695Skan}
34169695Skanternary_node;
35169695Skan
36169695Skan/* Insert string S into tree P, associating it with DATA.
37169695Skan   Return the data in the tree associated with the string if it's
38169695Skan   already there, and replace is 0.
39169695Skan   Otherwise, replaces if it it exists, inserts if it doesn't, and
40169695Skan   returns the data you passed in. */
41169695Skanvoid *ternary_insert (ternary_tree *p, const char *s,
42169695Skan		      void *data, int replace);
43169695Skan
44169695Skan/* Delete the ternary search tree rooted at P.
45169695Skan   Does NOT delete the data you associated with the strings. */
46169695Skanvoid ternary_cleanup (ternary_tree p);
47169695Skan
48169695Skan/* Search the ternary tree for string S, returning the data associated
49169695Skan   with it if found. */
50169695Skanvoid *ternary_search (const ternary_node *p, const char *s);
51169695Skan#endif
52