tags:

views:

45

answers:

4

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
+5  A: 

Yes, it's called a set. Most languages implement them in some form.

anon
Indeed. The most typical implementation is a "hash set", which checks for uniqueness by computing the hash value of each object.
Noldorin
to answer 2nd part of your question, "hash set" also index the items on the hash value of objects.
Ratnesh Maurya
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
A: 

SQL with a UNIQUE field. sets in Python. Filenames on Filesystems. Depends on how you define "content".

balpha
+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