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