/src/lib/storage/set/ext_hash_set.e

http://github.com/tybor/Liberty · Specman e · 84 lines · 49 code · 9 blank · 26 comment · 0 complexity · 2b7a9afd6293b2f9760b38501b594596 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class EXT_HASHED_SET[E_]
  5. --
  6. -- Like a HASH_SET but the items' hash_code function is given
  7. --
  8. inherit
  9. ABSTRACT_HASHED_SET[E_]
  10. rename
  11. make as abs_make,
  12. with_capacity as abs_with_capacity
  13. from_collection as abs_from_collection
  14. end
  15. creation {ANY}
  16. make, with_capacity, from_collection
  17. feature {ANY}
  18. hash_coder: FUNCTION[TUPLE[E_], INTEGER]
  19. make (a_hash_coder: like hash_coder) is
  20. require
  21. a_hash_coder /= Void
  22. do
  23. hash_coder := a_hash_coder
  24. abs_make
  25. ensure
  26. hash_coder = a_hash_coder
  27. end
  28. with_capacity (a_hash_coder: like hash_coder; medium_size: INTEGER) is
  29. require
  30. a_hash_coder /= Void
  31. medium_size > 0
  32. do
  33. hash_coder := a_hash_coder
  34. abs_with_capacity(medium_size)
  35. ensure
  36. hash_coder = a_hash_coder
  37. end
  38. from_collection (a_hash_coder: like hash_coder; model: COLLECTION[like item]) is
  39. require
  40. a_hash_coder /= Void
  41. model /= Void
  42. do
  43. hash_coder := a_hash_coder
  44. abs_from_collection(model)
  45. ensure
  46. hash_coder = a_hash_coder
  47. end
  48. feature {}
  49. hash_code (e: E_): INTEGER is
  50. do
  51. Result := hash_coder.item([e])
  52. end
  53. invariant
  54. hash_coder /= Void
  55. end -- class EXT_HASHED_SET
  56. --
  57. -- Copyright (c) 2009 by all the people cited in the AUTHORS file.
  58. --
  59. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  60. -- of this software and associated documentation files (the "Software"), to deal
  61. -- in the Software without restriction, including without limitation the rights
  62. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  63. -- copies of the Software, and to permit persons to whom the Software is
  64. -- furnished to do so, subject to the following conditions:
  65. --
  66. -- The above copyright notice and this permission notice shall be included in
  67. -- all copies or substantial portions of the Software.
  68. --
  69. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  70. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  71. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  72. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  73. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  74. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  75. -- THE SOFTWARE.