问题标签 [hash-function]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - Hashtable,Hashfunction:Value,Key,Hashvalue之间的区别?
让我们假设我们有想要放入 Hashtable 的数据。哈希函数为每个数据对象计算一个哈希值,并将这个哈希值放入一个表中(每个值都应该有自己的桶)。通过哈希值,我们可以知道数据对象在表中的确切位置。
钥匙在这里起什么作用?Java 中的 HashMap 需要为我们放入 HashMap 中的每个值指定一个特定的键,并且使用该键我们可以获取该值。
我想知道我们要放入哈希表(在 java Hashmap 中)的值、哈希值和键之间有什么区别?这背后的数学原理是什么?
c++ - 具有三个整数的结构键的良好哈希函数
对于具有三个 int 来标识唯一结构的简单 C++ 结构,如果对 a、b 和 c 的实际值了解不多,什么可以是一个好的散列函数实现。我需要使用结构作为 unordered_map 的键吗?
c - IPv4/6 地址的快速散列函数
我正在用 C 编写程序,该程序旨在快速。
我想在数据流中存储 IP 地址的出现次数。例如,我将分析 100MB 的二进制文件,其中包含大约 2 000 000 个 IP 地址(但也许程序也将用于 x-GB 文件)。
我的想法是使用哈希表,所以我需要这些哈希函数:
我认为这个函数有时会发生冲突不是问题(我将使用单独的链接解决这个问题)。
- 我应该使用哪些哈希函数?
- 为这个问题使用哈希表是个好主意吗?
小数学:
- 20b 索引 = 1 048 576 个元素(够不够?)
- 32b 元素 = 4B 元素 = 4MB 表大小(这个大小可以吗,什么时候程序将在当前计算机上运行?)
注意:IP 地址可能已指定掩码。例如:IPv4/24 --> 现在只有 2^24 个不同的 IPv4 地址,而不是 2^32。设置掩码时,我应该使用不同的哈希表大小吗?
绝对优先的是速度。
c++ - 以三个无符号字符为键的无序映射
我必须制作一个由以下键和值组成的 unordered_map:
键:无符号字符、无符号字符、无符号字符
值:结构(int,int)
这是我定义的代码:
这段代码有什么问题吗,因为当我在 linux 终端上链接这些文件时。它给了我错误。部分错误如下
在函数`std::__detail::_Hash_code_base const, std::pair const, G::IndexGuide>, std::_Select1st const, G::IndexGuide> >, std::equal_to const>, std::hash const> , std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, false>::_M_bucket_index(std::__detail::_Hash_node const, G::IndexGuide>, false> const*, unsigned int) const':
java - java将数值加密为字母数字值
我想加密数值。
例如;
该值为数字。
我想将它加密为字母数字+数字。但是我只需要 5 个字符的输出。
AB123
是一个输出示例。
谁能给我任何加密的例子?
谢谢你。
hash-function - 哈希函数映射 5 到 7 张卡片的组合
参考原题:Optimizing hand-evaluation algorithm for Poker-Monte-Carlo-Simulation
我有一个包含 5 到 7 张卡片的列表,并希望将它们的值存储在一个哈希表中,该哈希表应该是一个 32 位整数数组,并由哈希函数值作为索引直接访问。关于 52 张牌中的大量可能组合,我不想浪费太多内存。
数字:
- 7张组合:133784560
- 6张组合:20358520
- 5张组合:2598960
- 总计:156.742.040 种可能的组合
存储 1.57 亿个 32 位整数值大约需要 580MB。所以我想通过在数组中为不需要的值保留内存来避免增加这个数字。
所以问题是:散列函数看起来如何,将每个可能的、非重复的卡片组合映射到 0 到 156.742.040 之间的连续值,或者至少接近它?
hashtable - 调整表大小时发现哈希函数错误
在准备考试时,我遇到了一个关于哈希表的问题。我得到一个长度为 11 的表,其中包含以下哈希函数:
然后将哈希表的大小调整为 12。因此新的哈希函数变为:
会出现哪些问题?
vector - 在方案中生成位向量
我正在尝试实现一个拼写检查器,它采用散列函数和字典,然后将单词的散列值映射到位向量。更具体地说,我正在尝试编写一个名为 gen-checker 的函数,该函数将哈希函数列表和单词字典作为输入,并返回一个拼写检查器。拼写检查器必须为字典的输入生成一个位向量表示,其中包含 #t 或 #f 指示单词的正确或错误拼写。
我已经定义了 has 函数并有一个要使用的字典,但我似乎无法设置位向量
我已经尝试实现(make-bitvector 8 #f)在这里找到:
http://www.gnu.org/software/guile/manual/html_node/Bit-Vectors.html
但由于某种原因,drracket 无法识别它。我究竟做错了什么?如何实现位向量表示?
c++ - C++ Bitwise operations on an Integer such as Mid-Square, Folding, and Truncation
I am trying to perform some bitwise operations on a given key for a hash table program. The methods that I am trying to figure out are folding, mid-square, truncation, and radix. I am not expecting anyone to give me the direct answer, but help send me in the right direction. I cannot find any correspondence or help online that refers to this, or any algorithms that may help. I have a bitwise program that shows some of the operations on binary numbers, such as shifting, XOR, OR, AND< and so on. What I am not understanding is how to select only one portion of a 32 bit binary number, such as in mid-square, where you would select the middle four bits, and use just those in the operation. I have tried several things, but the following is what I have ended up with. I think the mid-square works (not sure though), but only seems to work on large integers. The folding and truncation definitely are not working. I haven't even attempted the radix method. Any help, guidance, or referring me to the appropriate documentation that would be most helpful would be great.
EDIT (Revisions): Ok, here are some revisions I have made. I don't know if any of these are right, but let me know what can be changed, better optimized, and is totally wrong. I get output with all four methods, but whether or not is is all right, I don't know yet. I haven't thoroughly examined each.
REVISED CODE:
encryption - 盐做法澄清
我最近在阅读 Jeff Six 的《Android 平台的应用程序安全性》,我发现了一个令我感到困惑的声明。在描述盐和散列函数的加密部分中,做了这个声明
就像 IVs [Initialization Vector] 一样,盐值应该是随机的,但它们不需要保密。
这是真的?因为我对盐和散列函数的理解是这个陈述是错误的,盐需要保护,因为如果盐被释放,可以生成一个新的彩虹表,从而不需要盐?它是否正确?或者盐真的不需要保密吗?为什么会这样?