diff options
-rwxr-xr-x | make/build.xml | 48 | ||||
-rw-r--r-- | src/java/com/jogamp/common/util/IntIntHashMap.java | 39 | ||||
-rw-r--r-- | test/junit/com/jogamp/common/util/IntIntHashMapTest.java | 6 |
3 files changed, 58 insertions, 35 deletions
diff --git a/make/build.xml b/make/build.xml index f9eb19b..9076c5f 100755 --- a/make/build.xml +++ b/make/build.xml @@ -34,14 +34,6 @@ <property name="gluegen.excludes" value="com/jogamp/gluegen/runtime/BufferFactoryInternal.java,com/sun/gluegen/nativesig/**" /> </target> - <target name="setup.javase"> - <!-- not needed anymore --> - </target> - - <target name="setup.javacdc"> - <!-- not needed anymore --> - </target> - <target name="init" depends="gluegen.properties.load.user,setup-excludes-1,setup-excludes-2"> <!-- Declare all paths and user defined variables. --> @@ -72,10 +64,6 @@ <mkdir dir="${classes}" /> <mkdir dir="${classes-cdc}" /> - <!-- Set up Java SE and Java CDC files --> - <antcall target="setup.javase" inheritRefs="true" /> - <antcall target="setup.javacdc" inheritRefs="true" /> - <!-- Create the classpath for ANTLR. This requires the user-defined - "antlr.jar" property. --> <path id="antlr.classpath"> @@ -434,7 +422,41 @@ <!-- - Build GlueGen. --> - <target name="gluegen.build" depends="init"> + <target name="pre-build"> + + <antcall target="create-map" inheritrefs="true"> + <param name="map.name" value="IntObjectHashMap"/> + <param name="map.value" value="Object"/> + <param name="map.null" value="null"/> + </antcall> + + <antcall target="create-map" inheritrefs="true"> + <param name="map.name" value="IntLongHashMap"/> + <param name="map.value" value="long"/> + <param name="map.null" value="0"/> + </antcall> + + </target> + + <target name="create-map"> + <!-- substitutes certain token in IntIntHashmap to create new primitive HasmMap--> + <copy file="${src.java}/com/jogamp/common/util/IntIntHashMap.java" + tofile="${src.generated.java}/com/jogamp/common/util/${map.name}.java" overwrite="true"> + <filterchain> + <replaceregex pattern="IntIntHashMap" replace="${map.name}"/> + <replaceregex pattern="@see ${map.name}" replace="@see IntIntHashMap"/> + <replaceregex pattern="/\*value\*/int/\*value\*/" replace="${map.value}"/> + <replaceregex pattern="/\*null\*/0/\*null\*/" replace="${map.null}"/> + </filterchain> + <!-- no clue why we have to do this twice... otherwise it will only replace one token per line --> + <filterchain> + <replaceregex pattern="/\*value\*/int/\*value\*/" replace="${map.value}"/> + </filterchain> + </copy> + </target> + + + <target name="gluegen.build" depends="init, pre-build"> <!-- Because ANTLR looks for importVocab files in the current working directory, it likes to have all of its files, including supergrammars, in one place, so copy all of the diff --git a/src/java/com/jogamp/common/util/IntIntHashMap.java b/src/java/com/jogamp/common/util/IntIntHashMap.java index 7a32654..6960161 100644 --- a/src/java/com/jogamp/common/util/IntIntHashMap.java +++ b/src/java/com/jogamp/common/util/IntIntHashMap.java @@ -31,32 +31,33 @@ package com.jogamp.common.util; /** - * Fast HashMap with int keys and int values. + * Fast HashMap for primitive data.. * Original code is based on the <a href="http://code.google.com/p/skorpios/"> skorpios project</a> * released under new BSD license. * @author Michael Bien * @see IntObjectHashMap + * @see IntLongHashMap */ -public class IntIntHashMap { +public class /*name*/IntIntHashMap/*name*/ { private final float loadFactor; private Entry[] table; - + private int size; private int mask; private int capacity; private int threshold; - public IntIntHashMap() { + public /*name*/IntIntHashMap/*name*/() { this(16, 0.75f); } - public IntIntHashMap(int initialCapacity) { + public /*name*/IntIntHashMap/*name*/(int initialCapacity) { this(initialCapacity, 0.75f); } - public IntIntHashMap(int initialCapacity, float loadFactor) { + public /*name*/IntIntHashMap/*name*/(int initialCapacity, float loadFactor) { if (initialCapacity > 1 << 30) { throw new IllegalArgumentException("initialCapacity is too large."); } @@ -76,7 +77,7 @@ public class IntIntHashMap { this.mask = capacity - 1; } - public boolean containsValue(int value) { + public boolean containsValue(/*value*/int/*value*/ value) { Entry[] table = this.table; for (int i = table.length; i-- > 0;) { for (Entry e = table[i]; e != null; e = e.next) { @@ -88,8 +89,8 @@ public class IntIntHashMap { return false; } - public boolean containsKey(int key) { - int index = key & mask; + public boolean containsKey(/*key*/int/*key*/ key) { + /*key*/int/*key*/ index = key & mask; for (Entry e = table[index]; e != null; e = e.next) { if (e.key == key) { return true; @@ -98,24 +99,24 @@ public class IntIntHashMap { return false; } - public int get(int key) { + public /*value*/int/*value*/ get(/*key*/int/*key*/ key) { int index = key & mask; for (Entry e = table[index]; e != null; e = e.next) { if (e.key == key) { return e.value; } } - return 0; + return /*null*/0/*null*/; } - public int put(int key, int value) { + public /*value*/int/*value*/ put(/*key*/int/*key*/ key, /*value*/int/*value*/ value) { int index = key & mask; // Check if key already exists. for (Entry e = table[index]; e != null; e = e.next) { if (e.key != key) { continue; } - int oldValue = e.value; + /*value*/int/*value*/ oldValue = e.value; e.value = value; return oldValue; } @@ -144,10 +145,10 @@ public class IntIntHashMap { threshold = (int) (newCapacity * loadFactor); mask = capacity - 1; } - return 0; + return /*null*/0/*null*/; } - public int remove(int key) { + public /*value*/int/*value*/ remove(/*key*/int/*key*/ key) { int index = key & mask; Entry prev = table[index]; Entry e = prev; @@ -165,7 +166,7 @@ public class IntIntHashMap { prev = e; e = next; } - return 0; + return /*null*/0/*null*/; } public int size() { @@ -182,11 +183,11 @@ public class IntIntHashMap { private final static class Entry { - private final int key; - private int value; + private final /*key*/int/*key*/ key; + private /*value*/int/*value*/ value; private Entry next; - private Entry(int k, int v, Entry n) { + private Entry(/*key*/int/*key*/ k, /*value*/int/*value*/ v, Entry n) { key = k; value = v; next = n; diff --git a/test/junit/com/jogamp/common/util/IntIntHashMapTest.java b/test/junit/com/jogamp/common/util/IntIntHashMapTest.java index 6ccf0e3..18eeef6 100644 --- a/test/junit/com/jogamp/common/util/IntIntHashMapTest.java +++ b/test/junit/com/jogamp/common/util/IntIntHashMapTest.java @@ -99,7 +99,7 @@ public class IntIntHashMapTest { long mapTime = (currentTimeMillis() - time); out.println(" map: " + mapTime+"ms"); - assertTrue(intmapTime < mapTime); + assertTrue(intmapTime <= mapTime); System.out.println(); @@ -115,7 +115,7 @@ public class IntIntHashMapTest { for (int i = 0; i < iterations; i++) { map.get(rndValues[i]); } - assertTrue(intmapTime < mapTime); + assertTrue(intmapTime <= mapTime); out.println(); @@ -132,7 +132,7 @@ public class IntIntHashMapTest { map.remove(rndValues[i]); } - assertTrue(intmapTime < mapTime); + assertTrue(intmapTime <= mapTime); } |