avltree.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_AVLTREE_H
  21. #define _AAPL_AVLTREE_H
  22. #include "compare.h"
  23. /**
  24. * \addtogroup avltree
  25. * @{
  26. */
  27. /**
  28. * \class AvlTree
  29. * \brief Basic AVL tree.
  30. *
  31. * AvlTree is the standard by-structure AVL tree. To use this structure the
  32. * user must define an element type and give it the necessary properties. At
  33. * the very least it must have a getKey() function that will be used to
  34. * compare the relative ordering of elements and tree management data
  35. * necessary for the AVL algorithm. An element type can acquire the management
  36. * data by inheriting the AvlTreeEl class.
  37. *
  38. * AvlTree does not presume to manage the allocation of elements in the tree.
  39. * The destructor will not delete the items in the tree, instead the elements
  40. * must be explicitly de-allocated by the user if necessary and when it is
  41. * safe to do so. The empty() routine will traverse the tree and delete all
  42. * items.
  43. *
  44. * Since the tree does not manage the elements, it can contain elements that
  45. * are allocated statically or that are part of another data structure.
  46. *
  47. * \include ex_avltree.cpp
  48. */
  49. /*@}*/
  50. #define BASE_EL(name) name
  51. #define BASEKEY(name) name
  52. #define AVLMEL_CLASSDEF class Element, class Key, class Compare = CmpOrd<Key>
  53. #define AVLMEL_TEMPDEF class Element, class Key, class Compare
  54. #define AVLMEL_TEMPUSE Element, Key, Compare
  55. #define AvlTree AvlTree
  56. #include "avlcommon.h"
  57. #undef BASE_EL
  58. #undef BASEKEY
  59. #undef AVLMEL_CLASSDEF
  60. #undef AVLMEL_TEMPDEF
  61. #undef AVLMEL_TEMPUSE
  62. #undef AvlTree
  63. #endif /* _AAPL_AVLTREE_H */