Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any thing hashmap can do but map cannot?

I only know that the difference between hashmap and map is that hashmap is implemented with hash function but map is implemented with tree. Could any body add anything more?

Based on this, is there any thing hashmap can do but map cannot?

like image 231
skydoor Avatar asked Mar 30 '10 00:03

skydoor


People also ask

Why is hash better than a map?

In contrast to Map, HashMap can hold duplicate values. It's possible to implement the Map interface by utilizing its implementing classes. Hashmap is all about implementing the Map Interface. The map does not allow storage of a single null key whereas HashMap can store multiple null values along with a single null key.

What are Hashmaps good for?

Hashmaps are probably the most commonly used implementation of the concept of a map. They allow arbitrary objects to be associated with other arbitrary objects. This can be very useful for doing things like grouping or joining data together by some common attribute.

Does HashMap guarantee default ordering?

HashMap is unordered; you can't and shouldn't assume anything beyond that. This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.

Is a HashMap the same as an object?

JavaScript Objects: Similar but Different The key in a hashmap can be any datatype, this includes arrays and objects. Meanwhile, objects can only use integers, strings, and symbols as their keys. Hashmaps are organized as linked lists, so the order of its elements is maintained, which allows the hashmap to be iterable.


1 Answers

  • Hashmaps have average case better performance for access (O(1)), but worse worst case performance (O(n)). Maps are always O(lg(n)).

  • Maps are ordered by their key, hashmaps are not.

  • Hashmaps generally use more memory than maps.

  • Maps typically allow for faster iteration.

  • Good hash functions are harder to write than good ordering functions (and more difficult to analyse).

I don't believe there's anything that a hashmap can do that a map can't.

like image 186
Peter Alexander Avatar answered Sep 27 '22 00:09

Peter Alexander