Why is the initialCapacity of Hashtable 11 while the DEFAULT_INITIAL_CAPACITY in HashMap is 16 and requires a power of 2?

The following article addresses this question in some detail: HashMap requires a better hashCode() – JDK 1.4 Part II. According to that article, the main reason to move to power-of-two sizes was that bit masking is faster than integer division. This is not without adverse consequences, which are explained by one of the original authors: … Read more

Is the hashCode function generated by Eclipse any good?

You can see the implementation of hashCode function in java.util.ArrayList as public int hashCode() { int hashCode = 1; Iterator<E> i = iterator(); while (i.hasNext()) { E obj = i.next(); hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode()); } return hashCode; } It is one such example and your Eclipse generated code follows a … Read more

Simple hashmap implementation in C++

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 the value, not as the key, … Read more

Have a good hash function for a C++ hash table?

Now assumming you want a hash, and want something blazing fast that would work in your case, because your strings are just 6 chars long you could use this magic: size_t precision = 2; //change the precision with this size_t hash(const char* str) { return (*(size_t*)str)>> precision; } CRC is for slowpokes 😉 Explanation: This … Read more

Why do we use linear probing in hash tables when there is separate chaining linked with lists?

I’m surprised that you saw chained hashing to be faster than linear probing – in practice, linear probing is typically significantly faster than chaining. This is primarily due to locality of reference, since the accesses performed in linear probing tend to be closer in memory than the accesses performed in chained hashing. There are other … Read more

Multidimensional associative arrays in Bash

You can’t do what you’re trying to do: bash arrays are one-dimensional $ declare -A PERSONS $ declare -A PERSON $ PERSON[“FNAME”]=’John’ $ PERSON[“LNAME”]=’Andrew’ $ declare -p PERSON declare -A PERSON='([FNAME]=”John” [LNAME]=”Andrew” )’ $ PERSONS[1]=([FNAME]=”John” [LNAME]=”Andrew” ) bash: PERSONS[1]: cannot assign list to array member You can fake multidimensionality by composing a suitable array index … Read more

Difference between HashMap and HashTable purely in Data Structures

In Computing Science terminology, a map is an associative container mapping from a key to a value. In other words, you can do operations like “for key K remember value V” and later “for key K get the value”. A map can be implemented in many ways – for example, with a (optionally balanced) binary … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)