hashtable

What is a hash map in programming and where can it be used

*爱你&永不变心* 提交于 2019-11-27 10:21:29
问题 I have often heard people talking about hashing and hash maps and hash tables. I wanted to know what they are and where you can best use them for. 回答1: First you shoud maybe read this article. When you use lists and you are looking for a special item you normally have to iterate over the complete list. This is very expensive when you have large lists. A hashtable can be a lot faster, under best circumstances you will get the item you are looking for with only one access. How is it working?

Super high performance C/C++ hash map (table, dictionary) [closed]

こ雲淡風輕ζ 提交于 2019-11-27 10:14:29
I need to map primitive keys (int, maybe long) to struct values in a high-performance hash map data structure. My program will have a few hundred of these maps, and each map will generally have at most a few thousand entries. However, the maps will be "refreshing" or "churning" constantly; imagine processing millions of add and delete messages a second. What libraries in C or C++ have a data structure that fits this use case? Or, how would you recommend building your own? Thanks! Scharron I would recommend you to try Google SparseHash (or the C11 version Google SparseHash-c11 ) and see if it

Have a good hash function for a C++ hash table?

。_饼干妹妹 提交于 2019-11-27 09:37:40
问题 I am in need of a performance-oriented hash function implementation in C++ for a hash table that I will be coding. I looked around already and only found questions asking what's a good hash function "in general". I've considered CRC32 (but where to find good implementation?) and a few cryptography algorithms. My table, though, has very specific requirements. Here's what the table will be like: 100,000 items max 200,000 capacity (so the load is 0.5) hashing a 6-character string which is a part

What is the true difference between a dictionary and a hash table?

Deadly 提交于 2019-11-27 09:36:28
问题 I've always used dictionaries. I write in Python. 回答1: A dictionary is a general concept that maps keys to values. There are many ways to implement such a mapping. A hashtable is a specific way to implement a dictionary. Besides hashtables, another common way to implement dictionaries is red-black trees. Each method has it's own pros and cons. A red-black tree can always perform a lookup in O(log N). A hashtable can perform a lookup in O(1) time although that can degrade to O(N) depending on

Custom HashMap Code Issue

江枫思渺然 提交于 2019-11-27 08:29:09
问题 I have following code, where I used HashMap (using two parallel arrays) for storing key-value pairs (key can have multiple values). Now, I have to store and load it for future use that's why I store and load it by using File Channel. Issue with this code is: I can store nearly 120 millions of key-value pairs in my 8 GB server (actually, I can allocate nearly 5 gb out of 8 gb for my JVM, and those two parallel arrays takes nearly 2.5 gb, other memory are used for various processing of my code)

Powershell Hashtable Count and Keys Properties getting overloaded

大城市里の小女人 提交于 2019-11-27 08:04:33
问题 Problem Statement : The Count and Keys properties can get overloaded by a hash value and not return their expected values. My Powershell Code is this: $hash = @{} $hash.one = "Number 1" $hash.two = "Number 2" "Count is [{0}]" -f $hash.Count $hash.Count = "Count's Hash Value" "Count is now [{0}]" -f $hash.Count My Output is this: Count is [2] Count is now [Count's Hash Value] The Count Property gets overloaded! This issues could cause users some very hard to diagnose bugs. Had me confused for

Hash function for a string

别来无恙 提交于 2019-11-27 08:03:09
We are currently dealing with hash function in my class. Our instructor asked us to a hash function on the internet to compare to the two we have used in our code. The first one: int HashTable::hash (string word) // POST: the index of entry is returned { int sum = 0; for (int k = 0; k < word.length(); k++) sum = sum + int(word[k]); return sum % SIZE; } Second: int HashTable::hash (string word) { int seed = 131; unsigned long hash = 0; for(int i = 0; i < word.length(); i++) { hash = (hash * seed) + word[i]; } return hash % SIZE; } Where SIZE is 501 (The size of the hash table) and the input is

Why is Dictionary.First() so slow?

元气小坏坏 提交于 2019-11-27 07:43:29
问题 Not a real question because I already found out the answer, but still interesting thing. I always thought that hash table is the fastest associative container if you hash properly. However, the following code is terribly slow. It executes only about 1 million iterations and takes more than 2 minutes of time on a Core 2 CPU. The code does the following: it maintains the collection todo of items it needs to process. At each iteration it takes an item from this collection (doesn't matter which

Why hashmap lookup is O(1) i.e. constant time?

亡梦爱人 提交于 2019-11-27 07:15:25
If we look from Java perspective then we can say that hashmap lookup takes constant time. But what about internal implementation? It still would have to search through particular bucket (for which key's hashcode matched) for different matching keys.Then why do we say that hashmap lookup takes constant time? Please explain. Under the appropriate assumptions on the hash function being used, we can say that hash table lookups take expected O(1) time (assuming you're using a standard hashing scheme like linear probing or chained hashing). This means that on average , the amount of work that a hash

Using IEqualityComparer GetHashCode with a tolerance

*爱你&永不变心* 提交于 2019-11-27 07:10:00
问题 I am trying to implement an IEqualityComparer that has a tolerance on a date comparison. I have also looked into this question. The problem is that I can't use a workaround because I am using the IEqualityComparer in a LINQ .GroupJoin() . I have tried a few implementations that allow for tolerance. I can get the Equals() to work because I have both objects but I can't figure out how to implement GetHashCode() . My best attempt looks something like this: public class ThingWithDateComparer :