bstset.h 2.5 KB

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