hashtable

how does except method work in linq

梦想与她 提交于 2019-11-27 02:15:40
问题 I have the classes: class SomeClass { public string Name{get;set;} public int SomeInt{get;set;} } class SomeComparison: IEqualityComparer<SomeClass> { public bool Equals(SomeClass s, SomeClass d) { return s.Name == d.Name; } public int GetHashCode(SomeClass a) { return (a.Name.GetHashCode() * 251); } } I also have two large List<SomeClass> called list1 and list2 before I used to have: var q = (from a in list1 from b in list2 where a.Name != b.Name select a).ToList(); and that took about 1

Multidimensional associative arrays in Bash

夙愿已清 提交于 2019-11-27 01:36:33
问题 I'm trying to create a multidimensional associative array but need some help. I have reviewed the page suggested in this SO answer but it confused me even more. So far here is what I have: The script: #!/bin/bash declare -A PERSONS declare -A PERSON PERSON["FNAME"]='John' PERSON["LNAME"]='Andrew' PERSONS["1"]=${PERSON[@]} PERSON["FNAME"]='Elen' PERSON["LNAME"]='Murray' PERSONS["2"]=${PERSON[@]} for KEY in "${!PERSONS[@]}"; do TMP="${PERSONS["$KEY"]}" echo "$KEY - $TMP" echo "${TMP["FNAME"]}"

When should I use a Hashtable versus a HashMap

断了今生、忘了曾经 提交于 2019-11-27 01:05:59
问题 This is not a question about the differences between Hashtable and HashMap . I understand that a Hashtable object cannot accept null values for either key or value entries, that it is synchronized collection, and that it uses slightly less memory than a HashMap . I'm wondering about the scenarios where it would be more appropriate to use a Hashtable instead of a HashMap . 回答1: This is not a question about the differences between Hashtable and HashMap Well it is really... I'm wondering about

How do you implement GetHashCode for structure with two string, when both strings are interchangeable

自作多情 提交于 2019-11-27 00:59:15
问题 I have a structure in C#: public struct UserInfo { public string str1 { get; set; } public string str2 { get; set; } } The only rule is that UserInfo(str1="AA", str2="BB").Equals(UserInfo(str1="BB", str2="AA")) How to override the GetHashCode function for this structure? 回答1: MSDN: A hash function must have the following properties: If two objects compare as equal, the GetHashCode method for each object must return the same value. However, if two objects do not compare as equal, the

Why does HashMap require that the initial capacity be a power of two?

泪湿孤枕 提交于 2019-11-27 00:14:47
I was going through Java's HashMap source code when I saw the following //The default initial capacity - MUST be a power of two. static final int DEFAULT_INITIAL_CAPACITY = 16; My question is why does this requirement exists in the first place? I also see that the constructor which allows creating a HashMap with a custom capacity converts it into a power of two: int capacity = 1; while (capacity < initialCapacity) capacity <<= 1; Why does the capacity always has to be a power of two? Also, when automatic rehashing is performed, what exactly happens? Is the hash function altered too? The map

Difference between Hashtable and Collections.synchronizedMap(HashMap)

萝らか妹 提交于 2019-11-27 00:14:01
问题 As far as I know, java.util.Hashtable synchronizes each and every method in the java.util.Map interface, while Collections.synchronizedMap(hash_map) returns a wrapper object containing synchronized methods delegating calls to the actual hash_map (correct me if I am wrong). I have two questions : What difference does it make to synchronize each and every method and to have a wrapper class? What are the scenarios to choose one over the other? What happens when we do Collections.synchronizedMap

Hash tables VS associative arrays

心已入冬 提交于 2019-11-27 00:08:04
问题 Recently I have read about hash-tables in a very famous book "Introduction to Algorithms". I haven't used them in any real applications yet, but want to. But I don't know how to start. Can anyone give me some samples of using it, for example, how to realize a dictionary application (like ABBYY Lingvo) using hash-tables? And finally I would like to know what is the difference between hash-tables and associative arrays in PHP, I mean which technology should I use and in which situations? If I

Improving performance of very large dictionary in Python

痴心易碎 提交于 2019-11-27 00:03:10
问题 I find that if I initialize an empty dictionary at the beginning, and then adding elements to the dictionary in a for loop (about 110,000 keys, the value for each key is a list, also increasing in the loop), the speed goes down as for loop goes. I suspect that the problem is, the dictionary does not know the number of keys at init time and it is not doing something very smart, so perhaps the storage collision becomes quite often and it slows down. If I know the number of keys and exactly what

ConcurrentHashMap and Hashtable in Java [duplicate]

怎甘沉沦 提交于 2019-11-26 23:55:50
This question already has an answer here: What's the difference between ConcurrentHashMap and Collections.synchronizedMap(Map)? 18 answers What is the difference between a ConcurrentHashMap and a Hashtable in Java? Which is more efficient for threaded applications? Lucas Holt ConcurrentHashMap uses multiple buckets to store data. This avoids read locks and greatly improves performance over a HashTable . Both are thread safe, but there are obvious performance wins with ConcurrentHashMap . When you read from a ConcurrentHashMap using get() , there are no locks, contrary to the HashTable for

Generate same unique hash code for all anagrams

吃可爱长大的小学妹 提交于 2019-11-26 22:54:29
问题 Recently, I attended an interview and faced a good question regarding hash collisions. Question : Given a list of strings, print out the anagrams together. Example : i/p : {act, god, animal, dog, cat} o/p : act, cat, dog, god I want to create hashmap and put the word as key and value as list of anagrams To avoid collision, I want to generate unique hash code for anagrams instead of sorting and using the sorted word as key. I am looking for hash algorithm which take care of collision other