c)
{
super(c);
s = c;
@@ -554,21 +557,12 @@ public class MAPS
public static class SynchronizedNavigableMap KEY_VALUE_GENERIC_TYPE extends SynchronizedSortedMap KEY_VALUE_GENERIC_TYPE implements NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE {
NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map;
- /**
- * Default constructor
- * @param map the map that should be synchronized
- */
- public SynchronizedNavigableMap(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map) {
+ SynchronizedNavigableMap(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map) {
super(map);
this.map = map;
}
- /**
- * Constructor with Access Control
- * @param map the map that should be synchronized
- * @param mutex the access controller
- */
- public SynchronizedNavigableMap(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) {
+ SynchronizedNavigableMap(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) {
super(map, mutex);
this.map = map;
}
@@ -677,21 +671,12 @@ public class MAPS
public static class SynchronizedSortedMap KEY_VALUE_GENERIC_TYPE extends SynchronizedMap KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE {
SORTED_MAP KEY_VALUE_GENERIC_TYPE map;
- /**
- * Default constructor
- * @param map the map that should be synchronized
- */
- public SynchronizedSortedMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map) {
+ SynchronizedSortedMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map) {
super(map);
this.map = map;
}
- /**
- * Constructor with Access Control
- * @param map the map that should be synchronized
- * @param mutex the access controller
- */
- public SynchronizedSortedMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) {
+ SynchronizedSortedMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) {
super(map, mutex);
this.map = map;
}
@@ -760,21 +745,12 @@ public class MAPS
protected Object mutex;
- /**
- * Default constructor
- * @param map the map that should be synchronized
- */
- public SynchronizedMap(MAP KEY_VALUE_GENERIC_TYPE map) {
+ SynchronizedMap(MAP KEY_VALUE_GENERIC_TYPE map) {
this.map = map;
mutex = this;
}
- /**
- * Constructor with Access Control
- * @param map the map that should be synchronized
- * @param mutex the access controller
- */
- public SynchronizedMap(MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) {
+ SynchronizedMap(MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) {
this.map = map;
this.mutex = mutex;
}
diff --git a/src/main/java/speiger/src/collections/utils/HashUtil.java b/src/main/java/speiger/src/collections/utils/HashUtil.java
index ae816ddb..e3ae80e6 100644
--- a/src/main/java/speiger/src/collections/utils/HashUtil.java
+++ b/src/main/java/speiger/src/collections/utils/HashUtil.java
@@ -1,45 +1,90 @@
package speiger.src.collections.utils;
+/**
+ * Helper class that is used for HashMap functions reduce duplicated code
+ */
public class HashUtil
{
+ /** Minimum HashMap Capacity */
public static final int DEFAULT_MIN_CAPACITY = 16;
+ /** Default HashMap Load Factor */
public static final float DEFAULT_LOAD_FACTOR = 0.75F;
+ /** HashMap Load Factor with reduced hash collisions but more memory usage */
public static final float FAST_LOAD_FACTOR = 0.5F;
+ /** HashMap Load Factor with minimal hash collisions but more memory usage */
public static final float FASTER_LOAD_FACTOR = 0.25F;
+ /** 232 · φ, φ = (√5 − 1)/2. */
private static final int INT_PHI = 0x9E3779B9;
+ /** The reciprocal of {@link #INT_PHI} modulo 232. */
private static final int INV_INT_PHI = 0x144cbc89;
+ /** Quickly mixes the bits of an integer.
+ *
+ * This method mixes the bits of the argument by multiplying by the golden ratio and
+ * xorshifting the result. It is borrowed from Koloboke,
+ *
+ * @param x an integer.
+ * @return a hash value obtained by mixing the bits of {@code x}.
+ * @see #invMix(int)
+ */
public static int mix(final int x) {
final int h = x * INT_PHI;
return h ^ (h >>> 16);
}
+ /** The inverse of {@link #mix(int)}. This method is mainly useful to create unit tests.
+ *
+ * @param x an integer.
+ * @return a value that passed through {@link #mix(int)} would give {@code x}.
+ */
public static int invMix(final int x) {
return (x ^ x >>> 16) * INV_INT_PHI;
}
+ /**
+ * Function that rounds up to the closest power of 2
+ * A modified version of https://stackoverflow.com/a/466242
+ * @param x that should be converted to the next power of two
+ * @return the input number rounded up to the next power of two
+ */
public static int nextPowerOfTwo(int x) {
- if(x == 0) return 1;
- x--;
- x |= x >> 1;
- x |= x >> 2;
- x |= x >> 4;
- x |= x >> 8;
- return (x | x >> 16) + 1;
+ if(x != 0) {
+ x--;
+ x |= x >> 1;
+ x |= x >> 2;
+ x |= x >> 4;
+ x |= x >> 8;
+ x |= x >> 16;
+ }
+ return x + 1;
}
+ /**
+ * Function that rounds up to the closest power of 2
+ * A modified version of https://stackoverflow.com/a/466242
+ * @param x that should be converted to the next power of two
+ * @return the input number rounded up to the next power of two
+ */
public static long nextPowerOfTwo(long x) {
- if(x == 0) return 1L;
- x--;
- x |= x >> 1;
- x |= x >> 2;
- x |= x >> 4;
- x |= x >> 8;
- x |= x >> 16;
- return (x | x >> 32) + 1L;
+ if(x != 0) {
+ x--;
+ x |= x >> 1;
+ x |= x >> 2;
+ x |= x >> 4;
+ x |= x >> 8;
+ x |= x >> 16;
+ x |= x >> 32;
+ }
+ return x + 1L;
}
+ /**
+ * Helper function that creates the ideal array size for HashMap
+ * @param size the original array size
+ * @param loadFactor the load factor
+ * @return the new array size
+ */
public static int arraySize(int size, float loadFactor) {
return (int)Math.min(1 << 30, Math.max(2, nextPowerOfTwo((long)Math.ceil(size / loadFactor))));
}
diff --git a/src/main/java/speiger/src/collections/utils/SanityChecks.java b/src/main/java/speiger/src/collections/utils/SanityChecks.java
index 5fac5fd9..04285086 100644
--- a/src/main/java/speiger/src/collections/utils/SanityChecks.java
+++ b/src/main/java/speiger/src/collections/utils/SanityChecks.java
@@ -10,6 +10,7 @@ import java.util.concurrent.ForkJoinTask;
*/
public class SanityChecks
{
+ /** Max Possible ArraySize without the JVM Crashing */
public static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
private static ForkJoinPool WORK_POOL = ForkJoinPool.commonPool();
private static boolean FORCE_IGNORE_PARALLELISM = false;
diff --git a/src/test/java/speiger/src/collections/ints/utils/SortingTests.java b/src/test/java/speiger/src/collections/ints/utils/SortingTests.java
index 75aaf2f0..6b272124 100644
--- a/src/test/java/speiger/src/collections/ints/utils/SortingTests.java
+++ b/src/test/java/speiger/src/collections/ints/utils/SortingTests.java
@@ -1,10 +1,7 @@
package speiger.src.collections.ints.utils;
import java.util.Arrays;
-import java.util.Spliterators;
import java.util.stream.IntStream;
-import java.util.stream.Stream;
-import java.util.stream.StreamSupport;
import org.junit.Assert;
import org.junit.Test;