diff options
author | Sven Gothel <[email protected]> | 2011-06-26 17:31:21 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-06-26 17:31:21 +0200 |
commit | ad3dc39ccfddb007c3e91acf454f804573969419 (patch) | |
tree | 5dd5f4c5e1f0e1b0f220240c14c7f2cb69bcf46c /src/junit/com | |
parent | 334baf0e3b5aea862c443a7c78f4b54ccc1d1fb4 (diff) |
Fix HastMapTests - Clone: Use unique random pairs: key,value
Diffstat (limited to 'src/junit/com')
7 files changed, 284 insertions, 118 deletions
diff --git a/src/junit/com/jogamp/common/util/IntCloneable.java b/src/junit/com/jogamp/common/util/IntCloneable.java new file mode 100644 index 0000000..461589b --- /dev/null +++ b/src/junit/com/jogamp/common/util/IntCloneable.java @@ -0,0 +1,51 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.common.util; + +public class IntCloneable implements Cloneable { + private int i; + + public IntCloneable(int i) { this.i = i; } + + public int intValue() { return i; } + + @Override + public Object clone() { + return new IntCloneable(i); + } + + @Override + public boolean equals(Object obj) { + if(this == obj) { return true; } + if (obj instanceof IntCloneable) { + IntCloneable v = (IntCloneable)obj; + return i == v.i ; + } + return false; + } +} diff --git a/src/junit/com/jogamp/common/util/IntIntHashMapTest.java b/src/junit/com/jogamp/common/util/IntIntHashMapTest.java index bc03231..04f2d67 100644 --- a/src/junit/com/jogamp/common/util/IntIntHashMapTest.java +++ b/src/junit/com/jogamp/common/util/IntIntHashMapTest.java @@ -35,7 +35,6 @@ import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; -import java.util.Random; import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.*; @@ -49,25 +48,12 @@ import static java.lang.System.*; public class IntIntHashMapTest { private static int iterations; - private static int[] rndKeys; - private static int[] rndValues; + private static IntIntUniqueRndValues pairs; @BeforeClass public static void init() { - - iterations = 20000; - final int keySeed = 42; - final int valueSeed = 23; - - Random keyRnd = new Random(/*keySeed*/); - Random valueRnd = new Random(/*valueSeed*/); - - rndKeys = new int[iterations]; - rndValues = new int[iterations]; - for (int i = 0; i < iterations; i++) { - rndValues[i] = valueRnd.nextInt(); - rndKeys[i] = keyRnd.nextInt(); - } + iterations = 10000; + pairs = new IntIntUniqueRndValues(iterations); } /** @@ -81,14 +67,14 @@ public class IntIntHashMapTest { // put for (int i = 0; i < iterations; i++) { - intmap.put(rndKeys[i], rndValues[i]); + intmap.put(pairs.keys[i], pairs.values[i]); - assertTrue(intmap.containsValue(rndValues[i])); - assertTrue(intmap.containsKey(rndKeys[i])); + assertTrue(intmap.containsValue(pairs.values[i])); + assertTrue(intmap.containsKey(pairs.keys[i])); } for (int i = 0; i < iterations; i++) { - map.put(rndKeys[i], rndValues[i]); + map.put(pairs.keys[i], pairs.values[i]); } assertEquals(map.size(), intmap.size()); @@ -113,7 +99,7 @@ public class IntIntHashMapTest { final IntIntHashMap intmap = new IntIntHashMap(iterations); for (int i = 0; i < iterations; i++) { - intmap.put(rndKeys[i], rndValues[i]); + intmap.put(pairs.keys[i], pairs.values[i]); } Iterator<IntIntHashMap.Entry> iterator = intmap.iterator(); @@ -141,7 +127,7 @@ public class IntIntHashMapTest { intmap.setKeyNotFoundValue(-1); for (int i = 0; i < smallSize; i++) { - intmap.put(rndKeys[i], rndValues[i]); + intmap.put(pairs.keys[i], pairs.values[i]); } assertEquals(intmap.size(), smallSize); @@ -175,10 +161,10 @@ public class IntIntHashMapTest { assertEquals(intmapCopy.size(), n); for (int i = 0; i < smallSize; i++) { - assertTrue(intmap.containsValue(rndValues[i])); - assertTrue(intmap.containsKey(rndKeys[i])); - assertTrue(intmapCopy.containsValue(rndValues[i])); - assertTrue(intmapCopy.containsKey(rndKeys[i])); + assertTrue(intmap.containsValue(pairs.values[i])); + assertTrue(intmap.containsKey(pairs.keys[i])); + assertTrue(intmapCopy.containsValue(pairs.values[i])); + assertTrue(intmapCopy.containsKey(pairs.keys[i])); } // out.println(intmap); @@ -195,7 +181,7 @@ public class IntIntHashMapTest { assertEquals(intmap.capacity(), capacity); for (int i = 0; i < fixedSize; i++) { - intmap.put(rndKeys[i], rndValues[i]); + intmap.put(pairs.keys[i], pairs.values[i]); } assertEquals(intmap.size(), fixedSize); assertEquals(intmap.capacity(), capacity); @@ -233,10 +219,10 @@ public class IntIntHashMapTest { assertEquals(intmapCopy.capacity(), capacity); for (int i = 0; i < fixedSize; i++) { - assertTrue(intmap.containsValue(rndValues[i])); - assertTrue(intmap.containsKey(rndKeys[i])); - assertTrue(intmapCopy.containsValue(rndValues[i])); - assertTrue(intmapCopy.containsKey(rndKeys[i])); + assertTrue(intmap.containsValue(pairs.values[i])); + assertTrue(intmap.containsKey(pairs.keys[i])); + assertTrue(intmapCopy.containsValue(pairs.values[i])); + assertTrue(intmapCopy.containsKey(pairs.keys[i])); } // out.println(intmap); @@ -261,14 +247,14 @@ public class IntIntHashMapTest { out.println("put"); long time = nanoTime(); for (int i = 0; i < iterations; i++) { - intmap.put(rndKeys[i], rndValues[i]); + intmap.put(pairs.keys[i], pairs.values[i]); } long intmapPutTime = (nanoTime() - time); out.println(" iimap: " + intmapPutTime/1000000.0f+"ms"); time = nanoTime(); for (int i = 0; i < iterations; i++) { - map.put(rndKeys[i], rndValues[i]); + map.put(pairs.keys[i], pairs.values[i]); } long mapPutTime = (nanoTime() - time); out.println(" map: " + mapPutTime/1000000.0f+"ms"); @@ -278,14 +264,14 @@ public class IntIntHashMapTest { System.out.println("get"); time = nanoTime(); for (int i = 0; i < iterations; i++) { - intmap.get(rndKeys[i]); + intmap.get(pairs.keys[i]); } long intmapGetTime = (nanoTime() - time); out.println(" iimap: " + intmapGetTime/1000000.0f+"ms"); time = nanoTime(); for (int i = 0; i < iterations; i++) { - map.get(rndKeys[i]); + map.get(pairs.keys[i]); } long mapGetTime = (nanoTime() - time); out.println(" map: " + mapGetTime/1000000.0f+"ms"); @@ -295,7 +281,7 @@ public class IntIntHashMapTest { out.println("remove"); time = nanoTime(); for (int i = 0; i < iterations; i++) { - intmap.remove(rndKeys[i]); + intmap.remove(pairs.keys[i]); } assertEquals(0, intmap.size()); long intmapRemoveTime = (nanoTime() - time); @@ -303,7 +289,7 @@ public class IntIntHashMapTest { time = nanoTime(); for (int i = 0; i < iterations; i++) { - map.remove(rndKeys[i]); + map.remove(pairs.keys[i]); } assertEquals(0, map.size()); long mapRemoveTime = (nanoTime() - time); diff --git a/src/junit/com/jogamp/common/util/IntIntObjUniqueRndValues.java b/src/junit/com/jogamp/common/util/IntIntObjUniqueRndValues.java new file mode 100644 index 0000000..38ba352 --- /dev/null +++ b/src/junit/com/jogamp/common/util/IntIntObjUniqueRndValues.java @@ -0,0 +1,60 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +/** + * Created on Sunday, March 28 2010 21:01 + */ +package com.jogamp.common.util; + +import java.util.HashSet; +import java.util.Random; + +public class IntIntObjUniqueRndValues { + + public int[] keys; + public IntCloneable[] values; + + public IntIntObjUniqueRndValues(int size) { + // final int keySeed = 42; + // final int valueSeed = 23; + Random keyRnd = new Random(/*keySeed*/); + Random valueRnd = new Random(/*valueSeed*/); + + HashSet<Integer> uniqueKeys = new HashSet<Integer>(size); + keys = new int[size]; + values = new IntCloneable[size]; + while (uniqueKeys.size() < size) { + int k = keyRnd.nextInt(); + if( uniqueKeys.add( new Integer(k) ) ) { + final int i = uniqueKeys.size()-1; + keys[i] = k; + values[i] = new IntCloneable(valueRnd.nextInt()); + } + } + } +} diff --git a/src/junit/com/jogamp/common/util/IntIntUniqueRndValues.java b/src/junit/com/jogamp/common/util/IntIntUniqueRndValues.java new file mode 100644 index 0000000..07b222b --- /dev/null +++ b/src/junit/com/jogamp/common/util/IntIntUniqueRndValues.java @@ -0,0 +1,60 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +/** + * Created on Sunday, March 28 2010 21:01 + */ +package com.jogamp.common.util; + +import java.util.HashSet; +import java.util.Random; + +public class IntIntUniqueRndValues { + + public int[] keys; + public int[] values; + + public IntIntUniqueRndValues(int size) { + // final int keySeed = 42; + // final int valueSeed = 23; + Random keyRnd = new Random(/*keySeed*/); + Random valueRnd = new Random(/*valueSeed*/); + + HashSet<Integer> uniqueKeys = new HashSet<Integer>(size); + keys = new int[size]; + values = new int[size]; + while (uniqueKeys.size() < size) { + int k = keyRnd.nextInt(); + if( uniqueKeys.add( new Integer(k) ) ) { + final int i = uniqueKeys.size()-1; + keys[i] = k; + values[i] = valueRnd.nextInt(); + } + } + } +} diff --git a/src/junit/com/jogamp/common/util/IntObjectHashMapTest.java b/src/junit/com/jogamp/common/util/IntObjectHashMapTest.java index 289ff7e..8c4d9c8 100644 --- a/src/junit/com/jogamp/common/util/IntObjectHashMapTest.java +++ b/src/junit/com/jogamp/common/util/IntObjectHashMapTest.java @@ -35,7 +35,6 @@ import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; -import java.util.Random; import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.*; @@ -47,49 +46,13 @@ import static org.junit.Assert.*; */ public class IntObjectHashMapTest { - public static class IntCloneable implements Cloneable { - private int i; - - public IntCloneable(int i) { this.i = i; } - - public int intValue() { return i; } - - @Override - public Object clone() { - return new IntCloneable(i); - } - - @Override - public boolean equals(Object obj) { - if(this == obj) { return true; } - if (obj instanceof IntCloneable) { - IntCloneable v = (IntCloneable)obj; - return i == v.i ; - } - return false; - } - } - private static int iterations; - private static int[] rndKeys; - private static IntCloneable[] rndValues; + private static IntIntObjUniqueRndValues pairs; @BeforeClass public static void init() { - - iterations = 20000; - final int keySeed = 42; - final int valueSeed = 23; - - Random keyRnd = new Random(/*keySeed*/); - Random valueRnd = new Random(/*valueSeed*/); - - rndKeys = new int[iterations]; - rndValues = new IntCloneable[iterations]; - for (int i = 0; i < iterations; i++) { - rndValues[i] = new IntCloneable(valueRnd.nextInt()); - rndKeys[i] = keyRnd.nextInt(); - } + iterations = 10000; + pairs = new IntIntObjUniqueRndValues(iterations); } /** @@ -103,14 +66,14 @@ public class IntObjectHashMapTest { // put for (int i = 0; i < iterations; i++) { - intmap.put(rndKeys[i], rndValues[i]); + intmap.put(pairs.keys[i], pairs.values[i]); - assertTrue(intmap.containsValue(rndValues[i])); - assertTrue(intmap.containsKey(rndKeys[i])); + assertTrue(intmap.containsValue(pairs.values[i])); + assertTrue(intmap.containsKey(pairs.keys[i])); } for (int i = 0; i < iterations; i++) { - map.put(rndKeys[i], rndValues[i]); + map.put(pairs.keys[i], pairs.values[i]); } assertEquals(map.size(), intmap.size()); @@ -135,7 +98,7 @@ public class IntObjectHashMapTest { final IntObjectHashMap intmap = new IntObjectHashMap(iterations); for (int i = 0; i < iterations; i++) { - intmap.put(rndKeys[i], rndValues[i]); + intmap.put(pairs.keys[i], pairs.values[i]); } Iterator<IntObjectHashMap.Entry> iterator = intmap.iterator(); @@ -160,7 +123,7 @@ public class IntObjectHashMapTest { final IntObjectHashMap intmap = new IntObjectHashMap(iterations); for (int i = 0; i < iterations; i++) { - intmap.put(rndKeys[i], rndValues[i]); + intmap.put(pairs.keys[i], pairs.values[i]); } final IntObjectHashMap intmapCopy = (IntObjectHashMap) intmap.clone(); @@ -193,10 +156,10 @@ public class IntObjectHashMapTest { assertEquals(intmapCopy.size(), n); for (int i = 0; i < iterations; i++) { - assertTrue(intmap.containsValue(rndValues[i])); - assertTrue(intmap.containsKey(rndKeys[i])); - assertTrue(intmapCopy.containsValue(rndValues[i])); - assertTrue(intmapCopy.containsKey(rndKeys[i])); + assertTrue(intmap.containsValue(pairs.values[i])); + assertTrue(intmap.containsKey(pairs.keys[i])); + assertTrue(intmapCopy.containsValue(pairs.values[i])); + assertTrue(intmapCopy.containsKey(pairs.keys[i])); } // out.println(intmap); diff --git a/src/junit/com/jogamp/common/util/LongIntHashMapTest.java b/src/junit/com/jogamp/common/util/LongIntHashMapTest.java index 5b3f941..dccd8a3 100644 --- a/src/junit/com/jogamp/common/util/LongIntHashMapTest.java +++ b/src/junit/com/jogamp/common/util/LongIntHashMapTest.java @@ -35,7 +35,6 @@ import java.io.IOException; import java.util.Iterator; import java.util.HashMap; import java.util.Map.Entry; -import java.util.Random; import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.*; @@ -49,27 +48,14 @@ import static java.lang.System.*; public class LongIntHashMapTest { private static int iterations; - private static long[] rndKeys; - private static int[] rndValues; + private static LongIntUniqueRndValues pairs; @BeforeClass public static void init() { - - iterations = 20000; - final int keySeed = 42; - final int valueSeed = 23; - - Random keyRnd = new Random(/*keySeed*/); - Random valueRnd = new Random(/*valueSeed*/); - - rndKeys = new long[iterations]; - rndValues = new int[iterations]; - for (int i = 0; i < iterations; i++) { - rndValues[i] = valueRnd.nextInt(); - rndKeys[i] = keyRnd.nextLong(); - } - + iterations = 10000; + pairs = new LongIntUniqueRndValues(iterations); } + /** * Test of put method, of class LongIntHashMap. */ @@ -81,14 +67,14 @@ public class LongIntHashMapTest { // put for (int i = 0; i < iterations; i++) { - intmap.put(rndKeys[i], rndValues[i]); + intmap.put(pairs.keys[i], pairs.values[i]); - assertTrue(intmap.containsValue(rndValues[i])); - assertTrue(intmap.containsKey(rndKeys[i])); + assertTrue(intmap.containsValue(pairs.values[i])); + assertTrue(intmap.containsKey(pairs.keys[i])); } for (int i = 0; i < iterations; i++) { - map.put(rndKeys[i], rndValues[i]); + map.put(pairs.keys[i], pairs.values[i]); } assertEquals(map.size(), intmap.size()); @@ -113,10 +99,10 @@ public class LongIntHashMapTest { final LongIntHashMap map = new LongIntHashMap(iterations); for (int i = 0; i < iterations; i++) { - map.put(rndKeys[i], rndValues[i]); + map.put(pairs.keys[i], pairs.values[i]); } - Iterator iterator = map.iterator(); + Iterator<LongIntHashMap.Entry> iterator = map.iterator(); assertNotNull(iterator); assertTrue(iterator.hasNext()); @@ -150,7 +136,7 @@ public class LongIntHashMapTest { out.println("put"); long time = nanoTime(); for (int i = 0; i < iterations; i++) { - intmap.put(rndKeys[i], rndValues[i]); + intmap.put(pairs.keys[i], pairs.values[i]); } long intmapPutTime = (nanoTime() - time); out.println(" iimap: " + intmapPutTime/1000000.0f+"ms"); @@ -158,7 +144,7 @@ public class LongIntHashMapTest { time = nanoTime(); for (int i = 0; i < iterations; i++) { - map.put(rndKeys[i], rndValues[i]); + map.put(pairs.keys[i], pairs.values[i]); } long mapPutTime = (nanoTime() - time); out.println(" map: " + mapPutTime/1000000.0f+"ms"); @@ -168,14 +154,14 @@ public class LongIntHashMapTest { System.out.println("get"); time = nanoTime(); for (int i = 0; i < iterations; i++) { - intmap.get(rndKeys[i]); + intmap.get(pairs.keys[i]); } long intmapGetTime = (nanoTime() - time); out.println(" iimap: " + intmapGetTime/1000000.0f+"ms"); time = nanoTime(); for (int i = 0; i < iterations; i++) { - map.get(rndKeys[i]); + map.get(pairs.keys[i]); } long mapGetTime = (nanoTime() - time); out.println(" map: " + mapGetTime/1000000.0f+"ms"); @@ -185,7 +171,7 @@ public class LongIntHashMapTest { out.println("remove"); time = nanoTime(); for (int i = 0; i < iterations; i++) { - intmap.remove(rndKeys[i]); + intmap.remove(pairs.keys[i]); } assertEquals(0, intmap.size()); long intmapRemoveTime = (nanoTime() - time); @@ -193,7 +179,7 @@ public class LongIntHashMapTest { time = nanoTime(); for (int i = 0; i < iterations; i++) { - map.remove(rndKeys[i]); + map.remove(pairs.keys[i]); } assertEquals(0, map.size()); long mapRemoveTime = (nanoTime() - time); diff --git a/src/junit/com/jogamp/common/util/LongIntUniqueRndValues.java b/src/junit/com/jogamp/common/util/LongIntUniqueRndValues.java new file mode 100644 index 0000000..6ead167 --- /dev/null +++ b/src/junit/com/jogamp/common/util/LongIntUniqueRndValues.java @@ -0,0 +1,60 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +/** + * Created on Sunday, March 28 2010 21:01 + */ +package com.jogamp.common.util; + +import java.util.HashSet; +import java.util.Random; + +public class LongIntUniqueRndValues { + + public long[] keys; + public int[] values; + + public LongIntUniqueRndValues(int size) { + // final int keySeed = 42; + // final int valueSeed = 23; + Random keyRnd = new Random(/*keySeed*/); + Random valueRnd = new Random(/*valueSeed*/); + + HashSet<Long> uniqueKeys = new HashSet<Long>(size); + keys = new long[size]; + values = new int[size]; + while (uniqueKeys.size() < size) { + long k = keyRnd.nextLong(); + if( uniqueKeys.add( new Long(k) ) ) { + final int i = uniqueKeys.size()-1; + keys[i] = k; + values[i] = valueRnd.nextInt(); + } + } + } +} |