sbsttable.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_SBSTTABLE_H
  21. #define _AAPL_SBSTTABLE_H
  22. #include "compare.h"
  23. #include "svector.h"
  24. /**
  25. * \addtogroup bst
  26. * @{
  27. */
  28. /**
  29. * \class SBstTable
  30. * \brief Copy-on-write binary search table for structures that contain a key.
  31. *
  32. * This is a basic binary search table that employs a copy-on-write data
  33. * storage mechanism. It can be used to contain a structure that has a key and
  34. * possibly some data. The key should be a member of the element class and
  35. * accessible with getKey(). A class containing the compare routine must be
  36. * supplied.
  37. */
  38. /*@}*/
  39. #define BST_TEMPL_DECLARE class Element, class Key, \
  40. class Compare = CmpOrd<Key>, class Resize = ResizeExpn
  41. #define BST_TEMPL_DEF class Element, class Key, class Compare, class Resize
  42. #define BST_TEMPL_USE Element, Key, Compare, Resize
  43. #define GET_KEY(el) ((el).getKey())
  44. #define BstTable SBstTable
  45. #define Vector SVector
  46. #define Table STable
  47. #define BSTTABLE
  48. #define SHARED_BST
  49. #include "bstcommon.h"
  50. #undef BST_TEMPL_DECLARE
  51. #undef BST_TEMPL_DEF
  52. #undef BST_TEMPL_USE
  53. #undef GET_KEY
  54. #undef BstTable
  55. #undef Vector
  56. #undef Table
  57. #undef BSTTABLE
  58. #undef SHARED_BST
  59. /**
  60. * \fn SBstTable::insert(const Key &key, Element **lastFound)
  61. * \brief Insert a new element with the given key.
  62. *
  63. * If the given key does not already exist in the table a new element is
  64. * inserted with the given key. A constructor taking only const Key& is used
  65. * to initialize the new element. If lastFound is given, it is set to the new
  66. * element created. If the insert fails then lastFound is set to the existing
  67. * element with the same key.
  68. *
  69. * \returns The new element created upon success, null upon failure.
  70. */
  71. /**
  72. * \fn SBstTable::insertMulti(const Key &key)
  73. * \brief Insert a new element even if the key exists already.
  74. *
  75. * If the key exists already then the new element is placed next to some
  76. * element with the same key. InsertMulti cannot fail. A constructor taking
  77. * only const Key& is used to initialize the new element.
  78. *
  79. * \returns The new element created.
  80. */
  81. #endif /* _AAPL_SBSTTABLE_H */