/src/lib/storage/dictionary/hashed_dictionary.e

http://github.com/tybor/Liberty · Specman e · 69 lines · 31 code · 6 blank · 32 comment · 0 complexity · fe2c0ede331616d934ca610e5013786e MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class HASHED_DICTIONARY[V_, K_ -> HASHABLE]
  5. --
  6. -- Associative memory. Values of type `V_' are stored using Keys of type `K_'.
  7. --
  8. -- Efficient implementation of DICTIONARY using `hash_code' on keys.
  9. --
  10. inherit
  11. ABSTRACT_HASHED_DICTIONARY[V_, K_]
  12. create {ANY}
  13. make, with_capacity, manifest_creation, default_create
  14. create {ABSTRACT_HASHED_DICTIONARY}
  15. special_common_dictionary
  16. feature {}
  17. hash_code (k: K_): INTEGER
  18. do
  19. Result := k.hash_code
  20. end
  21. special_common_dictionary (fn: like free_nodes)
  22. -- Used to avoid having a recursive once function while initializing `common_free_nodes'.
  23. require
  24. fn /= Void
  25. -- common_free_nodes = Void
  26. -- {V_} ?:= free_nodes
  27. -- {K_} ?:= generating_type
  28. local
  29. new_capacity: INTEGER
  30. do
  31. new_capacity := Default_size
  32. buckets := buckets.calloc(new_capacity)
  33. capacity := new_capacity
  34. cache_user := -1
  35. count := 0
  36. free_nodes := fn
  37. debug
  38. create nodes_list.with_capacity(new_capacity)
  39. end
  40. ensure
  41. count = 0
  42. end
  43. end -- class HASHED_DICTIONARY
  44. --
  45. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  46. --
  47. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  48. -- of this software and associated documentation files (the "Software"), to deal
  49. -- in the Software without restriction, including without limitation the rights
  50. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  51. -- copies of the Software, and to permit persons to whom the Software is
  52. -- furnished to do so, subject to the following conditions:
  53. --
  54. -- The above copyright notice and this permission notice shall be included in
  55. -- all copies or substantial portions of the Software.
  56. --
  57. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  58. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  59. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  60. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  61. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  62. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  63. -- THE SOFTWARE.