2 * Copyright 2002 Adrian Thurston <thurston@cs.queensu.ca>
5 /* This file is part of Aapl.
7 * Aapl is free software; you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free
9 * Software Foundation; either version 2.1 of the License, or (at your option)
12 * Aapl is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with Aapl; if not, write to the Free Software Foundation, Inc., 59
19 * Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef _AAPL_BSTTABLE_H
23 #define _AAPL_BSTTABLE_H
35 * \brief Binary search table for structures that contain a key.
37 * This is the basic binary search table. It can be used to contain a
38 * structure that has a key and possibly some data. The key should be a member
39 * of the element class and accessible with getKey(). A class containing the
40 * compare routine must be supplied.
45 #define BST_TEMPL_DECLARE class Element, class Key, \
46 class Compare = CmpOrd<Key>, class Resize = ResizeExpn
47 #define BST_TEMPL_DEF class Element, class Key, class Compare, class Resize
48 #define BST_TEMPL_USE Element, Key, Compare, Resize
49 #define GET_KEY(el) ((el).getKey())
52 #include "bstcommon.h"
54 #undef BST_TEMPL_DECLARE
61 * \fn BstTable::insert(const Key &key, Element **lastFound)
62 * \brief Insert a new element with the given key.
64 * If the given key does not already exist in the table a new element is
65 * inserted with the given key. A constructor taking only const Key& is used
66 * to initialize the new element. If lastFound is given, it is set to the new
67 * element created. If the insert fails then lastFound is set to the existing
68 * element with the same key.
70 * \returns The new element created upon success, null upon failure.
74 * \fn BstTable::insertMulti(const Key &key)
75 * \brief Insert a new element even if the key exists already.
77 * If the key exists already then the new element is placed next to some
78 * element with the same key. InsertMulti cannot fail. A constructor taking
79 * only const Key& is used to initialize the new element.
81 * \returns The new element created.
84 #endif /* _AAPL_BSTTABLE_H */