最好的收集与型双为重点使用

最好的收集与型双为重点使用

本文介绍了最好的收集与型双为重点使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的对象:

Public Cactus{
    Public Double key;
    Public String value;
}



我有大约〜100 仙人掌,而这一切都有一个唯一的密钥,并且具有一定的重复值。
我不过需要检索值关于〜2000倍液键。
我的值-10和280之间变化。

I have about ~100 Cactus, which all have a unique key, and a value that has some duplicates.I will however have to retrieve the value for a key about ~2000 times.My Key values varies between -10 and 280.

我想这个过程是一样快越好。什么是我们的最佳方法呢?我是用思考了的HashTable ,虽然我总是用一个用整数,而不是双击,出于某种原因,我很担心,它不是用好的做法双击

I want this process to be as quick as possible. What would be the best approach for this? I was thinking using a HashTable, although I always used one with Integer and not Double, and for some reason I am worried that it's not good practice to use Double as Key.

由于我的情况下,该集将是最好用?

Given my scenario, which collection would be the best to use?

推荐答案

使用双象在字典中的关键通常是一个非常糟糕的主意。你会遇到各种与在那里你认为你存储在字典0.1表示错误的问题,但事实上你存储的东西非常接近,但并不完全等于0.1。

Using a double as a key in a dictionary is generally a really bad idea. You will run into all sorts of problems with representation errors where you think you stored 0.1 in the dictionary but actually you stored something very close to but not quite equal to 0.1.

我建议使用另一种类型(字符串?)如果你需要完全匹配。

I'd suggest using another type (string?) if you need exact matches.

如果你不想完全匹配,但只找到最接近的值,可以考虑像一个排序列表来代替。

If you don't want exact matches but just finding the closest value, consider something like a SortedList instead.

这篇关于最好的收集与型双为重点使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:38