hash-function

Generating k pairwise independent hash functions

∥☆過路亽.° 提交于 2019-12-04 18:58:49
问题 I'm trying to implement a Count-Min Sketch algorithm in Scala, and so I need to generate k pairwise independent hash functions. This is a lower-level than anything I've ever programmed before, and I don't know much about hash functions except from Algorithms classes, so my question is: how do I generate these k pairwise independent hash functions? Am I supposed to use a hash function like MD5 or MurmurHash? Do I just generate k hash functions of the form f(x) = ax + b (mod p) , where p is a

How can I use a C++ unordered_set for a custom class?

。_饼干妹妹 提交于 2019-12-04 12:02:40
问题 How can I store objects of a class in an unordered_set ? My program needs to frequently check if an object exists in this unordered_set and if it does, then do some update on that object. I have looked up online on how to use unordered_set , but sadly most tutorials are about using it on int or string types. But how can I use it on a class? How can I define a hash function to make the node_id in the following example the key of the unordered_set ? #include <iostream> #include <unordered_set>

Generating k pairwise independent hash functions

删除回忆录丶 提交于 2019-12-03 12:32:39
I'm trying to implement a Count-Min Sketch algorithm in Scala, and so I need to generate k pairwise independent hash functions. This is a lower-level than anything I've ever programmed before, and I don't know much about hash functions except from Algorithms classes, so my question is: how do I generate these k pairwise independent hash functions? Am I supposed to use a hash function like MD5 or MurmurHash? Do I just generate k hash functions of the form f(x) = ax + b (mod p) , where p is a prime and a and b are random integers? (i.e., the universal hashing family everyone learns in algorithms

How can I use a C++ unordered_set for a custom class?

扶醉桌前 提交于 2019-12-03 06:48:34
How can I store objects of a class in an unordered_set ? My program needs to frequently check if an object exists in this unordered_set and if it does, then do some update on that object. I have looked up online on how to use unordered_set , but sadly most tutorials are about using it on int or string types. But how can I use it on a class? How can I define a hash function to make the node_id in the following example the key of the unordered_set ? #include <iostream> #include <unordered_set> using namespace std; // How can I define a hash function that makes 'node' use 'node_id' as key? struct

Towards understanding dictionaries

大兔子大兔子 提交于 2019-12-01 23:18:53
问题 I am required to use multiple hashtables, so in c++, I would normally use an std::unordered_map. So far I can understand that I can use a dictionary in Python, so let's assume the following code: my_dict_1 = {} my_dict_1['foo'] = 1 my_dict_2 = {} my_dict_2['foo'] = 2 Will the two dictionaries be using different hash functions (notice that the key is the same ), thus they can be considered two different hash tables (I mean that they will actually store the data differently)? EDIT: Yes the

Towards understanding dictionaries

◇◆丶佛笑我妖孽 提交于 2019-12-01 22:49:46
I am required to use multiple hashtables, so in c++ , I would normally use an std::unordered_map . So far I can understand that I can use a dictionary in Python, so let's assume the following code: my_dict_1 = {} my_dict_1['foo'] = 1 my_dict_2 = {} my_dict_2['foo'] = 2 Will the two dictionaries be using different hash functions (notice that the key is the same ), thus they can be considered two different hash tables (I mean that they will actually store the data differently)? EDIT: Yes the dictionaries are two different objects of course, but the question is about the technique that they will

Hash function on list independant of order of items in it

泪湿孤枕 提交于 2019-12-01 19:08:01
I want to have a dictionary that assigns a value to a set of integers. For example key is [1 2 3] and value will have certain value. The thing is that [3 2 1] needs to be treated the same in my case so hash needs to be equal, if I go with hash approach. The set will have 2 to 10 items. Sum of items is usually fixed so we cannot make hashcode according to sum, which is a first natural idea here. Not a homework task, actually facing this problem in my code. This set is basically IEnumerable<int> in C# so any data structure is fine to store them. Any help appreciated. Performance is pretty

Are there no specializations of std::hash for standard containers?

假如想象 提交于 2019-11-30 00:16:04
问题 I just found myself a little bit surprised being unable to simply use a std::unordered_set<std::array<int, 16> > test; because there does not seem to be a std::hash specialization for std::array s. Why is that? Or did I simply not find it? If there is indeed none, can the following implementation attempt be simplified? namespace std { template<typename T, size_t N> struct hash<array<T, N> > { typedef array<T, N> argument_type; typedef size_t result_type; result_type operator()(const argument

What are the important points about cryptographic hash functions?

一曲冷凌霜 提交于 2019-11-28 20:48:47
I was reading this question on MD5 hash values and the accepted answer confuses me. One of the main properties, as I understand it, of a cryptopgraphic hash function is that it is infeasible to find two different messages (inputs) with the same hash value. Yet the consensus answer to the question Why aren't MD5 hash values reversible? is Because an infinite number of input strings will generate the same output. This seems completely contradictory to me. Also, what perplexes me somewhat is the fact that the algorithms are public, yet the hash values are still irreversible. Is this because there

Hash function for floats

寵の児 提交于 2019-11-27 22:09:26
I'm currently implementing a hash table in C++ and I'm trying to make a hash function for floats... I was going to treat floats as integers by padding the decimal numbers, but then I realized that I would probably reach the overflow with big numbers... Is there a good way to hash floats? You don't have to give me the function directly, but I'd like to see/understand different concepts... Notes: I don't need it to be really fast, just evenly distributed if possible. I've read that floats should not be hashed because of the speed of computation, can someone confirm/explain this and give me other