使用浮点数/双精度数的哈希表/字典 [英] Hashtables/Dictionaries that use floats/doubles

查看:86
本文介绍了使用浮点数/双精度数的哈希表/字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某处读到了其他类似于散列表,字典的数据结构,但是它们没有使用整数,而是使用了浮点数/双精度数,等等.

I read somewhere about other data structures similar to hashtables, dictionaries but instead of using ints, they were using floats/doubles, etc.

有人知道他们是什么吗?

Anyone knows what they are?

推荐答案

如果您的意思是将浮点数/双精度数用作哈希中的键,那很容易.例如,在.NET中,它仅使用 Dictionary< double,MyValueType> .

If you mean using floats/doubles as keys in your hash, that's easy. For example, in .NET, it's just using Dictionary<double,MyValueType>.

如果您正在谈论让哈希值基于double而不是int....

If you're talking about having the hash be based off a double instead of an int....

从技术上讲,您可以将任何元素用作内部哈希.通常,这是使用int或long来完成的,因为它们速度很快,并且哈希算法易于计算.

Technically, you can have any element as your internal hash. Normally, this is done using an int or long, since these are fast, and the hashing algorithm is easy to compute.

但是,哈希实际上只是一个BitArray,因此任何东西都可以使用.除了可能会允许使用更大的哈希值集(即:如果您使用8字节或更大的哈希类型)以外,将其设置为int或long确实没有太多优势.

However, the hash is really just a BitArray at heart, so anything would work. There really isn't much advantage to making this something other than an int or long, other than potentially allowing a larger set of hash values (ie: if you go to an 8 byte or larger type for your hash).

这篇关于使用浮点数/双精度数的哈希表/字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆