[package] [Java implementation] [Execution output]


HashMap


import java.util.function.Function;

import church.lang.Array;

import church.util.Entry;
import church.util.HashTable;
import church.util.CollectionsSupport;
import church.util.LinkedList;

class HashMap<K, V>: hashMap1(HashTable<Entry<K, V>, K>: hashTable); // todo need a different name from below :(

map elements = hashMap1(HashTable.hashTable4(Entry: entry −> entry.key, ==, hashCode, elements));

empty_set = map([]);

// size HashMap: map = map.hashTable.size; // equivalent to the 'OO' style below
(HashMap: map).size = map.hashTable.size; // the parentheses are optional

(HashMap: map).get2(key, defaultFactory) = CollectionsSupport.get0(map.hashTable, key, defaultFactory);

(HashMap: map).get(key) = CollectionsSupport.getOrFail(map.hashTable, key); // all the parentheses are optional

(HashMap: map).contains(key) = map.hashTable.contains(key);

leftFold  = CollectionsSupport.leftLift (HashTable.leftFold,  HashMap: m −> m.hashTable);
rightFold = CollectionsSupport.rightLift(HashTable.rightFold, HashMap: m −> m.hashTable);

outEntry(stream, entry(key, value)) = stream << key << " -> " << value;

stream << hashMap = CollectionsSupport.encode3(stream, leftFold, hashMap, outEntry);