bsttable.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2002 Adrian Thurston <thurston@cs.queensu.ca>
  3. */
  4. /* This file is part of Aapl.
  5. *
  6. * Aapl is free software; you can redistribute it and/or modify it under the
  7. * terms of the GNU Lesser General Public License as published by the Free
  8. * Software Foundation; either version 2.1 of the License, or (at your option)
  9. * any later version.
  10. *
  11. * Aapl is distributed in the hope that it will be useful, but WITHOUT ANY
  12. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with Aapl; if not, write to the Free Software Foundation, Inc., 59
  18. * Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #ifndef _AAPL_BSTTABLE_H
  21. #define _AAPL_BSTTABLE_H
  22. #include "compare.h"
  23. #include "vector.h"
  24. /**
  25. * \addtogroup bst
  26. * @{
  27. */
  28. /**
  29. * \class BstTable
  30. * \brief Binary search table for structures that contain a key.
  31. *
  32. * This is the basic binary search table. It can be used to contain a
  33. * structure that has a key and possibly some data. The key should be a member
  34. * of the element class and accessible with getKey(). A class containing the
  35. * compare routine must be supplied.
  36. */
  37. /*@}*/
  38. #define BST_TEMPL_DECLARE class Element, class Key, \
  39. class Compare = CmpOrd<Key>, class Resize = ResizeExpn
  40. #define BST_TEMPL_DEF class Element, class Key, class Compare, class Resize
  41. #define BST_TEMPL_USE Element, Key, Compare, Resize
  42. #define GET_KEY(el) ((el).getKey())
  43. #define BSTTABLE
  44. #include "bstcommon.h"
  45. #undef BST_TEMPL_DECLARE
  46. #undef BST_TEMPL_DEF
  47. #undef BST_TEMPL_USE
  48. #undef GET_KEY
  49. #undef BSTTABLE
  50. /**
  51. * \fn BstTable::insert(const Key &key, Element **lastFound)
  52. * \brief Insert a new element with the given key.
  53. *
  54. * If the given key does not already exist in the table a new element is
  55. * inserted with the given key. A constructor taking only const Key& is used
  56. * to initialize the new element. If lastFound is given, it is set to the new
  57. * element created. If the insert fails then lastFound is set to the existing
  58. * element with the same key.
  59. *
  60. * \returns The new element created upon success, null upon failure.
  61. */
  62. /**
  63. * \fn BstTable::insertMulti(const Key &key)
  64. * \brief Insert a new element even if the key exists already.
  65. *
  66. * If the key exists already then the new element is placed next to some
  67. * element with the same key. InsertMulti cannot fail. A constructor taking
  68. * only const Key& is used to initialize the new element.
  69. *
  70. * \returns The new element created.
  71. */
  72. #endif /* _AAPL_BSTTABLE_H */