Skip to content

Hash Map Rules

Structure

Structure(HashMapC) HashMapC(Structure(VectorC) keyVector, Structure(VectorC) valueVector)

Builds a hash map of Categorical values indexed by Categorical keys. The operands must come from VectorC rules of the same size, with unique keys in the keyVector. Both vectors in the operands must contain only literal values (no variables or rules).

TableHashMapC

Structure(HashMapC) TableHashMapC(Table table, Categorical key, Categorical value)

Builds a hash map of Categorical values from keys and values in a table. In case of duplicate keys in the table, only the first matching value is kept. Both vectors in the operands must contain only literal values (no variables or rules).

ValueAtKeyC

Categorical ValueAtKeyC(Structure(HashMapC) hashMap, Categorical key)

Returns a value of a categorical hash map at given key. Returns "" if not found. It allows to efficiently recode a Categorical value into another Categorical value.

Example

Dictionary Person
{
  Categorical Name;
  Categorical Sex;
  // Maps "male" -> "Mr" and "female" -> "Mrs"
  Categorical Gender =
    ValueAtKeyC(HashMapC(VectorC("male", "female"), VectorC("Mr", "Mrs")), Sex);
}

HashMap

Structure(HashMap) HashMap(Structure(VectorC) keyVector, Structure(Vector) valueVector)

Builds a hash map of numerical values indexed by keys. The operands must be the result of VectorC and Vector rules of the same size, with unique keys in the vector of keys.

TableHashMap

Structure(HashMap) TableHashMap(Table table, Categorical key, Numerical value)

Builds a hash map of Numerical values from keys and values in a table. In case of duplicate keys in the table, only the first matching value is kept.

ValueAtKey

Numerical ValueAtKey(Structure(HashMap) hashMap, Categorical key)

Returns a value of a numerical hash map at given key. Returns missing value is not found. It allows to efficiently recode a Categorical value into a Numerical one.

Example

Dictionary Person
{
  Categorical Name;
  Categorical Sex;
  // Maps "male" -> 0 and "female" -> 1
  Numerical NumericGender = ValueAtKey(HashMap(VectorC("male", "female"), VectorC(0, 1)), Sex);
}