hashtable

Binary Trees vs. Linked Lists vs. Hash Tables

你离开我真会死。 提交于 2019-11-27 16:40:59
I'm building a symbol table for a project I'm working on. I was wondering what peoples opinions are on the advantages and disadvantages of the various methods available for storing and creating a symbol table. I've done a fair bit of searching and the most commonly recommended are binary trees or linked lists or hash tables. What are the advantages and or disadvantages of all of the above? (working in c++) Your use case is presumably going to be "insert the data once (e.g., application startup) and then perform lots of reads but few if any extra insertions". Therefore you need to use an

What's the logic behind Python's hash function order?

只愿长相守 提交于 2019-11-27 16:16:19
As we know, Some of Python's data structures use hash tables for storing items like set or dictionary . So there is no order in these objects. But it seems that, for some sequences of numbers that's not true. For example consider the following examples : >>> set([7,2,5,3,6]) set([2, 3, 5, 6, 7]) >>> set([4,5,3,0,1,2]) set([0, 1, 2, 3, 4, 5]) But it isn't sorted if we make a small change : >>> set([8,2,5,3,6]) set([8, 2, 3, 5, 6]) So the question is: How does Python's hash function work on integer sequences? Although there are a lot of questions in SO about hash and its order,but no one of them

The fastest way to retrieve 16k Key-Value pairs?

六月ゝ 毕业季﹏ 提交于 2019-11-27 16:15:02
OK, here's my situation : I have a function - let's say U64 calc (U64 x) - which takes a 64-bit integer parameter, performs some CPU-intensive operation, and returns a 64-bit value Now, given that I know ALL possible inputs (the x s) of that function beforehand (there are some 16000 though), I thought it might be better to pre-calculate them and then fetch them on demand (from an array-like structure). The ideal situation would be to store them all in some array U64 CALC[] and retrieve them by index (the x again) And here's the issue : I may know what the possible inputs for my calc function

Why are entries in addition order in a .Net Dictionary?

空扰寡人 提交于 2019-11-27 15:59:23
I just saw this behaviour and I'm a bit surprised by it... If I add 3 or 4 elements to a Dictionary, and then do a "For Each" to get all the keys, they appear in the same order I added them. The reason this surprises me is that a Dictionary is supposed to be a HashTable internally, so I expected things to come out in ANY order (ordered by the hash of the key, right?) What am I missing here? Is this a behaviour I can count on? EDIT: OK, I thought already of many of the reasons why this might happen (like the separate list to entries, whether this is a coincidence, etc). My question is, does

Hashtable to Dictionary<> syncroot .

扶醉桌前 提交于 2019-11-27 14:45:51
Hashtables have a syncroot property but generic dictionaries don't. If I have code that does this: lock (hashtable.Syncroot) { .... } How do I replicate this if I am removing the hashtable and changing to generic dictionaries? If you are going strictly for compatability then Bryan is correct. This is the best way to maintain your current semantics on top of a Dictionary. Expanding on it though. The reason the SyncRoot property was not directly added to the generic dictionary is that it's a dangerous way to do synchronization. It's only slighly better than "lock(this)" which is very dangerous

Java: A “prime” number or a “power of two” as HashMap size?

这一生的挚爱 提交于 2019-11-27 12:23:51
Many books and tutorials say that the size of a hash table must be a prime to evenly distribute the keys in all the buckets. But Java's HashMap always uses a size that is a power of two. Shouldn't it be using a prime? What's better, a "prime" or a "power of two" as the hash table size? Using a power of two effectively masks out top bits of the hash code. Thus a poor-quality hash function might perform particularly badly in this scenario. Java's HashMap mitigates this by mistrusting the object's hashCode() implementation and applying a second level of hashing to its result : Applies a

Iterating over and deleting from Hashtable in Java

泪湿孤枕 提交于 2019-11-27 11:54:24
I have a Hashtable in Java and want to iterate over all the values in the table and delete a particular key-value pair while iterating. How may this be done? You need to use an explicit java.util.Iterator to iterate over the Map 's entry set rather than being able to use the enhanced For-loop syntax available in Java 6. The following example iterates over a Map of Integer , String pairs, removing any entry whose Integer key is null or equals 0. Map<Integer, String> map = ... Iterator<Map.Entry<Integer, String>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<Integer, String>

hash function providing unique uint from an integer coordinate pair

烂漫一生 提交于 2019-11-27 11:15:14
问题 The problem in general: I have a big 2d point space, sparsely populated with dots. Think of it as a big white canvas sprinkled with black dots. I have to iterate over and search through these dots a lot. The Canvas (point space) can be huge, bordering on the limits of int and its size is unknown before setting points in there. That brought me to the idea of hashing: Ideal: I need a hash function taking a 2D point, returning a unique uint32. So that no collisions can occur. You can assume that

Hashtable in C++?

家住魔仙堡 提交于 2019-11-27 10:55:21
I usually use C++ stdlib map whenever I need to store some data associated with a specific type of value (a key value - e.g. a string or other object). The stdlib map implementation is based on trees which provides better performance (O(log n)) than the standard array or stdlib vector. My questions is, do you know of any C++ "standard" hashtable implementation that provides even better performance (O(1))? Something similar to what is available in the Hashtable class from the Java API. Chris Jester-Young If you're using C++11, you have access to the <unordered_map> and <unordered_set> headers.

Why are hash table expansions usually done by doubling the size?

这一生的挚爱 提交于 2019-11-27 10:32:05
I've done a little research on hash tables, and I keep running across the rule of thumb that when there are a certain number of entries (either max or via a load factor like 75%) the hash table should be expanded. Almost always, the recommendation is to double (or double plus 1, i.e., 2n+1) the size of the hash table. However, I haven't been able to find a good reason for this. Why double the size, rather than, say, increasing it 25%, or increasing it to the size of the next prime number, or next k prime numbers (e.g., three)? I already know that it's often a good idea to choose an initial