hashtable

.NET HashTable Vs Dictionary - Can the Dictionary be as fast?

随声附和 提交于 2019-11-26 11:58:51
I am trying to figure out when and why to use a Dictionary or a HashTable. I have done a bit of a search on here and have found people talking about the generic advantages of the Dictionary which I totally agree with, which leads the boxing and unboxing advantage for a slight performance gain. But I have also read the Dictionary will not always return the objects in the order they are inserted, thing it is sorted. Where as a HashTable will. As I understand it this leads to the HashTable being far faster for some situations. My question is really, what might those situations be? Am I just wrong

How do HashTables deal with collisions?

偶尔善良 提交于 2019-11-26 11:31:52
I've heard in my degree classes that a HashTable will place a new entry into the 'next available' bucket if the new Key entry collides with another. How would the HashTable still return the correct Value if this collision occurs when calling for one back with the collision key? I'm assuming that the Keys are String type and the hashCode() returns the default generated by say Java. If I implement my own hashing function and use it as part of a look-up table (i.e. a HashMap or Dictionary ), what strategies exist for dealing with collisions? I've even seen notes relating to prime numbers!

Hashtable key within integer interval

雨燕双飞 提交于 2019-11-26 11:27:36
问题 I don\'t know if this is possible but i\'m trying to make an Hashtable of where Interval is a class with 2 integer / long values, a start and an end and i wanted to make something like this: Hashtable<Interval, WhateverObject> test = new Hashtable<Interval, WhateverObject>(); test.put(new Interval(100, 200), new WhateverObject()); test.get(new Interval(150, 150)) // returns the new WhateverObject i created above because 150 is betwwen 100 and 200 test.get(new Interval(250, 250)) // doesn\'t

How to implement an efficient bidirectional hash table? [duplicate]

只谈情不闲聊 提交于 2019-11-26 10:22:00
This question already has an answer here: Two way/reverse map 13 answers Python dict is a very useful data-structure: d = {'a': 1, 'b': 2} d['a'] # get 1 Sometimes you'd also like to index by values. d[1] # get 'a' Which is the most efficient way to implement this data-structure? Any official recommend way to do it? Here is a class for a bidirectional dict , inspired by Finding key from value in Python dictionary and modified to allow the following 2) and 3). Note that : 1) The inverse directory bd.inverse auto-updates itself when the standard dict bd is modified. 2) The inverse directory bd

Advantages of Binary Search Trees over Hash Tables

邮差的信 提交于 2019-11-26 10:06:01
问题 What are the advantages of binary search trees over hash tables? Hash tables can look up any element in Theta(1) time and it is just as easy to add an element....but I\'m not sure of the advantages going the other way around. 回答1: Remember that Binary Search Trees (reference-based) are memory-efficient. They do not reserve more memory than they need to. For instance, if a hash function has a range R(h) = 0...100 , then you need to allocate an array of 100 (pointers-to) elements, even if you

Why does LinkedHashSet<E> extend HashSet<e> and implement Set<E>

[亡魂溺海] 提交于 2019-11-26 09:09:15
问题 Opened a LinkedHashSet source code today and found some interesting thing: public class LinkedHashSet<E> extends HashSet<E> implements Set<E>, Cloneable, java.io.Serializable { The question is: why do they need both \"extends HashSet\" and \"implements Set\" when HashSet already is the Set? 回答1: I've asked Josh Bloch, and he informs me that it was a mistake. He used to think, long ago, that there was some value in it, but he since "saw the light". Clearly JDK maintainers haven't considered

How do I encode a JavaScript object as JSON?

为君一笑 提交于 2019-11-26 08:26:46
问题 Is there a good way to encode a JavaScript object as JSON? I have a list of key value pairs...where the name is from a checkbox, and the value is either true or false based on whether the box is checked or not: var values = {}; $(\'#checks :checkbox\').each(function() { values[this.name]=this.checked; }); I want to pass these values into a JSON object so store into a cookie to render a table (Columns will be added according to what the user checks off). Does anyone know a solution? 回答1: I

Hashtable with MultiDimensional Key in C#

瘦欲@ 提交于 2019-11-26 07:27:08
问题 I\'m basically looking for a way to access a hashtable value using a two-dimensional typed key in c#. Eventually I would be able to do something like this HashTable[1][false] = 5; int a = HashTable[1][false]; //a = 5 This is what I\'ve been trying...hasn\'t worked Hashtable test = new Hashtable(); test.Add(new Dictionary<int, bool>() { { 1, true } }, 555); Dictionary<int, bool> temp = new Dictionary<int, bool>() {{1, true}}; string testz = test[temp].ToString(); 回答1: I think a better approach

How to implement the Hashable Protocol in Swift for an Int array (a custom string struct)

为君一笑 提交于 2019-11-26 07:26:19
问题 I am making a structure that acts like a String , except that it only deals with Unicode UTF-32 scalar values. Thus, it is an array of UInt32 . (See this question for more background.) What I want to do I want to be able to use my custom ScalarString struct as a key in a dictionary. For example: var suffixDictionary = [ScalarString: ScalarString]() // Unicode key, rendered glyph value // populate dictionary suffixDictionary[keyScalarString] = valueScalarString // ... // check if dictionary

How Do I Choose Between a Hash Table and a Trie (Prefix Tree)?

主宰稳场 提交于 2019-11-26 06:53:08
问题 So if I have to choose between a hash table or a prefix tree what are the discriminating factors that would lead me to choose one over the other. From my own naive point of view it seems as though using a trie has some extra overhead since it isn\'t stored as an array but that in terms of run time (assuming the longest key is the longest english word) it can be essentially O(1) (in relation to the upper bound). Maybe the longest english word is 50 characters? Hash tables are instant look up