[jconch commit] r106 - in trunk: . src/jconch/multikey

1 view
Skip to first unread message

codesite...@google.com

unread,
Mar 15, 2008, 4:36:42 PM3/15/08
to jco...@googlegroups.com
Author: robert....@SmokejumperIT.com
Date: Fri Mar 14 15:57:28 2008
New Revision: 106

Modified:
trunk/jconch.iws
trunk/src/jconch/multikey/JConchMultiKey.java

Log:
Now caches the hash code on the multikeys.

Modified: trunk/jconch.iws
==============================================================================
--- trunk/jconch.iws (original)
+++ trunk/jconch.iws Fri Mar 14 15:57:28 2008
@@ -161,7 +161,7 @@
<file leaf-file-name="JConchMultiKey.java" pinned="false"
current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/jconch/multikey/JConchMultiKey.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="7" column="0" selection-start="155"
selection-end="155" vertical-scroll-proportion="0.11982881">
+ <state line="33" column="54" selection-start="967"
selection-end="967" vertical-scroll-proportion="0.56490725">
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -481,7 +481,7 @@
<option name="PERFORM_EDIT_IN_BACKGROUND" value="true" />
<option name="PERFORM_ADD_REMOVE_IN_BACKGROUND" value="true" />
<option name="FORCE_NON_EMPTY_COMMENT" value="false" />
- <option name="LAST_COMMIT_MESSAGE" value="Changing MultiKey to
cache the hashCode." />
+ <option name="LAST_COMMIT_MESSAGE" value="Fixed some bogus
documentation." />
<option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="true" />
<option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="true" />
<option name="REFORMAT_BEFORE_FILE_COMMIT" value="false" />
@@ -494,6 +494,7 @@
<option name="FILE_HISTORY_SPLITTER_PROPORTION" value="0.6" />
<MESSAGE value="Upgrading to IntelliJ and adding in the MultiKey
stuff." />
<MESSAGE value="Changing MultiKey to cache the hashCode." />
+ <MESSAGE value="Fixed some bogus documentation." />
</component>
<component name="VssConfiguration">
<option name="CLIENT_PATH" value="" />
@@ -634,7 +635,7 @@
</entry>
<entry file="file://$PROJECT_DIR$/src/jconch/multikey/JConchMultiKey.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="7" column="0" selection-start="155"
selection-end="155" vertical-scroll-proportion="0.11982881">
+ <state line="33" column="54" selection-start="967"
selection-end="967" vertical-scroll-proportion="0.56490725">
<folding>
<element signature="imports" expanded="true" />
</folding>

Modified: trunk/src/jconch/multikey/JConchMultiKey.java
==============================================================================
--- trunk/src/jconch/multikey/JConchMultiKey.java (original)
+++ trunk/src/jconch/multikey/JConchMultiKey.java Fri Mar 14 15:57:28 2008
@@ -5,24 +5,51 @@

import java.util.List;

+/**
+ * A fast, typed, non-modifiable, thread-safe implementation of having
multiple keys for a map.
+ */
public abstract class JConchMultiKey {

- private static final int BASE_HASH_CODE = RandomUtils.nextInt();
-
+ /**
+ * The number of elements in the multikey.
+ *
+ * @return The cardinality of this implementation.
+ */
public abstract int getKeyCount();

+ /**
+ * The keys that make up the multikey.
+ *
+ * @return An unmodifiable list of keys that make up the map.
+ */
public abstract List<Object> getKeys();

- @Override
- public int hashCode() {
- int hashCode = BASE_HASH_CODE;
+ /**
+ * An arbitrary value from which to start our hash code algorithm.
+ */
+ private static final int BASE_HASH_CODE = RandomUtils.nextInt();
+
+ /**
+ * The cached hash code for this map. Cached so that we get
thread safety and speed, and because it's
+ * almost inevitably going to be used in any case.
+ */
+ private final int hashCode;
+
+ public JConchMultiKey() {
+ int myHashCode = BASE_HASH_CODE;
for (final Object key : getKeys()) {
if (key == null) {
- hashCode = ~hashCode + 1;
+ myHashCode = ~myHashCode + 1;
} else {
- hashCode = hashCode ^ key.hashCode();
+ myHashCode = myHashCode ^ key.hashCode();
}
}
+ hashCode = myHashCode;
+ }
+
+
+ @Override
+ public int hashCode() {
return hashCode;
}

Reply all
Reply to author
Forward
0 new messages