I experienced some really ghostly TreeMap behavior, and I had some problems narrowing a small test case, so bear with me.
I want to read a large number of key-value pairs in a Map from a file provided at runtime. I use my own key class. Later, when I go to pull out the records, I discovered that one or more of them are missing. Using a debugger and some test cases, I decided that the missing record (s) definitely disappears during the read phase, but I'm not sure what causes it.
Basically:
Map<MyKey,Double> map = new TreeMap<MyKey,Double>();
map.put(key1,value1);
assertTrue(map.containsKey(key1));
if (!map.containsKey(keyN)) {
map.put(keyN, valueN);
}
assertTrue(map.containsKey(key1));
... Thus, adding a new key to the card leads to the fact that an unrelated record may drop out of it.
- key1 keyN, key1 - 500 -
- 2.. (N-1), key1 N
- 2.. (N-1), key1 , N, , () keyQ, ~ 300
- , , keyN 1, , keyQ 1, , ,
- HashMap , key1
- MyKey Comparable, equals hashCode.
TreeMap, , TreeMap - . HashMap , , TreeMap - , ?