1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Advanced services for serialization engines
20 # Maps instances to a value, uses `is_same_instance`
22 # Warning: This class does not implement all the services from `Map`.
23 class StrictHashMap[K
, V
]
27 var map
= new HashMap[K
, Array[Couple[K
, V
]]]
31 redef fun is_empty
do return length
== 0
34 fun node_at
(key
: K
): nullable Couple[K
, V
]
36 if not map
.keys
.has
(key
) then return null
40 if couple
.first
.is_same_serialized
(key
) then
50 var node
= node_at
(key
)
55 redef fun []=(key
, value
)
57 var node
= node_at
(key
)
64 if not map
.keys
.has
(key
) then
65 arr
= new Array[Couple[K
, V
]]
69 arr
.add
new Couple[K
, V
](key
, value
)
73 redef fun has_key
(key
) do return node_at
(key
) != null