Questions tagged [hash-function]

A hash function is an algorithm that maps large data sets of keys to smaller data sets of a fixed length. Hash functions are not reversible.

The values returned by a hash function are called hash values, hash codes, hash sums, checksums or simply hashes.

Hash functions are mostly used to accelerate lookup times for data comparison tasks such as finding items in a hash table, database, detecting duplicated or similar records in a large file, etc.

Read more on Wikipedia.

264 questions
10
votes
3 answers

C++11 Hash function for any enum type

I am writing a hash function for my object. I already can hash containers, and combine hashes, thanks to Generic Hash function for all STL-containers. But my classes also have enums. Of course I can create a hash function for every enum, but it does…
Draco Ater
  • 20,820
  • 8
  • 62
  • 86
10
votes
1 answer

Tabulation hashing and N3980

I am having trouble adapting the pending C++1z proposal N3980 by @HowardHinnant to work with tabulation hashing. Ab initio computing a tabulation hash works the same as for the hashing algorithm (Spooky, Murmur, etc.) described in N3980. It is not…
TemplateRex
  • 69,038
  • 19
  • 164
  • 304
10
votes
2 answers

Generating k pairwise independent hash functions

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…
grautur
  • 29,955
  • 34
  • 93
  • 128
9
votes
1 answer

Possible collisions in the standard JavaScript Object hash table implementation?

I recently happened to think about object property access times in JavaScript and came across this question which seemed to reasonably suggest that it should be constant time. This also made me wonder if there is a limit on object property key…
8
votes
5 answers

SSL encryption, SHA-1 and SHA-2

I am trying to implement SHA-2 encryption instead of SHA-1. For this, I know that the number of bits between these two hash algorithms are different, and it confuses me. How can this be achieved and at what parts do I need to make required…
Hellnar
  • 62,315
  • 79
  • 204
  • 279
7
votes
4 answers

What are buckets in terms of hash functions?

Looking at the book Mining of Massive Datasets, section 1.3.2 has an overview of Hash Functions. Without a computer science background, this is quite new to me; Ruby was my first language, where a hash seems to be equivalent to Dictionary
Zach Smith
  • 8,458
  • 13
  • 59
  • 133
7
votes
8 answers

What is a hash function in java?

I have check out this Wikipedia page on it, but I still don't understand it. Can someone please help my dim-witted mind to understand the concepts of hashing, hashtable/hashmap, and hash functions? Some examples would really help.
Mohit Deshpande
  • 53,877
  • 76
  • 193
  • 251
7
votes
1 answer

why a good choice of mod is "a prime not too close to an exact of 2"

To generate a hash function, Map a key k into one of m slots by taking the remainder of k divided by m. That is, the hash function is h(k) = k mod m. I have read at several places that a good choice of m will be A prime - I understand that we want…
learner
  • 606
  • 2
  • 8
  • 17
7
votes
5 answers

Obtaining a k-wise independent hash function

I need to use a hash function which belongs to a family of k-wise independent hash functions. Any pointers on any library or toolkit in C, C++ or python which can generate a set of k-wise independent hash functions from which I can pick a function.…
vkmv
  • 1,345
  • 1
  • 14
  • 24
6
votes
1 answer

Is there any generic Hashable typeclass in Haskell? (a.k.a. "deriving (Hashable)")

Has anyone written a generic function so that hash functions can be generated automatically for custom data types (using the deriving mechanism)? A few times, I've written the following kind of boilerplate, data LeafExpr = Var Name | Star deriving…
gatoatigrado
  • 16,580
  • 18
  • 81
  • 143
6
votes
1 answer

Fast numeric hash function for Spark (PySpark)

I am trying to apply a hash function to short strings in a column of a PySpark DataFrame (running on an EMR cluster) and get a numeric value as a new column. CRC3 would do the job for example. I am aware of this question, but it's in Scala, I need a…
Alt
  • 2,597
  • 5
  • 26
  • 36
6
votes
3 answers

Idea for keep information about visited states

I making now 15-puzzle solver (in c++), but instead of only 15-puzzle, my program must to solve also 3x4 puzzles, 8x8 puzzles, etc... - > X x Y puzzles. I must somehow keep information about visited states, my first idea was to make tree, for…
piotrek
  • 1,333
  • 4
  • 17
  • 35
6
votes
3 answers

Best hash function for mixed numeric and literal identifiers

For performance reasons I have a need to split a set of objects identified by a string into groups. Objects may be either identified by a number or by a string in prefixed (qualified) form with dots separating parts of the…
Andrey Adamovich
  • 20,285
  • 14
  • 94
  • 132
6
votes
4 answers

Hashing and encryption technique for a huge data set containing phone numbers

Description of problem: I'm in the process of working with a highly sensitive data-set that contains the people's phone number information as one of the columns. I need to apply (encryption/hash function on them) to convert them as some encoded…
Learner
  • 1,685
  • 6
  • 30
  • 42
5
votes
2 answers

many to one mapping Hash Function

I don't know the actual mathematical term (many to one mapping is the terminology i've used) This is my requirement: hash_code = hash_function(element 1, element 2, ...... element n) i should be able to retrieve bool b = is_valid_hash(hash_code,…
PC.
  • 6,870
  • 5
  • 36
  • 71
1
2
3
17 18