📄 testhashstructures.java
字号:
throw new Exception("HashMap size mismatch"); } } } void populateBySerialIntKeysInt(DoubleIntIndex intLookup, org.hsqldb.lib.IntKeyHashMap hMap, int testSize) throws Exception { for (int i = 0; i < testSize; i++) { int intValue = randomgen.nextInt(); intLookup.addUnique(i, intValue); hMap.put(i, new Integer(intValue)); if (intLookup.size() != hMap.size()) { throw new Exception("HashMap size mismatch"); } } } void populateByRandomIntKeysInt(DoubleIntIndex intLookup, org.hsqldb.lib.IntKeyHashMap hMap, int testSize) throws Exception { for (int i = 0; i < testSize; i++) { int intValue = randomgen.nextInt(); intLookup.addUnique(intValue, i); hMap.put(intValue, new Integer(i)); // actually this can happen as duplicates are allowed in DoubleIntTable if (intLookup.size() != hMap.size()) { throw new Exception("Duplicate random in int lookup"); } } } void populateByRandomIntKeys(java.util.HashMap uMap, org.hsqldb.lib.HashMap hMap, int testSize) throws Exception { for (int i = 0; i < testSize; i++) { int intValue = randomgen.nextInt(); uMap.put(new Integer(intValue), new Integer(i)); hMap.put(new Integer(intValue), new Integer(i)); if (uMap.size() != hMap.size()) { throw new Exception("HashMap size mismatch"); } } } void populateByRandomIntKeysInt(java.util.HashMap uMap, org.hsqldb.lib.IntKeyHashMap hMap, int testSize) throws Exception { for (int i = 0; i < testSize; i++) { int intValue = randomgen.nextInt(); uMap.put(new Integer(intValue), new Integer(i)); hMap.put(intValue, new Integer(i)); if (uMap.size() != hMap.size()) { throw new Exception("HashMap size mismatch"); } } } void depopulateRandomly(java.util.HashMap uMap, org.hsqldb.lib.HashMap hMap, int testCount) throws Exception { int removeCount = 0; int size = uMap.size(); if (testCount > size / 2) { testCount = size / 2; } while (removeCount < testCount) { java.util.Iterator uIt = uMap.keySet().iterator(); for (int i = 0; uIt.hasNext(); i++) { Object uKey = uIt.next(); int intValue = randomgen.nextInt(size); if (intValue == i) { uIt.remove(); hMap.remove(uKey); removeCount++; } if (uMap.size() != hMap.size()) { throw new Exception("HashMap size mismatch"); } } } } void depopulateByIterator(java.util.HashMap uMap, org.hsqldb.lib.HashMap hMap, int testCount) throws Exception { org.hsqldb.lib.Iterator hIt = hMap.keySet().iterator(); System.out.println(uMap.size()); for (int i = 0; hIt.hasNext(); i++) { Object key = hIt.next(); int check = randomgen.nextInt(2); if (check == i % 2) { hIt.remove(); uMap.remove(key); } if (uMap.size() != hMap.size()) { throw new Exception("HashMap size mismatch"); } } System.out.println(uMap.size()); } void depopulateByIntIterator(java.util.HashMap uMap, org.hsqldb.lib.IntKeyHashMap hIntMap, int testCount) throws Exception { org.hsqldb.lib.Iterator hIt = hIntMap.keySet().iterator(); System.out.println(uMap.size()); for (int i = 0; hIt.hasNext(); i++) { Object key = new Integer(hIt.nextInt()); int check = randomgen.nextInt(2); if (check == i % 2) { hIt.remove(); uMap.remove(key); } if (uMap.size() != hIntMap.size()) { throw new Exception("HashMap size mismatch"); } } System.out.println(uMap.size()); } void clearByIntIterator(java.util.HashMap uMap, org.hsqldb.lib.IntKeyHashMap hIntMap) throws Exception { org.hsqldb.lib.Iterator hIt = hIntMap.keySet().iterator(); System.out.println(uMap.size()); for (int i = 0; hIt.hasNext(); i++) { Object key = new Integer(hIt.nextInt()); hIt.remove(); uMap.remove(key); if (uMap.size() != hIntMap.size()) { throw new Exception("HashMap size mismatch"); } } System.out.println(uMap.size()); } void compareByUIterator(java.util.HashMap uMap, org.hsqldb.lib.HashMap hMap) throws Exception { java.util.Iterator uIt = uMap.keySet().iterator(); for (int i = 0; uIt.hasNext(); i++) { Object uKey = uIt.next(); Object oU = uMap.get(uKey); Object hU = hMap.get(uKey); if (!oU.equals(hU)) { throw new Exception("HashMap value mismatch"); } } } void compareByHIterator(java.util.HashMap uMap, org.hsqldb.lib.HashMap hMap) throws Exception { org.hsqldb.lib.Iterator hIt = hMap.keySet().iterator(); for (int i = 0; hIt.hasNext(); i++) { Object hKey = hIt.next(); Object oU = uMap.get(hKey); Object hU = hMap.get(hKey); if (!oU.equals(hU)) { throw new Exception("HashMap value mismatch"); } } } void compareByUIteratorInt(java.util.HashMap uMap, org.hsqldb.lib.IntKeyHashMap hMap) throws Exception { java.util.Iterator uIt = uMap.keySet().iterator(); for (int i = 0; uIt.hasNext(); i++) { Object uKey = uIt.next(); Object oU = uMap.get(uKey); Object hU = hMap.get(((Integer) uKey).intValue()); if (!oU.equals(hU)) { throw new Exception("HashMap value mismatch"); } } } void compareByHIteratorInt(java.util.HashMap uMap, org.hsqldb.lib.IntKeyHashMap hMap) throws Exception { org.hsqldb.lib.Iterator hIt = hMap.keySet().iterator(); for (int i = 0; hIt.hasNext(); i++) { Object hKey = new Integer(hIt.nextInt()); Object oU = uMap.get(hKey); Object hU = hMap.get(((Integer) hKey).intValue()); if (!oU.equals(hU)) { throw new Exception("HashMap value mismatch"); } } } void compareByHIteratorInt(DoubleIntIndex intLookup, org.hsqldb.lib.IntKeyHashMap hMap) throws Exception { org.hsqldb.lib.Iterator hIt = hMap.keySet().iterator(); for (int i = 0; hIt.hasNext(); i++) { int hK = hIt.nextInt(); int lookup = intLookup.findFirstEqualKeyIndex(hK); int lV = intLookup.getValue(lookup); Integer hV = (Integer) hMap.get(hK); if (hV.intValue() != lV) { throw new Exception("HashMap value mismatch"); } } } int nextIntRandom(Random r, int range) { int b = Math.abs(r.nextInt()); return b % range; } public static void main(String[] argv) { try { TestHashStructures test = new TestHashStructures("testHashMap"); test.testHashMap(); test.testIntKeyHashMap(); test.testHashMappedList(); test.testDoubleIntLookup(); test.testDoubleIntSpeed(); } catch (Exception e) { e.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -