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