perfect-hash

Convert a string to number and back to string?

萝らか妹 提交于 2020-01-20 02:25:16
问题 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);

Perfect hash function generator for functions

我怕爱的太早我们不能终老 提交于 2020-01-11 08:42:08
问题 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?

Fastest possible string key lookup for known set of keys

大城市里の小女人 提交于 2019-12-18 12:16:44
问题 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

Is it possible to create a Minimal Perfect Hash function without a separate lookup table for a small (<64) set of keys?

做~自己de王妃 提交于 2019-12-18 03:35:16
问题 I recently read this article Throw away the keys: Easy, Minimal Perfect Hashing about generating a minimal perfect hash table for a known set of keys. The article seems to assume that you need an intermediate table. Is there any other, simpler way to generate such a function if we assume that the set of keys is small (i.e. < 64). In my case, I want to map a set of thread ID:s to a unique block of data within an array. The threads are started before the hash function is generated and stay

Undefined reference to cmph functions even after installing cpmh library

爷,独闯天下 提交于 2019-12-11 17:14:32
问题 I am using gcc 4.4.3 on ubuntu. I installed cmph library tools 0.9-1 using command sudo apt-get install libcmph-tools Now, when I tried to compile example program vector_adapter_ex1.c , gcc is able to detect cmph.h library in its include file but is showing multiple errors like vector_adapter_ex1.c:(.text+0x93): undefined reference to cmph_io_vector_adapter' vector_adapter_ex1.c:(.text+0xa3): undefined reference to cmph_config_new' vector_adapter_ex1.c:(.text+0xbb): undefined reference to

Is it possible to make a minimal perfect hash function in this situation?

扶醉桌前 提交于 2019-12-09 10:32:30
问题 I want to create a Hash Map (or another structure, if you have any suggestions) to store key value pairs. The keys will all be inserted at once at the same time as the map is created, but I don't know what the keys will be (arbitrary length strings) until runtime, when I need to create the map. I am parsing a query string like this "x=100&name=bob&color=red&y=150" (but the string can have an unlimited number of variables and the variables can have any length name). I want to parse it once and

Perfect minimal hash for mathematical combinations

风格不统一 提交于 2019-12-05 05:56:08
问题 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 number of subsets of S with K elements is given by the formula C(N, K) . Example My problem is this: Create a perfect minimal hash for those subsets. The size of the example hash table will be C(8, 3) or 56 . I don't care about ordering, only

Injective two-way mappings [duplicate]

早过忘川 提交于 2019-12-03 23:03:30
问题 This question already has answers here : Two way/reverse map (15 answers) Closed last year . 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

Perfect minimal hash for mathematical combinations

别说谁变了你拦得住时间么 提交于 2019-12-03 17:24:53
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 number of subsets of S with K elements is given by the formula C(N, K) . Example My problem is this: Create a perfect minimal hash for those subsets. The size of the example hash table will be C(8, 3) or 56 . I don't care about ordering, only that there be 56 entries in the hash table, and that I can determine the hash quickly from a set of K

Is there a way to make this hash lookup any faster?

雨燕双飞 提交于 2019-12-03 04:19:38
问题 I have a requirement to (very) quickly process strings of a limited range, tallying their values. The input file is of the form: January 7 March 22 September 87 March 36 and so forth. Because the line widths are identical, I can simply read in a line with fread reasonably fast, and I've developed a perfect hashing function which works, but I wanted to see if anyone could offer any advice on how to make it even faster. I'll profile each suggestion to see how it goes. The hashing function is