/** Format: mapType, num, (key, value) pairs */ private void writeObject(ObjectOutputStream out) throws IOException { out.writeObject(mapType); out.writeInt(num); for (Entry e : this) { out.writeObject(e.getKey()); out.writeDouble(e.getValue()); } }
public static void main(String[] args) throws Exception { // Test int T = 200; int n = 10000; if (args[0].equals("ser")) { StringDoubleMap map = test(10000, 10000); map.locked = false; // Cheat map.switchToSortedList(); ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("map")); out.writeObject(map); out.close(); ObjectInputStream in = new ObjectInputStream(new FileInputStream("map")); StringDoubleMap map2 = (StringDoubleMap) in.readObject(); in.close(); assert map.size() == map2.size(); for (StringDoubleMap.Entry e : map) { assert map2.getSure(e.getKey()) == e.getValue(); } } else if (args[0].equals("test")) { for (int i = 0; ; i++) { System.out.println("test " + i); test(10000, 10000); } } else if (args[0].equals("sdm")) { StringDoubleMap map = new StringDoubleMap(); for (int q = 0; q < T; q++) { // System.out.println(q); for (int i = 0; i < n; i++) { // if(q > 0) System.out.println("put " + i); map.put(i + "key" + i, i + q); // map.debugDump(); // if(q == 1 && i == 1000) // map.switchToHashTable(); } if (q == 0) { map.switchToSortedList(); // map.repCheck(); // map.lock(); map.debugDump(); } } } else { HashMap<String, Double> omap = new HashMap<String, Double>(); for (int q = 0; q < T; q++) { for (int i = 0; i < n; i++) { omap.put(i + "key" + i, 1.0 + i + q); } } } /*map.switchToSortedList(); map.debugDump(); map.switchToHashTable(); map.debugDump(); map.switchToSortedList(); map.debugDump(); for(Entry e : map) System.out.println(e.getKey() + " => " + e.getValue());*/ }