uses Collection.makeHashMap,
     Collection.makeStringHasher,
     Collection.makeStringEquator,
     Collection.Map,
     Collection.Collection,
     Collection.Set,
     Collection.Iterator,
     Collection.MapEntry,
     Collection.Hasher,
     Collection.Equator,
     io.print,
     conv.itos

main(args: array[string]): int = (
	m: Map;

	m = makeHashMap(makeStringHasher(), makeStringEquator(),
					    makeStringEquator());
	testMap(m);

	0
)

SIZE = 10000

testMap(m: Map) = (
	x: string;
	xx: object;

	i: int = 0;

	while (i < SIZE) (
		k: string = itos(i);
		v: string = itos(i+1);
		m.put(k, v);
		i++
	);

/*
	printMap(m);

*/
	xx = m.get("121");
	x = cast(xx, string);

	if (xx)
	    print("oops: get failed (null)\N")
	else if (x != "122")
	    print("oops: get failed\N")
	else
	    print("ok: get successful\N");

	size: int = m.size();

	// Re-map a key.
	m.put("0", "0");

/*
	printMap(m);
*/

	xx = m.get("0");
	x = cast(xx, string);

	if (xx)
	    print("oops: get failed (null)\N")
	else if (x != "0")
	    print("oops: get failed\N")
	else
	    print("ok: get successful\N");

	if (m.size() == size)
	    print("ok: put idempotent\N")
	else
	    print("oops: put not idempotent\N");

	i = 1;

	while (i < SIZE) (
		k: string = itos(i);
		m.remove(k);
		i++
	);

	if (m.size() == 1)
	    print("ok: remove successful\N")
	else
	    print("oops: remove failed\N");

/*
	printMap(m);

	printCollection(m.keys());
*/
)

printCollection(c: Collection) = (
	i: Iterator;
	a: string;
	n: int = 0;

	i = c.iterator();

	while (i.hasNext()) (
		a = cast(i.next(), string);
 
		if (n > 64) (
			print("\N");
			n = 0
		);

		print(a);
		n = n + length(a) + 1;

		if (i.hasNext()) print(" ") else print("\N")
	)
)

printMap(m: Map) = (
	i: Iterator;
	e: MapEntry;
	a: string;
	b: string;
	n: int = 0;

	i = m.entries().iterator();

	while (i.hasNext()) (
		e = cast(i.next(), MapEntry);
		a = cast(e.key(), string);
		b = cast(e.value(), string);

		if (n > 64) (
			print("\N");
			n = 0
		);

		print("[" + a + " => " + b + "]");
		n = n + length(a) + length(b) + 7;

		if (i.hasNext()) print(" ") else print("\N")
	)
)
