Back to index

cell-binutils  2.17cvs20070401
ternary.h
Go to the documentation of this file.
00001 /* ternary.h - Ternary Search Trees
00002    Copyright 2001 Free Software Foundation, Inc.
00003 
00004    Contributed by Daniel Berlin (dan@cgsoftware.com)
00005 
00006 
00007    This program is free software; you can redistribute it and/or modify it
00008    under the terms of the GNU General Public License as published by the
00009    Free Software Foundation; either version 2, or (at your option) any
00010    later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
00020    USA.  */
00021 #ifndef TERNARY_H_
00022 #define TERNARY_H_
00023 /* Ternary search trees */
00024 
00025 typedef struct ternary_node_def *ternary_tree;
00026 
00027 typedef struct ternary_node_def
00028 {
00029   char splitchar;
00030   ternary_tree lokid;
00031   ternary_tree eqkid;
00032   ternary_tree hikid;
00033 }
00034 ternary_node;
00035 
00036 /* Insert string S into tree P, associating it with DATA. 
00037    Return the data in the tree associated with the string if it's
00038    already there, and replace is 0.
00039    Otherwise, replaces if it it exists, inserts if it doesn't, and
00040    returns the data you passed in. */
00041 void *ternary_insert (ternary_tree *p, const char *s,
00042                     void *data, int replace);
00043 
00044 /* Delete the ternary search tree rooted at P. 
00045    Does NOT delete the data you associated with the strings. */
00046 void ternary_cleanup (ternary_tree p);
00047 
00048 /* Search the ternary tree for string S, returning the data associated
00049    with it if found. */
00050 void *ternary_search (const ternary_node *p, const char *s);
00051 #endif