hashtable

Why Hashtable does not allow null keys or values?

房东的猫 提交于 2019-11-27 18:45:19
As specified in JDK documentation, Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values. Why is this? Hashtable is the older class, and its use is generally discouraged. Perhaps they saw the need for a null key, and more importantly - null values, and added it in the HashMap implementation. HashMap is newer, and has more advanced capabilities, which are basically just an improvement on the Hashtable functionality. When HashMap was created, it was specifically designed to handle null values as keys and handles them as a special case. Edit From

Is there a Directed Acyclic Graph (DAG) data type in Java, and should I use it?

拈花ヽ惹草 提交于 2019-11-27 18:41:56
问题 I am modeling a power subsystem in Java. A simple SQLite database contains a set of Line Replaceable Units (LRUs) and the connections between them. I am writing a Power Model API to simplify queries of the data store, using DDD patterns and repositories. I am seeking an appropriate Java collection to model the query results. There are some special cases in a LRU connection stream that have to be modeled: Initially, there's a Power Distribution Unit (PDU) with multiple ports (<=16) that feeds

Sorting a HashMap based on Value then Key? [duplicate]

回眸只為那壹抹淺笑 提交于 2019-11-27 18:39:49
问题 Possible Duplicate: How to sort a Map<Key, Value> on the values in Java? I have a HashMap of the type: HashMap<String, Integer> h = new HashMap<String, Integer>(); The HashMap contains a list of Strings and the Integer is a counter for the number of times that String has been found. What I would like to be able to do is sort the HashMap based on the Integers, then on the alphabetical order of the Strings. At the moment I am keeping a record of the largest occurrence of a word (variable named

Rehashing process in hashmap or hashtable

雨燕双飞 提交于 2019-11-27 18:37:02
How is the rehashing process done in a hashmap or hashtable when the size exceeds the maxthreshold value? Are all pairs just copied to a new array of buckets? EDIT: What happen to the elements in the same bucket (in linked list) after rehashing? I mean will they remain in same bucket after rehashing? dharam The maximum threshold in the question is called the load factor. It is advisable to have a load factor of around 0.75. Load factor is defined as (m/n) where n is the total size of the hash table and m is the preferred number of entries which can be inserted before a increment in size of the

Overriding Python's Hashing Function in Dictionary

对着背影说爱祢 提交于 2019-11-27 18:32:32
问题 I am trying to create a custom hash function for some object that I'll be hashing into a dictionary. The hashing function is unique (not the standard Python one). This is very important to me: to use the unique function. Each key's value is a list. Assuming I override __hash__ and end up coming up with the right hash number for an object. Would: dict = {} dict[number_here] = value hash the value into the position number number_here , or would it still be at the position that Python's hash

Why are there no hashtables in the C standard library?

喜夏-厌秋 提交于 2019-11-27 18:18:41
Why is that there is no Hashtable support as part of Standard C Library? Is there any specific reason for this? paxdiablo There is no hashtable in the standard C library because either: no-one has submitted a proposal to the working group; or the working group has deemed it unnecessary. That's the way ISO works. Proposals are put forward and accepted or rejected. You have to be careful what you add to the standard library since you have two conflicting groups. As a user, you might want every data structure under the sun to be added to the standard to make the language more useful. But, as a

Why push method is significantly slower than putting values via array indices in Javascript

夙愿已清 提交于 2019-11-27 17:48:23
问题 I pretty don't understand why this test : http://jsperf.com/push-method-vs-setting-via-key Shows that a.push(Math.random()); is over ten times slower than a[i] = Math.random(); Could you explain why this is the case ? What magic "push" do that make it so slow ? (or so slow compared to other valid method of doing that). EDIT NOTE: The push test is biased. I increase size of the array every iteration! Read carefully accepted answer! 回答1: Could you explain why this is the case? Because your test

Fast disk-based hashtables?

强颜欢笑 提交于 2019-11-27 17:38:10
I have sets of hashes (first 64 bits of MD5, so they're distributed very randomly) and I want to be able to see if a new hash is in a set, and to add it to a set. Sets aren't too big, the largest will be millions of elements, but there are hundreds of sets, so I cannot hold them all in memory. Some ideas I had so far: I tried just keeping it all in sqlite table, but it becomes really really slow once it cannot fit everything in memory. Bloom filters sound like they would have very high error rate. I don't mind tiny error rate (64 bit hash gives 1 collision on 4G element set already), but error

Trie complexity and searching

℡╲_俬逩灬. 提交于 2019-11-27 17:20:35
问题 What is the complexity of creating a trie of a list of words and what is complexity of searching other set of word in that trie? Should I use trie for string searching, when i have hashtable? 回答1: The complexity of creating a trie is O(W*L) , where W is the number of words, and L is an average length of the word: you need to perform L lookups on the average for each of the W words in the set. Same goes for looking up words later: you perform L steps for each of the W words. Hash insertions

Chained Hash Tables vs. Open-Addressed Hash Tables

最后都变了- 提交于 2019-11-27 17:17:41
Can somebody explain the main differences between (advantages / disadvantages) the two implementations? For a library, what implementation is recommended? Richard Barrell Wikipedia's article on hash tables gives a distinctly better explanation and overview of different hash table schemes that people have used than I'm able to off the top of my head. In fact you're probably better off reading that article than asking the question here. :) That said... A chained hash table indexes into an array of pointers to the heads of linked lists. Each linked list cell has the key for which it was allocated