hashtable

Why are tuples constructed from differently initialized sets equal?

随声附和 提交于 2019-12-03 00:59:06
I expected the following two tuples >>> x = tuple(set([1, "a", "b", "c", "z", "f"])) >>> y = tuple(set(["a", "b", "c", "z", "f", 1])) to compare unequal, but they don't: >>> x == y >>> True Why is that? Zero Piraeus At first glance, it appears that x should always equal y , because two sets constructed from the same elements are always equal: >>> x = set([1, "a", "b", "c", "z", "f"]) >>> y = set(["a", "b", "c", "z", "f", 1]) >>> x {1, 'z', 'a', 'b', 'c', 'f'} >>> y {1, 'z', 'a', 'b', 'c', 'f'} >>> x == y True However , it is not always the case that tuples (or other ordered collections)

A minimal hash function for C?

强颜欢笑 提交于 2019-12-03 00:29:41
问题 I can't use boost:hash because I have to stick with C and can't use C++. But, I need to hash a large number (10K to 100k) of tokens strings (5 to 40 bytes length) so that search within those are fastest. MD5, SHA1 or any long hash function seems too heavy for a simple task, I am not doing cryptography. Plus there is the storage and computing cost. Therefore my question: What might be the simplest hash algorithm that will ensure collision prevention in most practical cases. How many bit to use

What does “bucket entries” mean in the context of a hashtable?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 00:15:18
What does "bucket entries" mean in the context of a hashtable? A bucket is simply a fast-access location (like an array index) that is the the result of the hash function. The idea with hashing is to turn a complex input value into a different value which can be used to rapidly extract or store data. Consider the following hash function for mapping people's names into street addresses. First take the initials from the first and last name and turn them both into numeric values (0 through 25, from 'A' through 'Z'). Multiply the first by 26 and add the second, and this gives you a value from 0 to

Hash Table: Why deletion is difficult in open addressing scheme

帅比萌擦擦* 提交于 2019-12-02 20:26:24
I am trying to understand the open addressing method. I refer to T. H. Cormen's book on this topic, which states that deletion is difficult in open addressing. I am completely stuck at this paragraph: Deletion from an open-address hash table is difficult. When we delete a key from slot i , we cannot simply mark that slot as empty by storing NIL in it. Doing so might make it impossible to retrieve any key k during whose insertion we had probed slot i and found it occupied. I don't understand this. Please explain it with some examples. Assume hash(x) = hash(y) = hash(z) = i . And assume x was

How do I get the number of keys in a hash table in Lua?

荒凉一梦 提交于 2019-12-02 20:02:30
myTable = {} myTable["foo"] = 12 myTable["bar"] = "blah" print(#myTable) -- this prints 0 Do I actually have to iterate through the items in the table to get the number of keys? numItems = 0 for k,v in pairs(myTable) do numItems = numItems + 1 end print(numItems) -- this prints 2 I experimented with both the # operator and table.getn(). I thought table.getn() would do what you wanted but as it turns out it's returning the same value as #, namely 0. It appears that dictionaries insert nil placeholders as necessary. Looping over the keys and counting them seems like the only way to get the

Efficiently picking a random element from a chained hash table?

北城以北 提交于 2019-12-02 18:47:42
Just for practice (and not as a homework assignment) I have been trying to solve this problem (CLRS, 3rd edition, exercise 11.2-6): Suppose we have stored n keys in a hash table of size m, with collisions resolved by chaining, and that we know the length of each chain, including the length L of the longest chain. Describe a procedure that selects a key uniformly at random from among the keys in the hash table and returns it in expected time O(L * (1 + m/n)). What I thought so far is that the probability of each key being returned is 1/n. If we try to get a random value x between 1 to n, and

GHashTable that using uint64_t as key and a struct as value

时光总嘲笑我的痴心妄想 提交于 2019-12-02 18:44:41
问题 I am studying the GHashTable . Though there are already some examples in Stackoverflow, they are just some common case. So I am still not sure how to implement my requirements and decide to ask for help. I want to use a uint64_t as key and a struct as value. I find that there is no such built-in hash function in GLib . There is just a g_int64_hash() . Though the key is uint64_t , it will just be about 52 bits. So I think gint64 is OK. But I see some examples using GINT_TO_POINTER() to convert

How many hash buckets

你说的曾经没有我的故事 提交于 2019-12-02 17:39:27
If I notice that a hash table (or any other data structure built on a hash table) is filling up, at what point should you build a new table with more buckets. And given n items in the table so far, how do you figure out how many buckets to use in the new one? So let's say I have 100 buckets. Should I reorganize it when there are 50 items in it? 500? 5000? Or should I look for the most-full bucket and key on that? Then when I hit that point how big do I make the new hash table? Related to this, if you know beforehand roughly how many items will go in, is there a way to compute the number of

Is there HashTable structure in Wolfram Mathematica?

[亡魂溺海] 提交于 2019-12-02 17:38:52
I want to use a Structure like HashTable. Is there similar structure in Wolfram Mathematica ? Pillsy Update: Mathematica version 10 introduced the Association data structure ( tutorial ). There are a number of possibilities. The easiest possibility, which works well if you don't need to add or delete keys from your table, or change their associated values, is to construct a list of rules with the key on the left-hand side and the value on the right-hand side, and use Dispatch on it. If you do need to change the entries in your table, you can use the DownValues of a symbol as a hash table. This

Variables in command when calling hashtable

穿精又带淫゛_ 提交于 2019-12-02 16:32:56
问题 I'm trying to fetch a value from a hashtable like the one below. $Hashtable1AuthTestID = @{ "BID_XPI" = "(id 2)"; "MBID_XPI" = "(id 3)"; "T_XPI" = "(id 4)"; "ST_XPI" = "(id 5)"; "SI_XPI" = "(id 6)"; "T_SAML" = "(id 7)"; "ST_SAML" = "(id 8)"; "SI_SAML" = "(id 9)"; "BID_SAML" = "(id 10)"; "MBID_SAML" = "(id 11)"; } It's working fine if I use $Hashtable1AuthTestID.BID_XPI but since this will be a generic script for several different type of data (and environments) I would like to include several