Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
»

Mutable_Hash_Map

container.Mutable_Hash_Map

(LM 
type
:
mutate, HK 
type
:
property.hashable, V 
type
)
 ref
:
Mutable_Map HK, V
 is
[Contains abstract features]
[Private constructor]
Mutable_Hash_Map -- a mutable hash map from keys HK to values V

Uses a mutable array internally, when upper_load_factor is reached size is multiplied
by resize_factor (doubled, tripled, etc.) and elements are copied to new array of this size.
If lower_load_factor is reached size is divided by resize_factor.
Insert and retrieve operations on this map are therefore in amortized O(1).

Type Parameters

the mutate effect
type of the keys
type of the values

Functions

create an immutable map from this
 => 
String
[Inherited from  Mutable_Map]
[Contains abstract features]
create a string containing all mappings

redefines:

 => 
Type
[Inherited from  Any]
[Contains abstract features]
Get the dynamic type of this instance. For value instances `x`, this is
equal to `type_of x`, but for `x` with a `ref` type `x.dynamic_type` gives
the actual runtime type, while `type_of x` results in the static
compile-time type.

There is no dynamic type of a type instance since this would result in an
endless hierarchy of types. So for Type values, dynamic_type is redefined
to just return Type.type.
(k container.Mutable_Hash_Map.HK)
 => 
option container.Mutable_Hash_Map.V
[Redefinition of  container.Mutable_Map.get]
[Contains abstract features]
get the value k is mapped to or nil if it does not exist
(k container.Mutable_Map.K, v container.Mutable_Map.V)
 => 
container.Mutable_Map.V
[Inherited from  Mutable_Map]
[Contains abstract features]
get the value stored in this map at key k,
if it does not exist, v is added and returned
(k container.Mutable_Map.K)
 => 
bool
[Inherited from  Mutable_Map]
[Contains abstract features]
check if key k is present in the set of keys
(k container.Mutable_Map.K)
 => 
option container.Mutable_Map.V
[Inherited from  Mutable_Map]
[Contains abstract features]
get the value k is mapped to, or nil if none.
(k container.Mutable_Map.K, v container.Mutable_Map.V)
 => 
unit
[Inherited from  Mutable_Map]
[Contains abstract features]
convenience feature to add a key-value pair to this map
does the same as `put k v`
get a list of all key/value pairs in this map
 => 
Sequence container.Mutable_Map.K
[Inherited from  Mutable_Map]
[Contains abstract features]
get a sequence of all keys in this map
 => 
String
[Inherited from  Any]
[Contains abstract features]
convenience prefix operator to create a string from a value.

This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.
(k container.Mutable_Hash_Map.HK, v container.Mutable_Hash_Map.V)
 => 
unit
[Redefinition of  container.Mutable_Map.put]
[Contains abstract features]
add key-value pair to this map
if key already exists, existing value gets updated
add all key-value pairs to this map

for existing keys, value gets updated
(k container.Mutable_Hash_Map.HK)
 => 
option container.Mutable_Hash_Map.V
[Redefinition of  container.Mutable_Map.remove]
[Contains abstract features]
remove key from map, returns the removed value
 => 
i32
[Redefinition of  container.Mutable_Map.size]
[Contains abstract features]
number of entries in this map
 => 
Sequence container.Mutable_Map.V
[Inherited from  Mutable_Map]
[Contains abstract features]
get a sequence of all values in this map

Type Functions

 => 
String
[Inherited from  Type]
[Contains abstract features]
string representation of this type to be used for debugging.

result has the form "Type of '<name>'", but this might change in the future

redefines:

 => 
Type
[Inherited from  Type]
[Contains abstract features]
There is no dynamic type of a type instance since this would result in an
endless hierarchy of types, so dynamic_type is redefined to just return
Type.type here.

redefines:

create an empty instance of Mutable_Hash_Map
(T 
type
)
 => 
bool
[Inherited from  Type]
[Contains abstract features]
Is this type assignable to a type parameter with constraint `T`?

The result of this is a compile-time constant that can be used to specialize
code for a particular type.

is_of_integer_type(n T : numeric) => T : integer
say (is_of_integer_type 1234) # true
say (is_of_integer_type 3.14) # false

it is most useful in conjunction preconditions or `if` statements as in

pair(a,b T) is
same
pre T : property.equatable
=>
a = b

or

val(n T) is

# check if T is numeric, if so
# return true if n > zero,
# return nil if T is not numeric
#
more_than_zero option bool =>
if T : numeric then
n > T.zero
else
nil
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 => 
String
[Inherited from  Type]
[Contains abstract features]
name of this type, including type parameters, e.g. 'option (list i32)'.
 => 
String
[Inherited from  Type]
[Contains abstract features]
convenience prefix operator to create a string from a value.

This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.

NYI: Redefinition allows the type feature to be distinguished from its normal counterpart, see #3913

redefines:

 => 
Type
[Inherited from  Any]
[Contains abstract features]
Get a type as a value.

This is a feature with the effect equivalent to Fuzion's `expr.type` call tail.
It is recommended to use `expr.type` and not `expr.type_value`.

`type_value` is here to show how this can be implemented and to illustrate the
difference to `dynamic_type`.
0.094dev (2025-06-18 15:08:51 GIT hash 89cffc23ae669b0898a5564fefbf793fcb8e5ca7 built by fridi@fzen)