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_SBSTTABLE_H
23 #define _AAPL_SBSTTABLE_H
35 * \brief Copy-on-write binary search table for structures that contain a key.
37 * This is a basic binary search table that employs a copy-on-write data
38 * storage mechanism. It can be used to contain a structure that has a key and
39 * possibly some data. The key should be a member of the element class and
40 * accessible with getKey(). A class containing the compare routine must be
46 #define BST_TEMPL_DECLARE class Element, class Key, \
47 class Compare = CmpOrd<Key>, class Resize = ResizeExpn
48 #define BST_TEMPL_DEF class Element, class Key, class Compare, class Resize
49 #define BST_TEMPL_USE Element, Key, Compare, Resize
50 #define GET_KEY(el) ((el).getKey())
51 #define BstTable SBstTable
52 #define Vector SVector
57 #include "bstcommon.h"
59 #undef BST_TEMPL_DECLARE
70 * \fn SBstTable::insert(const Key &key, Element **lastFound)
71 * \brief Insert a new element with the given key.
73 * If the given key does not already exist in the table a new element is
74 * inserted with the given key. A constructor taking only const Key& is used
75 * to initialize the new element. If lastFound is given, it is set to the new
76 * element created. If the insert fails then lastFound is set to the existing
77 * element with the same key.
79 * \returns The new element created upon success, null upon failure.
83 * \fn SBstTable::insertMulti(const Key &key)
84 * \brief Insert a new element even if the key exists already.
86 * If the key exists already then the new element is placed next to some
87 * element with the same key. InsertMulti cannot fail. A constructor taking
88 * only const Key& is used to initialize the new element.
90 * \returns The new element created.
93 #endif /* _AAPL_SBSTTABLE_H */