189857Sobrien/* ternary.h - Ternary Search Trees 289857Sobrien Copyright 2001 Free Software Foundation, Inc. 389857Sobrien 489857Sobrien Contributed by Daniel Berlin (dan@cgsoftware.com) 589857Sobrien 689857Sobrien 789857Sobrien This program is free software; you can redistribute it and/or modify it 889857Sobrien under the terms of the GNU General Public License as published by the 989857Sobrien Free Software Foundation; either version 2, or (at your option) any 1089857Sobrien later version. 1189857Sobrien 1289857Sobrien This program is distributed in the hope that it will be useful, 1389857Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1489857Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1589857Sobrien GNU General Public License for more details. 1689857Sobrien 1789857Sobrien You should have received a copy of the GNU General Public License 1889857Sobrien along with this program; if not, write to the Free Software 19218822Sdim Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, 2089857Sobrien USA. */ 2189857Sobrien#ifndef TERNARY_H_ 2289857Sobrien#define TERNARY_H_ 2389857Sobrien/* Ternary search trees */ 2489857Sobrien 2589857Sobrientypedef struct ternary_node_def *ternary_tree; 2689857Sobrien 2789857Sobrientypedef struct ternary_node_def 2889857Sobrien{ 2989857Sobrien char splitchar; 3089857Sobrien ternary_tree lokid; 3189857Sobrien ternary_tree eqkid; 3289857Sobrien ternary_tree hikid; 3389857Sobrien} 3489857Sobrienternary_node; 3589857Sobrien 3689857Sobrien/* Insert string S into tree P, associating it with DATA. 3789857Sobrien Return the data in the tree associated with the string if it's 3889857Sobrien already there, and replace is 0. 3989857Sobrien Otherwise, replaces if it it exists, inserts if it doesn't, and 4089857Sobrien returns the data you passed in. */ 41218822Sdimvoid *ternary_insert (ternary_tree *p, const char *s, 42218822Sdim void *data, int replace); 4389857Sobrien 4489857Sobrien/* Delete the ternary search tree rooted at P. 4589857Sobrien Does NOT delete the data you associated with the strings. */ 46218822Sdimvoid ternary_cleanup (ternary_tree p); 4789857Sobrien 4889857Sobrien/* Search the ternary tree for string S, returning the data associated 4989857Sobrien with it if found. */ 50218822Sdimvoid *ternary_search (const ternary_node *p, const char *s); 5189857Sobrien#endif 52