From 08387f98bc83ba48601ba7860716cfec4d56c92d Mon Sep 17 00:00:00 2001 From: jjenista Date: Thu, 10 Nov 2011 00:09:42 +0000 Subject: [PATCH] bug fix: retrieve by full key returned empty set, now correct --- Robust/src/Util/MultiViewMap.java | 8 +++++ .../src/Util/UnitTests/MultiViewMapTest.java | 32 +++++++++++++------ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Robust/src/Util/MultiViewMap.java b/Robust/src/Util/MultiViewMap.java index c8482c91..4ce0f9d3 100644 --- a/Robust/src/Util/MultiViewMap.java +++ b/Robust/src/Util/MultiViewMap.java @@ -221,6 +221,14 @@ public class MultiViewMap { Set getFullKeys( BitSet view, MultiKey partialKey ) { + if( view.equals( fullView ) ) { + Set fullKeys = new HashSet(); + if( fullKey2value.containsKey( partialKey ) ) { + fullKeys.add( partialKey ); + } + return fullKeys; + } + Map> partialKey2fullKeys = getPartialKey2fullKeys( view ); return getFullKeys( partialKey2fullKeys, partialKey ); diff --git a/Robust/src/Util/UnitTests/MultiViewMapTest.java b/Robust/src/Util/UnitTests/MultiViewMapTest.java index fc4a004d..c2c1f97b 100644 --- a/Robust/src/Util/UnitTests/MultiViewMapTest.java +++ b/Robust/src/Util/UnitTests/MultiViewMapTest.java @@ -17,9 +17,11 @@ public class MultiViewMapTest { private static Random random; + private static int numTests = 0; + private static int numPassed = 0; - private static void p() { System.out.println( " passed" ); } - private static void f() { System.out.println( " !!!FAILED!!!" ); } + private static void p() { numTests++; numPassed++; System.out.print( "." ); } + private static void f() { numTests++; System.out.println( "!!!FAILED!!!" ); } private static void verify( Map expected, Map actual ) { @@ -43,12 +45,14 @@ public class MultiViewMapTest { joinOp = new JoinOpInteger(); + System.out.println(""); testBuilder(); System.out.println(""); testMap(); System.out.println(""); stressTest(); System.out.println(""); + System.out.println(numPassed+"/"+numTests+" passed."); } @@ -208,7 +212,7 @@ public class MultiViewMapTest { expected = new HashMap(); verify( expected, mapA.get( view0, partialKey4 ) ); - + // Try across a merge mapA.put( vader, 1001 ); expected = new HashMap(); @@ -239,6 +243,14 @@ public class MultiViewMapTest { expected.put( r2, 1004 ); verify( expected, mapA.get( view0, partialKey4 ) ); + + // Get for full keys didn't work in production, + // so test it explicitly + expected = new HashMap(); + expected.put( luke, 1002 ); + verify( expected, mapA.get( view012, luke ) ); + + // removes vader and han MultiKey partialKey4true = MultiKey.factory( 4, true ); mapA.remove( view01, partialKey4true ); @@ -301,16 +313,16 @@ public class MultiViewMapTest { } - System.out.println( " Number of full keys in each table per op cycle:" ); + //System.out.println( " Number of full keys in each table per op cycle:" ); for( int reps = 0; reps < 100; ++reps ) { int nextOp = random.nextInt( 100 ); - System.out.print( " Op: " ); + //System.out.print( " Op: " ); if( nextOp < 15 ) { // put some new values in - System.out.print( "PT " ); + //System.out.print( "PT " ); int numNewValues = 1 + random.nextInt( 8 ); for( int i = 0; i < numNewValues; ++i ) { MultiKey newKey = MultiKey.factory( getInt( ints ), @@ -321,7 +333,7 @@ public class MultiViewMapTest { } else if( nextOp < 70 ) { // remove values by a random view - System.out.print( "RM " ); + //System.out.print( "RM " ); MultiViewMap map = getMap( maps ); switch( random.nextInt( 6 ) ) { @@ -335,16 +347,16 @@ public class MultiViewMapTest { } else { // merge two tables - System.out.print( "MG " ); + //System.out.print( "MG " ); getMap( maps ).merge( getMap( maps ) ); } for( int i = 0; i < maps.length - 1; ++i ) { if( i < maps.length - 1 ) { - System.out.print( maps[i].size() + ", " ); + //System.out.print( maps[i].size() + ", " ); } } - System.out.println( maps[maps.length-1].size() ); + //System.out.println( maps[maps.length-1].size() ); } System.out.println( "DONE" ); -- 2.34.1