[Mulgara-svn] r836 - branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter
pag at mulgara.org
pag at mulgara.org
Thu Apr 24 05:43:04 UTC 2008
Author: pag
Date: 2008-04-23 22:43:03 -0700 (Wed, 23 Apr 2008)
New Revision: 836
Modified:
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/TestContext.java
Log:
Now doing bi-directional mapping from objects to IDs, as the test code which relied on hashcodes sometimes collided in one JVM and not another.
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/TestContext.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/TestContext.java 2008-04-24 05:41:57 UTC (rev 835)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/TestContext.java 2008-04-24 05:43:03 UTC (rev 836)
@@ -43,6 +43,12 @@
/** The map for converting IDs into Nodes stored against them */
private Map<Long,Node> globalizer = new HashMap<Long,Node>();
+ /** The map for converting Nodes into the IDs stored against them */
+ private Map<Node,Long> localizer = new HashMap<Node,Long>();
+
+ /** The pseudo node-pool counter */
+ private long lastNode = 1;
+
/**
* Empty constructor used for tests which have no data.
*/
@@ -84,7 +90,7 @@
if (columnNumber >= columnNames.size()) throw new QueryException("Unexpected column: " + columnNumber);
Node v = rows[rowNumber][columnNumber];
if (v == null) throw new QueryException("Unbound column: " + columnNumber);
- return v.hashCode();
+ return localizer.get(v);
}
/** @see org.mulgara.query.filter.Context#getInternalColumnIndex(java.lang.String) */
@@ -106,9 +112,15 @@
}
/**
- * Map node hash codes to the nodes. This is using hash codes as pseudo-gNodes
- * for the sake of testing. If there is a hash collision, then either update this
- * class or change the test to use non-conflicting test values.
+ * Gets a previously unused node ID.
+ * @return a new Node ID.
+ */
+ private long newNodeId() {
+ return lastNode++;
+ }
+
+ /**
+ * Map node IDs to the nodes, and nodes back to their IDs.
* @param rows An array of node arrays.
*/
private void mapGlobalizer(Node[][] rows) {
@@ -116,9 +128,14 @@
assert row.length == columnNames.size();
for (Node v: row) {
if (v == null) v = Null.NULL;
- Node stored = globalizer.get((long)v.hashCode());
- if (stored == null) globalizer.put((long)v.hashCode(), v);
- else assert stored == v : "Unexpected hash collision in test";
+ Long storedId = localizer.get(v);
+ if (storedId == null) {
+ storedId = newNodeId();
+ globalizer.put(storedId, v);
+ localizer.put(v, storedId);
+ } else {
+ assert globalizer.get(storedId) == v : "Bidirectional mapping for nodes<->ID failed";
+ }
}
}
}
More information about the Mulgara-svn
mailing list