/src/lib/storage/bijective_dictionary/bijective_dictionary_reverser.e

http://github.com/tybor/Liberty · Specman e · 161 lines · 111 code · 26 blank · 24 comment · 3 complexity · 124735ba7ee5435b08f7d35a867a11b1 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class BIJECTIVE_DICTIONARY_REVERSER[V_, K_]
  5. -- Allows to view a BIJECTIVE_DICTIONARY[V_, K_] as a BIJECTIVE_DICTIONARY[K_, V_]
  6. inherit
  7. BIJECTIVE_DICTIONARY[V_, K_]
  8. create {ANY}
  9. from_bijective_dictionary
  10. feature {ANY}
  11. from_bijective_dictionary (bijective_dictionary_: like bijective_dictionary)
  12. do
  13. bijective_dictionary := bijective_dictionary_
  14. end
  15. count: INTEGER
  16. do
  17. Result := bijective_dictionary.count
  18. end
  19. has (k: K_): BOOLEAN
  20. do
  21. Result := bijective_dictionary.has_value(k)
  22. end
  23. at (k: K_): V_
  24. do
  25. Result := bijective_dictionary.key_at(k)
  26. end
  27. reference_at (k: K_): V_
  28. do
  29. if has(k) then
  30. Result := at(k)
  31. end
  32. end
  33. fast_has (k: K_): BOOLEAN
  34. do
  35. Result := bijective_dictionary.fast_has_value(k)
  36. end
  37. fast_at (k: K_): V_
  38. do
  39. Result := bijective_dictionary.fast_key_at(k)
  40. end
  41. fast_reference_at (k: K_): V_
  42. do
  43. if fast_has(k) then
  44. Result := fast_at(k)
  45. end
  46. end
  47. has_value (v: V_): BOOLEAN
  48. do
  49. Result := bijective_dictionary.has(v)
  50. end
  51. key_at (v: V_): K_
  52. do
  53. Result := bijective_dictionary.at(v)
  54. end
  55. fast_has_value (v: V_): BOOLEAN
  56. do
  57. Result := bijective_dictionary.fast_has(v)
  58. end
  59. fast_key_at (v: V_): K_
  60. do
  61. Result := bijective_dictionary.fast_at(v)
  62. end
  63. put (v: V_; k: K_)
  64. do
  65. remove(k)
  66. add(v, k)
  67. end
  68. add (v: V_; k: K_)
  69. do
  70. bijective_dictionary.add(k, v)
  71. next_generation
  72. end
  73. remove (k: K_)
  74. local
  75. v: V_
  76. do
  77. if has(k) then
  78. v := at(k)
  79. bijective_dictionary.remove(v)
  80. end
  81. next_generation
  82. end
  83. clear_count
  84. do
  85. bijective_dictionary.clear_count
  86. next_generation
  87. end
  88. clear_count_and_capacity
  89. do
  90. bijective_dictionary.clear_count_and_capacity
  91. next_generation
  92. end
  93. capacity: INTEGER
  94. do
  95. Result := bijective_dictionary.capacity
  96. end
  97. item (index: INTEGER): V_
  98. do
  99. Result := bijective_dictionary.key(index)
  100. end
  101. key (index: INTEGER): K_
  102. do
  103. Result := bijective_dictionary.item(index)
  104. end
  105. copy (other: like Current)
  106. do
  107. bijective_dictionary := other.bijective_dictionary
  108. end
  109. internal_key (k: K_): K_
  110. do
  111. Result := key_at(at(k))
  112. end
  113. feature {BIJECTIVE_DICTIONARY}
  114. bijective_dictionary: BIJECTIVE_DICTIONARY[K_, V_]
  115. end -- class BIJECTIVE_DICTIONARY_REVERSER
  116. --
  117. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  118. --
  119. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  120. -- of this software and associated documentation files (the "Software"), to deal
  121. -- in the Software without restriction, including without limitation the rights
  122. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  123. -- copies of the Software, and to permit persons to whom the Software is
  124. -- furnished to do so, subject to the following conditions:
  125. --
  126. -- The above copyright notice and this permission notice shall be included in
  127. -- all copies or substantial portions of the Software.
  128. --
  129. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  130. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  131. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  132. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  133. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  134. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  135. -- THE SOFTWARE.