sbstset.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_SBSTSET_H
  21. #define _AAPL_SBSTSET_H
  22. /**
  23. * \addtogroup bst
  24. * @{
  25. */
  26. /**
  27. * \class SBstSet
  28. * \brief Copy-on-write binary search table for types that are the key.
  29. *
  30. * This is a set style binary search table that employs the copy-on-write
  31. * mechanism for storing table data. BstSet is suitable for types that
  32. * comprise the entire key. Rather than look into the element to retrieve the
  33. * key, the element is the key. A class that contains a comparison routine
  34. * for the key must be given.
  35. */
  36. /*@}*/
  37. #include "compare.h"
  38. #include "svector.h"
  39. #define BST_TEMPL_DECLARE class Key, class Compare = CmpOrd<Key>, \
  40. class Resize = ResizeExpn
  41. #define BST_TEMPL_DEF class Key, class Compare, class Resize
  42. #define BST_TEMPL_USE Key, Compare, Resize
  43. #define GET_KEY(el) (el)
  44. #define BstTable SBstSet
  45. #define Vector SVector
  46. #define Table STable
  47. #define Element Key
  48. #define BSTSET
  49. #define SHARED_BST
  50. #include "bstcommon.h"
  51. #undef BST_TEMPL_DECLARE
  52. #undef BST_TEMPL_DEF
  53. #undef BST_TEMPL_USE
  54. #undef GET_KEY
  55. #undef BstTable
  56. #undef Vector
  57. #undef Table
  58. #undef Element
  59. #undef BSTSET
  60. #undef SHARED_BST
  61. /**
  62. * \fn SBstSet::insert(const Key &key, Key **lastFound)
  63. * \brief Insert the given key.
  64. *
  65. * If the given key does not already exist in the table then it is inserted.
  66. * The key's copy constructor is used to place the item in the table. If
  67. * lastFound is given, it is set to the new entry created. If the insert fails
  68. * then lastFound is set to the existing key of the same value.
  69. *
  70. * \returns The new element created upon success, null upon failure.
  71. */
  72. /**
  73. * \fn SBstSet::insertMulti(const Key &key)
  74. * \brief Insert the given key even if it exists already.
  75. *
  76. * If the key exists already then it is placed next to some other key of the
  77. * same value. InsertMulti cannot fail. The key's copy constructor is used to
  78. * place the item in the table.
  79. *
  80. * \returns The new element created.
  81. */
  82. #endif /* _AAPL_SBSTSET_H */