/src/lib/storage/dictionary/ext_hashed_dictionary.e

http://github.com/tybor/Liberty · Specman e · 78 lines · 42 code · 8 blank · 28 comment · 0 complexity · a26d6f298ddbb2ff60c976f58e0ddc21 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_DICTIONARY[V_, K_]
  5. --
  6. -- Associative memory. Values of type `V_' are stored using Keys of type `K_'.
  7. --
  8. -- Efficient implementation of DICTIONARY using a hash_coder function on keys.
  9. --
  10. inherit
  11. ABSTRACT_HASHED_DICTIONARY[V_, K_]
  12. rename
  13. make as abs_make
  14. with_capacity as abs_with_capacity
  15. end
  16. create {ANY}
  17. make, with_capacity
  18. feature {ANY}
  19. hash_coder: FUNCTION[TUPLE[K_], INTEGER]
  20. feature {}
  21. hash_code (k: K_): INTEGER
  22. do
  23. Result := hash_coder.item([k])
  24. end
  25. feature {ANY}
  26. make (a_hash_coder: like hash_coder)
  27. require
  28. a_hash_coder /= Void
  29. do
  30. hash_coder := a_hash_coder
  31. abs_make
  32. ensure
  33. is_empty
  34. hash_coder = a_hash_coder
  35. end
  36. with_capacity (a_hash_coder: like hash_coder; medium_size: INTEGER)
  37. require
  38. a_hash_coder /= Void
  39. medium_size > 0
  40. do
  41. hash_coder := a_hash_coder
  42. abs_with_capacity(medium_size)
  43. ensure
  44. is_empty
  45. hash_coder = a_hash_coder
  46. capacity >= medium_size
  47. end
  48. invariant
  49. hash_coder /= Void
  50. end -- class EXT_HASHED_DICTIONARY
  51. --
  52. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  53. --
  54. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  55. -- of this software and associated documentation files (the "Software"), to deal
  56. -- in the Software without restriction, including without limitation the rights
  57. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  58. -- copies of the Software, and to permit persons to whom the Software is
  59. -- furnished to do so, subject to the following conditions:
  60. --
  61. -- The above copyright notice and this permission notice shall be included in
  62. -- all copies or substantial portions of the Software.
  63. --
  64. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  65. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  66. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  67. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  68. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  69. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  70. -- THE SOFTWARE.