Here is the definition of our EmployeeMap once more:
EmployeeMap allows to better declare our intention in the code but as far as the Ice run-time is concerned using
Map will be equally fine, the same goes for TypeScript using
EmployeeMap is convenient but as far as the compiler is concerned using a type that implements
Map<number, Employee> will be fine
Ice.HashMap. This is true for Slice dictionaries where the key type is
long or a Slice structure that qualifies as a legal dictionary key:
In these cases an extra constructor is generated that initializes the
Ice.HashMap with the desired comparison operator.
This version of the constructor accepts optional comparator functions that the map uses to compare keys and values for equality. If you instantiate a map directly using
new Ice.HashMap()without specifying comparator functions, the default comparators use the
===operator to compare keys and values. As an example, the following map compares its keys and values using
valueComparatorfunction is only used when comparing two maps for equality.
The type-specific constructor generated for a Slice dictionary supplies comparator functions appropriate for its key and value types.
Returns true if this map compares equal to the given map, false otherwise. You can optionally supply a function for
valueComparatorthat the map uses when comparing values; this function takes precedence over the comparator supplied to the map's constructor.
Returns a shallow copy of the map.
Legal key types for Ice.
NaN, and any object that defines a
hashCode method. The generated code for a Slice structure that qualifies as a legal dictionary key type includes a
hashCode method. Suppose we define another dictionary type:
The Slice compiler generates a constructor function equivalent to the following code:
Since the key is a user-defined structure type, the map requires a comparator that properly compares keys. Instantiating a map using
new EmployeeDeptMap automatically sets the comparators, whereas calling
new Ice.HashMap in this case would require you to supply your own comparators.
Slice dictionaries that map to a HashMap must be instantiated using the generated constructor.
- Attempting to use the
map[key] = valuesyntax to add an element to the map will not have the desired effect; you must use the