Lists/Maps/Sets (Was Re: The story of E, part 2 (fwd))

Tyler Close tyler@lfw.org
Wed, 14 Oct 1998 20:48:36 -0400


I'd like to add my two cents here.

First, I think sets are best implemented as maps where the keys and values
are identical, not as maps from keys to null. Consider the following:

if(v["a"] == null) 
{
	# "a" is not in the set
} 
else 
{
	# "a" is in the set.
}

This is also the system used by the C++ STL.

Following this logic, here are my syntax reccommendations:
{ 'a', 'b', 'c' }		# tranditional syntax for arrays
[ 'a', 'b', 'c' ]	 	# set sytax expands to below
[ 'a' => 'a', 'b' => 'b', 'c' => 'c' ]	# map syntax of a hashtable map.

This means that [] is an empty map.

Using this syntax, here's your example:
if(["windows", "win95", "winnt"] search(platform) == null)
{
	# thumb your nose.
}

The search method returns the value stored with the given key, else null.

Forget all this containsKey nonsense. Don't steal design flaws from Java.

As for the implementation classes:
>>             |   Keyed          	Indexed
>>  -----------+------------------------------
>>   immutable |   FinalHashtable     	FinalVector
>>             |
>>    mutable  |   Hashtable       	Vector
>>