specific behavior when there is no value associated with a key.
The default behavior is to abort, as usual.
Basically this patch factorizes the `abort` in a single function that can
be redefined.
Signed-off-by: Jean Privat <jean@pryen.org>
# Number of items in the collection.
fun length: Int is abstract
+
+ # Called by the underling implementation of `[]` to provide a default value when a `key` has no value
+ # By default the behavior is to abort.
+ #
+ # Note: the value is returned *as is*, implementations may want to store the value in the map before returning it
+ # @toimplement
+ protected fun provide_default_value(key: K): E do abort
end
# Maps are associative collections: `key` -> `item`.
do
var c = couple_at(key)
if c == null then
- abort
+ return provide_default_value(key)
else
return c.second
end
if i >= 0 then
return _items[i].second
else
- abort
+ return provide_default_value(key)
end
end
do
var c = node_at(key)
if c == null then
- abort
+ return provide_default_value(key)
else
return c._value
end