Dict
From CometPublic
Comet contains a Dictionary data structure where keys can be associated with values. A Dictionary is declared as follows:
dict{int->string} myDict();
dict{int->string} myDict = new dict{int->string}(); // alternative declaration useful when using objects
The format types of the keys and values are declared when creating a dictionary
dict{int->string} myDict(); // ints as keys to string values
dict{bool->int} myDict(); // bools as keys to int values
Once a dictionary has been created storing values is done using the syntax
myDict{1} = "Hello, World";
Retrieving data from a dictionary is also easy
string s = myDict{1};
You can access a set of all the keys in the dictionary using
myDict.getKeys();
Iterate over all elements in a dict:
forall(k in myDict.getKeys()) { /* do something with k or myDict{k} */ }
You check if the dictionary has a key with
myDict.hasKey(1);
If you wish to remove an element from a dictionary you can
myDict.remove(1);
Currently, as of version 0.07, dictionaries can use ints, bools, tuples and Objects as keys but they cannot use strings. Apparently strings are not part of the Object class heirarchy however you can work around this by wrapping the string you wish to use as a key within a tuple.
tuple Key { string id; }
dict{Key->int} myDict();
myDict{new Key("test")} = 10;
cout << myDict{new Key("test")} << endl;
This is also usually true for values as well, if you find a datatype that you wish to store within a dictionary or use as its key which isn't currently supported you can often wrap it in a tuple since the support for tuples is fairly well developed.
For an example of dictionaries being used check out the brief section on page 68 of the Constraint-Based Local Search book or probably more useful is the implementation of the Meet Invariant for the Social Golfers problem described here
A word of warning, although dictionaries are a handy feature of the Comet language they are not intended for use directly in invariants such as sum. This may be added in future versions.

