But what good is this, really? Does find really return to the caller what the caller already has? ...well, there are two uses of a USet: (1) as an oracle to answer whether a known item has the property the set represents, and (2) as a map (an association). In the map case we use the definition of == on type T to capture a useful notion of ``equivalent".
class record
{ public:
string name;
int phone;
record(string n, int p): name(n), phone(p) {}
};
///// support for USet implementations on T = record /////
// Tell USet the meaning of 'equal' for records.
bool operator==(record a, record b) { return a.name == b.name; }
//////////////////////////////////////////////////////////
// usage examples //
record dummy("null", 0);
// establish USet H, designate dummy as "null".
USetImplementation<record> H(dummy);
H.size(); // returns 0.
record me("saunders", 8316238);
record pres("obama", 1234567);
record vp("biden", 7654321);
H.add(me); // returns true.
H.add(pres); // returns true.
H.size(); // returns 2.
record me2("saunders", 0);
H.add(me2); // returns false.
// record with name "saunders" is already in.
H.size(); // returns 2.
H.remove(vp); // returns dummy record
H.size(); // returns 2.
record rec;
rec = H.find(me2); // returns me.
// IMPORTANT: phone # is now available in rec.
H.find(vp); // returns dummy
H.size(); // returns 2.
H.remove(me2); // returns me.
// Note that caller did not know me fully.
H.size(); // returns 1.