Is there any datatype /container in any language which checks for the uniqueness of the content than the value or index before inserting the item?
A:
The problem with that is that the value can be ANYTHING so that's very open ended and not always pratical.
Lloyd
2009-06-29 10:54:41
Indeed. The most typical implementation is a "hash set", which checks for uniqueness by computing the hash value of each object.
Noldorin
2009-06-29 10:57:05
to answer 2nd part of your question, "hash set" also index the items on the hash value of objects.
Ratnesh Maurya
2009-06-29 11:00:16
Not only the hash because that's just a necessary, not a sufficient condition. You still have to check for equality where the hash is the same.
Joey
2009-06-29 11:03:13
A:
SQL with a UNIQUE field. sets in Python. Filenames on Filesystems. Depends on how you define "content".
balpha
2009-06-29 10:55:15
+2
A:
Sure, one that comes to mind is Cocoa's NSSet class. The C++ STL also has a set class.
Of course, you need some way to define a unique object beyond simple pointer or reference comparison. For instance, in Cocoa, two objects are considered the same for the purpose of NSSet if they respond to isEqual:
with YES
and have the same hash code.
Gregory Higley
2009-06-29 10:55:38