Java

Contents
      1. Collections
              1. HashMap growth
              2. Mutable field pitfall
      2. References
      3. Links

Collections

HashMap growth
When length > loadFactor*capacity, the map length grows to 2n+1 (Sun default LoadFactor is .75). Set initialCapacity to 89 to get prime sizes until 2879 inclusively (cf. Z, p. 78-82). Since JDK 1.4, Sun always uses a power of two as bucket size, instead. It uses a bit mask to determine the bucket. HashMap re-hashes the hashCode to fit that situation (cf. K).
Mutable field pitfall
Consider adding a class x to a collection, and then changing one of the classes fields. If the hashCode of the class changes on that operation, the HashSet (among others) will probably have contains(x) returning false, even though it contains x. The reason being that x is still indexed by its old hash code. (cf. OSV)

References

Links


EditContents