/src/lib/storage/set/abstract_avl_set.e

http://github.com/tybor/Liberty · Specman e · 120 lines · 83 code · 14 blank · 23 comment · 4 complexity · 2966ef3021f4afcc0c1efa1e52bcb975 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. deferred class ABSTRACT_AVL_SET[E_]
  5. inherit
  6. SET[E_]
  7. redefine new_iterator
  8. end
  9. insert
  10. AVL_TREE[E_]
  11. rename
  12. set_value_and_key as set_item
  13. export
  14. {ITERATOR_ON_AVL_SET} root
  15. end
  16. feature {ANY}
  17. new_iterator: ITERATOR[E_]
  18. do
  19. create {ITERATOR_ON_AVL_SET[E_]} Result.make(Current)
  20. end
  21. add (e: like item)
  22. do
  23. item_memory := e
  24. root := do_insert(root)
  25. next_generation
  26. end
  27. fast_add (e: like item)
  28. do
  29. item_memory := e
  30. root := fast_do_insert(root)
  31. next_generation
  32. end
  33. clear_count, clear_count_and_capacity
  34. do
  35. if not is_empty then
  36. clear_nodes(root)
  37. root := Void
  38. count := 0
  39. map_dirty := True
  40. end
  41. next_generation
  42. end
  43. reference_at (e: like item): like item
  44. local
  45. n: ABSTRACT_AVL_SET_NODE[E_]
  46. do
  47. if root /= Void then
  48. n := root.at(e)
  49. if n /= Void then
  50. Result := n.item
  51. end
  52. end
  53. end
  54. item (index: INTEGER): E_
  55. do
  56. if map_dirty then
  57. build_map
  58. end
  59. Result := map.item(index - 1).item
  60. end
  61. feature {}
  62. set_item (n: like a_new_node)
  63. do
  64. n.set(item_memory)
  65. end
  66. set_value (n: like a_new_node)
  67. do
  68. end
  69. a_new_node: ABSTRACT_AVL_SET_NODE[E_]
  70. deferred
  71. end
  72. exchange_and_discard (n1, n2: like a_new_node)
  73. do
  74. map_dirty := True
  75. n1.set_item(n2.item)
  76. rebalance := True
  77. count := count - 1
  78. discard_node(n2)
  79. end
  80. feature {}
  81. make
  82. do
  83. create map.make(0)
  84. next_generation
  85. end
  86. end -- class ABSTRACT_AVL_SET
  87. --
  88. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  89. --
  90. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  91. -- of this software and associated documentation files (the "Software"), to deal
  92. -- in the Software without restriction, including without limitation the rights
  93. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  94. -- copies of the Software, and to permit persons to whom the Software is
  95. -- furnished to do so, subject to the following conditions:
  96. --
  97. -- The above copyright notice and this permission notice shall be included in
  98. -- all copies or substantial portions of the Software.
  99. --
  100. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  101. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  102. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  103. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  104. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  105. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  106. -- THE SOFTWARE.