Class Sets in need of examples

Monkey Forums/Monkey Programming/Class Sets in need of examples

darky000(Posted 2013) [#1]
Hello,

Can someone explain and give a code sample on how to implement a Set? There is no sample code in the documentation for me to follow.


Gerry Quinn(Posted 2013) [#2]
Oddly enough I spent a while today wrestling with it, and I think I have it.

Unless I am mistaken, you have to make a special class extending Set if you want to use it with your own objects. There is an extra complication because Sets are based on Maps, and it has to be done for them too.

So suppose I want to make a set of Points. The code would be like this:



Output is 2,3,4, because (2,2),(3,3) and (4,4) are in the block of points I placed in the set.


Gerry Quinn(Posted 2013) [#3]
I should note that while the Map documentation calls for -1, 0 and 1 as return values from Compare(), I think any negative or positive values will work instead of -1 and 1. Can this be confirmed?