PageRenderTime 25ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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