Questions tagged [perfect-hash]

A perfect hash function for a set S is a hash function that maps distinct elements in S to a set of integers, with no collisions.

60 questions
4
votes
4 answers

Perfect hash function for strings known in advance

I have 4000 strings and I want to create a perfect hash table with these strings. The strings are known in advance, so my first idea was to use a series of if statements: if (name=="aaa") return 1; else if (name=="bbb") return 2; …
4
votes
1 answer

Perfect hash for string with known number of keys

Is it possible to have a perfect hash function from strings to integers, when the number of elements to be hashed is known? By perfect hash function I mean that there is no chance of collision. Basically I am reading the signatures of multiple…
user1377000
  • 1,433
  • 3
  • 17
  • 29
4
votes
2 answers

Perfect minimal hash for mathematical combinations

First, define two integers N and K, where N >= K, both known at compile time. For example: N = 8 and K = 3. Next, define a set of integers [0, N) (or [1, N] if that makes the answer simpler) and call it S. For example: {0, 1, 2, 3, 4, 5, 6, 7} The…
Kendall Frey
  • 43,130
  • 20
  • 110
  • 148
3
votes
2 answers

Create perfect hash for millions of items - result just needs to be "exists or not"

Does anyone know of a good library (windows) that will allow me to create a static (not runtime) perfect hash for millions of items (probably about 10m)? I essentially have millions of sets of strings and I want to know at a minimal O(1) if a string…
Shahar Prish
  • 4,838
  • 3
  • 26
  • 47
3
votes
2 answers

Minimal perfect hash for N number of unknown keys

I have two unsorted arrays of 32-bit unsigned integers, size N1 and N2, respectively. Each array may contain duplicates. I would like to map each value (2^32 possible keys) to a spot in a byte-array of size (N1 + N2) to record frequencies of each…
datboi
  • 437
  • 4
  • 10
3
votes
2 answers

Determining Perfect Hash Lookup Table for Pearson Hash

I'm developing a programming language, and in my programming language, I'm storing objects as hash tables. The hash function I'm using is Pearson Hashing, which depends on a 256-bit lookup table. Here's the function: char* pearson(char* name,…
Imagist
  • 18,086
  • 12
  • 58
  • 77
2
votes
2 answers

16 bit unique key to 8 bit array index (perfect hash)

I have a set of structs that are uniquely identified by a uint16_t. There will never be more than 256 of these structs (due to reasons I won't get into a uint16_t must be used to identify the structs). I would like to store these structs via an…
HXSP1947
  • 1,311
  • 1
  • 16
  • 39
2
votes
1 answer

Perfect hash function for large set of integers [1..2^64 - 1]

I need to construct a perfect hash function that maps a set of integer [1..2^64 - 1] to itself (this function is actually some some complex permutation). To explain this problem suppose that we have sequence of integer primary keys in database. We…
2
votes
3 answers

Best way to perfectly hash a three letter lowercase String in Java?

My current solution uses a multi-dimensional array, does a simpler solution exist? I want to access the hashed objects in O(1) time and want to make best use of memory space hence the need for a perfect hash. public final class PerfectHash…
newlogic
  • 807
  • 8
  • 25
2
votes
0 answers

How can I calculate the size of an unordered_map for a perfect hash function seed number?

I want to achieve perfect hashing with unordered map. I have a set of compile time known string that is mapping to something. I want to generate perfect hash functions for them. I figured out if I choose the size of the unordered_map 3 time larger…
2
votes
2 answers

How to use gperf to create hash for a range of values?

I have range of hex numbers like these 0xabcd**** 0xabdc**89 0x****abcd 0xde****ab # 50 or so more entries like these # where * is any hex number I need a hash a function that will accept a 4byte value and generate Y/N answer for membership. I…
user2708149
  • 475
  • 4
  • 7
2
votes
4 answers

Are EnumMaps in Java perfect hash maps?

If the list of hash keys for a hash function is known and immutable, it is possible to generate a perfect hash function. A Enum in Java is a list of known and immutable elements. Therefor it should be possible to implement the EnumMap as a perfect…
ceving
  • 21,900
  • 13
  • 104
  • 178
2
votes
3 answers

Does a perfect hash function guarantee no collisions?

I have been reading and learning hashing and hashtables and experemented with some code(I am still very new to this so I might say something wrong that I missunderstood). I came to the issue for perfect hash functions. Provided that I have my own…
Bosak
  • 2,103
  • 4
  • 24
  • 43
2
votes
3 answers

Perfect hash function to obfuscate a sequential value

Here is what I need (language: C# 4): I am building a system where you can submit complaints. After complaint has been submitted you are given a unique 9 digits number that identifies your complaint in the system. For security (security through…
THX-1138
  • 21,316
  • 26
  • 96
  • 160
1
vote
1 answer

What is the better way to implement a perfect hash function for an iOS app?

I need to create a perfect hash for a list of string identifiers, so before to begin with this implementation (i have never did it before) i want to know if there is any good framework or good tutorial that could be useful? Thanks!
LuisEspinoza
  • 8,508
  • 6
  • 35
  • 57