hashtable

C# Dictionary<> and mutable keys

我只是一个虾纸丫 提交于 2019-11-27 06:48:26
问题 I was told that one of the many reasons strings were made immutable in the C# spec was to avoid the issue of HashTables having keys changed when references to the string keys altered their content. The Dictionary<> type allows reference types to be used as a key. How does the dictionary avoid the issue of altered keys that lead to "misplaced" values? Is there a memberwise clone made of an object when used as a key? 回答1: The Dictionary<TKey,TValue> type makes no attempt to protect against the

c++ - unordered_map complexity

纵饮孤独 提交于 2019-11-27 06:40:26
问题 I need to create a lookup function where a (X,Y) pair corresponds to a specific Z value. One major requirement for this is that I need to do it in as close to O(1) complexity as I can. My plan is to use an unordered_map. I generally do not use a hash table for lookup, as the lookup time has never been important to me. Am I correct in thinking that as long as I built the unordered_map with no collisions, my lookup time will be O(1)? My concern then is what the complexity becomes if there the

How do I limit the number of entries in a java hashtable?

空扰寡人 提交于 2019-11-27 05:50:11
问题 Is there a technique such that I can specify a number n such that when the (n + 1)th entry is inserted, the oldest entry is removed first ensuring that the size of the hashtable is always limited to n? 回答1: LinkedHashMap does exactly that, see javadoc for the removeEldestEntry method. Something like this should do the trick, this will remove the oldest inserted entry: Map map = new LinkedHashMap() { @Override protected boolean removeEldestEntry(Entry eldest) { return size() > N; } }; You can

How do I create a Dictionary that holds different types in C#

不想你离开。 提交于 2019-11-27 05:32:06
问题 I need some sort of way to store key/value pairs where the value can be of different types. So I like to do: int i = 12; string s = "test"; double x = 24.1; Storage.Add("age", i); Storage.Add("name", s); Storage.Add("bmi", x); And later retrieve the values with: int a = Storage.Get("age"); string b = Storage.Get("name"); double c = Storage.Get("bmi"); How should a Storage like this look like? Thanks, Erik 回答1: Well, you could use Dictionary<string, dynamic> in C# 4 / .NET 4 - but other than

Simple hashmap implementation in C++

倖福魔咒の 提交于 2019-11-27 05:22:02
问题 I'm relatively new to C++. In Java, it's easy for me to instantiate and use a hashmap. I'd like to know how to do it in a simple way in C++, since I saw many different implementations and none of them looked simple to me. 回答1: Most compilers should define std::hash_map for you; in the coming C++0x standard, it will be part of the standard library as std::unordered_map. The STL Page on it is fairly standard. If you use Visual Studio, Microsoft has a page on it. If you want to use your class as

Hashtable key within integer interval

吃可爱长大的小学妹 提交于 2019-11-27 05:05:54
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 find the value because there is no key that contains 250 in it's interval So basically what i want is that

The fundamentals of Hash tables?

不打扰是莪最后的温柔 提交于 2019-11-27 04:59:02
问题 I'm quite confused about the basic concepts of a Hash table. If I were to code a hash how would I even begin? What is the difference between a Hash table and just a normal array? Basically if someone answered this question I think all my questions would be answered: If I had 100 randomly generated numbers (as keys), how would I implement a hash table and why would that be advantageous over an array? Psuedo-code or Java would be appreciated as a learning tool... 回答1: The answers so far have

Why is the 't' in Hash Table(Hashtable) in Java not capitalized [closed]

心已入冬 提交于 2019-11-27 03:28:44
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . Everything in Java seems to follow capitalization rules except for Hashtable. Hashtable<String, String> ht = new Hashtable<String, String>(); as opposed to ArrayList<String> a = new ArrayList<String>(); or HashMap<String,Integer> a = new HashMap<String,Integer>(); Why is this ? Is Hash Table read as just one

Reference as key in swift dictionary

情到浓时终转凉″ 提交于 2019-11-27 03:17:27
问题 Dictionary key requires Hashable conformance: class Test {} var dictionary = [Test: String]() // Type 'Test' dies not conform to protocol 'Hashable' class Test: NSObject {} var dictionary = [Test: String]() // Works How to get address of pure Swift class instance to use as hashValue ? 回答1: Equality can be implemented as object identity, i.e. a == b iff a and b refer to the same instance of the class, and the hash value can be build from the ObjectIdentifier (which is the same for identical

how to get Hash table Arraylist to other intent?

心已入冬 提交于 2019-11-27 03:00:42
问题 I have hashtbles in array list. List<Hashtable<String, String>> info = new ArrayList<Hashtable<String, String>>(); Hashtable<String, String> hm = new Hashtable<String, String>(); // Put elements to the map hm.put("Read_Flag", s1); hm.put("sms_received_id", s2); hm.put("Sender_Id", s3); hm.put("Sender_Name", s4); hm.put("Patient_Name", s5); hm.put("Received_Date", s6); hm.put("Received_Text", s7); hm.put("Received_Text_Full", s8); hm.put("AttachmentFlag", s9); // Get a set of the entries Set<?