hashtable

Sorted hash table (map, dictionary) data structure design

强颜欢笑 提交于 2019-12-18 11:42:38
问题 Here's a description of the data structure: It operates like a regular map with get , put , and remove methods, but has a sort method that can be called to sorts the map. However, the map remembers its sorted structure, so subsequent calls to sort can be much quicker (if the structure doesn't change too much between calls to sort ). For example: I call the put method 1,000,000 times. I call the sort method. I call the put method 100 more times. I call the sort method. The second time I call

Implement a hash table

让人想犯罪 __ 提交于 2019-12-18 11:33:46
问题 I'm trying to create an efficient look-up table in C . I have an integer as a key and a variable length char* as the value. I've looked at uthash , but this requires a fixed length char* value. If I make this a big number, then I'm using too much memory. struct my_struct { int key; char value[10]; UT_hash_handle hh; }; Has anyone got any pointers? Any insight greatly appreciated. Thanks everyone for the answers. I've gone with uthash and defined my own custom struct to accommodate my data.

Creating Hashtable as final in java

非 Y 不嫁゛ 提交于 2019-12-18 11:16:01
问题 As we know the purpose of "final" keyword in java. While declaring a variable as final, we have to initialize the variable. like " final int a=10;" We can not change the value of "a". But if we go for HashTable its possible to add some value even declaring the HashTable as final. Example:: private static final Hashtable<String,Integer> MYHASH = new Hashtable<String,Integer>() {{ put("foo", 1); put("bar", 256); put("data", 3); put("moredata", 27); put("hello", 32); put("world", 65536); }}; Now

Hash table - why is it faster than arrays?

喜夏-厌秋 提交于 2019-12-18 10:02:55
问题 In cases where I have a key for each element and I don't know the index of the element into an array, hashtables perform better than arrays (O(1) vs O(n)). Why is that? I mean: I have a key, I hash it.. I have the hash.. shouldn't the algorithm compare this hash against every element's hash? I think there's some trick behind the memory disposition, isn't it? 回答1: In cases where I have a key for each element and I don't know the index of the element into an array, hashtables perform better

Hash table - why is it faster than arrays?

做~自己de王妃 提交于 2019-12-18 10:02:52
问题 In cases where I have a key for each element and I don't know the index of the element into an array, hashtables perform better than arrays (O(1) vs O(n)). Why is that? I mean: I have a key, I hash it.. I have the hash.. shouldn't the algorithm compare this hash against every element's hash? I think there's some trick behind the memory disposition, isn't it? 回答1: In cases where I have a key for each element and I don't know the index of the element into an array, hashtables perform better

Size of the hash table

醉酒当歌 提交于 2019-12-18 09:12:06
问题 Let the size of the hash table to be static (I set it once). I want to set it according to the number of entries. Searching yielded that the size should be a prime number and equal to 2*N (the closest prime number I guess), where N is the number of entries. For simplicity, assume that the hash table will not accept any new entries and won't delete any. The number of entries will be 200, 2000, 20000 and 2000000. However, setting the size to 2*N seems too much to me. It isn't? Why? If it is,

Optimizing Worst Case Time complexity to O(1) for python dicts [closed]

有些话、适合烂在心里 提交于 2019-12-18 05:17:15
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I have to store 500M two digit unicode character in memory (RAM). The data structure I use should have: Worst Case Space Complexity: O(n) Worst Case Time Complexity: O(1) <-- insertion, read, update, deletion I

Please explain murmur hash?

ⅰ亾dé卋堺 提交于 2019-12-17 23:12:48
问题 I just found out murmur hash, seems to be the fastest known and quite collision resistant. I tried to dig more about the algorithm or implementation in full source code, but I am having difficulty understanding it. Could someone here explain the algorithm used, or implement it in full source code, preferably in C. I read the C source code from the author website but has no idea, like: what is seed, h, k, m ? what does this mean : k *= m; k ^= k >> r; k *= m; h *= m; h ^= k; data += 4; len -=

How much memory does a Hashtable use?

怎甘沉沦 提交于 2019-12-17 22:53:33
问题 In Java, if I create a Hashtable<K, V> and put N elements in it, how much memory will it occupy? If it's implementation dependent, what would be a good "guess"? 回答1: Edit; Oh geez, I'm an idiot, I gave info for HashMap, not HashTable. However, after checking, the implementations are identical for memory purposes. This is dependent on your VM's internal memory setup (packing of items, 32 bit or 64 bit pointers, and word alignment/size) and is not specified by java. Basic info on estimating

How are hash tables implemented internally in popular languages?

穿精又带淫゛_ 提交于 2019-12-17 21:53:45
问题 Can someone please shed some light on how popular languages like Python, Ruby implements hash tables internally for symbol lookup? Do they use the classic "array with linked-list" method, or use a balanced tree? I need a simple (fewer LOC) and fast method for indexing the symbols in a DSL written in C. Was wondering what others have found most efficient and practical. 回答1: The classic "array of hash buckets" you mention is used in every implementation I've seen. One of the most educative