If one wishes to compare the objects by another criterion, then a comparison function can be declared when the Map is created. Lacking such a function, the program should not run. If a comparison function is declared when the Map is created, then that comparison function will be used instead. Swarm includes some built-in comparison functions, but, as we will see, the usage of customized functions is quite easy and convenient. Classes from which key objects are created can, of course, create more informative comparison methods.
Lets begin with the problem of using integers as keys.
The typecasting approach is used in many Swarm applications. The essence of this approach is to use type casting to trick the Swarm library to make it treat an integer as if it were an object. Without going too deeply into the computer science of the issue, it may not be possible to explain this, but we will take a stab at it. On many computer systems, a pointer uses the same amount of space as an integer. Instead of inserting objects into a Map with objects as keys, using this casting trick, one can insert objects at integer values that are cast as objects of type id .