Write operation in Hashmap
API call à hashmap.put(KEY,VALUE);
1. When
you call this function, KEY (object) hashcode function gets called.
2. return value of the hashcode() is integer.
3.
This value is divided by max_bucket value
4.
key,value and hashcode are stored respective buckets new entry
NOTE : So far, we haven’t discussed about the equals
function.
Read opearion in Hashmap
API call à
hashmap.get(KEY);
1. When
you call this function, KEY (object) hashcode function gets called.
2. return value of the hashcode() is integer.
3. from the
hashcode, it finds the bucket and traverse to the list to find the hashcode
4. Once it
matches with hashcode, it checks with object equality using equals() method
defined in KEY class ( from this point, you can infer another point.
a) if objects
are equal, then hashcode must be same. So that it fall in same bucket
b) if
hashcode is same, it doesn’t mean that objects are equals )
No comments:
Post a Comment