splay-tree.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* A splay-tree datatype.
  2. Copyright (C) 1998-2015 Free Software Foundation, Inc.
  3. Contributed by Mark Mitchell (mark@markmitchell.com).
  4. This file is part of the GNU Offloading and Multi Processing Library
  5. (libgomp).
  6. Libgomp is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3, or (at your option)
  9. any later version.
  10. Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. more details.
  14. Under Section 7 of GPL version 3, you are granted additional
  15. permissions described in the GCC Runtime Library Exception, version
  16. 3.1, as published by the Free Software Foundation.
  17. You should have received a copy of the GNU General Public License and
  18. a copy of the GCC Runtime Library Exception along with this program;
  19. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  20. <http://www.gnu.org/licenses/>. */
  21. /* The splay tree code copied from include/splay-tree.h and adjusted,
  22. so that all the data lives directly in splay_tree_node_s structure
  23. and no extra allocations are needed.
  24. Files including this header should before including it add:
  25. typedef struct splay_tree_node_s *splay_tree_node;
  26. typedef struct splay_tree_s *splay_tree;
  27. typedef struct splay_tree_key_s *splay_tree_key;
  28. define splay_tree_key_s structure, and define
  29. splay_compare inline function. */
  30. /* For an easily readable description of splay-trees, see:
  31. Lewis, Harry R. and Denenberg, Larry. Data Structures and Their
  32. Algorithms. Harper-Collins, Inc. 1991.
  33. The major feature of splay trees is that all basic tree operations
  34. are amortized O(log n) time for a tree with n nodes. */
  35. #ifndef _SPLAY_TREE_H
  36. #define _SPLAY_TREE_H 1
  37. /* The nodes in the splay tree. */
  38. struct splay_tree_node_s {
  39. struct splay_tree_key_s key;
  40. /* The left and right children, respectively. */
  41. splay_tree_node left;
  42. splay_tree_node right;
  43. };
  44. /* The splay tree. */
  45. struct splay_tree_s {
  46. splay_tree_node root;
  47. };
  48. extern splay_tree_key splay_tree_lookup (splay_tree, splay_tree_key);
  49. extern void splay_tree_insert (splay_tree, splay_tree_node);
  50. extern void splay_tree_remove (splay_tree, splay_tree_key);
  51. #endif /* _SPLAY_TREE_H */