Java - How to find a value from a hashmap that is the closest to a particular number?

后端 未结 4 1638
北荒
北荒 2021-01-14 07:44

Hi I have a HashMap and also a function which returns a double value known as answer. I want to check which value in the Hash

4条回答
  •  旧巷少年郎
    2021-01-14 08:11

    The concept of 'closest' is not really meaningful for Hashed data structures. The primary goal of efficient hashing algorithms is collision avoidance, which is directly contrary to closeness. Either you have a collision, or not.

    If you were asking this for an ordered key data structure (eg. TreeMap), the answer would be different.

提交回复
热议问题