perfect-hash

Perfect hash function generator for functions

妖精的绣舞 提交于 2019-12-01 18:08:23
I have a set of C++ functions. I want to map this functions in an hash table, something like: unordered_map<function<ReturnType (Args...)> , SomethingElse> , where SomethingElse is not relevant for this question. This set of functions is previously known, small (let say less than 50) and static (is not gonna change). Since lookup performance is crucial (should be performed in O(1) ), I want to define a perfect hashing function. There exists a perfect hash function generator for this scenario? I know that there exists perfect hashing functions generators (like GPERF or CMPH ) but since I've

Injective two-way mappings [duplicate]

℡╲_俬逩灬. 提交于 2019-12-01 01:56:04
This question already has an answer here: Two way/reverse map 13 answers I often deal with mappings which are injective . In programming terminology, this can be expressed as a dictionary where all values are unique as well as, of course, all keys. Is there a memory-efficient data structure for injective mappings with all the time-complexity properties you expect from dictionaries? For example: d = {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'} d.get(2) = 'b' # this works with a normal dictionary d.get('b', reverse=True) = 2 # but this is not possible All the solutions in Two way/reverse map seem to

Fastest possible string key lookup for known set of keys

南楼画角 提交于 2019-11-30 06:45:10
Consider a lookup function with the following signature, which needs to return an integer for a given string key: int GetValue(string key) { ... } Consider furthermore that the key-value mappings, numbering N, are known in advance when the source code for function is being written, e.g.: // N=3 { "foo", 1 }, { "bar", 42 }, { "bazz", 314159 } So a valid (but not perfect!) implementation for the function for the input above would be: int GetValue(string key) { switch (key) { case "foo": return 1; case "bar": return 42; case "bazz": return 314159; } // Doesn't matter what we do here, control will

Minimal perfect hash function

为君一笑 提交于 2019-11-30 05:02:11
I have many integers in range [0; 2^63-1]. There is only 10^8 integers, however. There is no duplicates . Full list is known at compile-time but it is just unique random numbers . These numbers never changes . To store one integer explicitly , 8 bytes required, and there is associated 1-byte values, so explicit storing requires about 860 MB. So I want to find minimal perfect hash function to map each of 10^8 integers from [0;2^63-1] to [0;10^8-1]. I should find this function only once, data never changes, and function can be complicated. But it should be minimal, perfect, and calculating

Minimal perfect hash function

自古美人都是妖i 提交于 2019-11-29 03:07:51
问题 I have many integers in range [0; 2^63-1]. There is only 10^8 integers, however. There is no duplicates . Full list is known at compile-time but it is just unique random numbers . These numbers never changes . To store one integer explicitly , 8 bytes required, and there is associated 1-byte values, so explicit storing requires about 860 MB. So I want to find minimal perfect hash function to map each of 10^8 integers from [0;2^63-1] to [0;10^8-1]. I should find this function only once, data

Convert a string to number and back to string?

痴心易碎 提交于 2019-11-29 00:17:20
I would like to know how I can convert a short ASCII string to a number (int, float, or numeric string). I saw a couple of posts here mentioned perfect hashes which seems like it might be what I need . However, I'm not quite understanding the math for this. How could you convert an ASCII string into a sequence of numbers and then back to a string? As a side note, breaking a string down into it's ASCII character numbers is easy enough. foreach(str_split($string) as $char) $number .= ord($char); Update After more reading I came up with this. However, I'm wondering if there are anyways to shorten