Alex Rivera | Logout

Why does HashSet have "Hash" in its name?

Asked 2010-11-03T01:48:13.467
9

Why is Hashset called a "Hash"-set?

I understand we call hashtable or a hashmap since it's a key value store and when we put(), then the key is hashed and distributed evenly using a good hash function.

I assume its called a HashSet because when we add(), the value is hashed and stored to keep it unique. But why the overkill? We don't really care about "equal distribution" of data like we do in a Hash table.

Edit
Report

1 Answer

13

We do care about equal distribution because we want constant time performance on our basic Collection operations. In order to respect the basic rules of a SET, no two objects are equal, we want to find a potentially equal match quickly. HashSet is one fairly good way of doing it. Compare to a theoretical ArraySet where adding a new element is a linear time operation to iterate and check every single existing entry for equality.

answered 2010-11-03T01:53:19.380

Your Answer