Permalink
Browse files

Some work on PrimLong hashmap

  • Loading branch information...
tzaeschke committed May 4, 2017
1 parent 1084ba6 commit 33f0db602a8e7115fdacdfad1f47be38af7cac9e
Showing with 261 additions and 0 deletions.
  1. +94 −0 .settings/org.eclipse.jdt.core.prefs
  2. +167 −0 src/org/zoodb/internal/util/PrimLongMapZ.java
@@ -1,12 +1,106 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,167 @@
package org.zoodb.internal.util;
import java.util.Collection;
import java.util.Set;
public class PrimLongMapZ<T> implements PrimLongMap<T> {
private static class Entry<T> implements PrimLongEntry<T> {
final long key;
T value;
Entry<T> next = null;
Entry(long key, T value) {
this.key = key;
this.value = value;
}
@Override
public long getKey() {
return key;
}
@Override
public T getValue() {
return value;
}
}
private static final double LOAD_FACTOR = 0.75;
private Entry<T>[] entries;
private int capacityPower = 6;
//capacity = 2^capacityPower
//TODO do we need a field for that?
private int capacity = 1 << capacityPower;
private int limitMax = (int) (capacity * LOAD_FACTOR);
private int size = 0;
private int modCount = 0;
public PrimLongMapZ() {
entries = new Entry[capacity];
}
private int calcHash(long key) {
//This works well with primes:
//return (int) key % capacity;
//Knuths multiplicative hash function
return (int)(key * 2654435761L) >> (32 - capacityPower);
}
private void checkRehash(int newSize) {
if (newSize > limitMax && capacityPower < 31) {
capacityPower++;
capacity = 1 << capacityPower;
limitMax = (int) (capacity * LOAD_FACTOR);
Entry<T>[] oldEntries = entries;
entries = new Entry[capacity];
for (int i = 0; i < oldEntries.length; i++) {
Entry<T> e = oldEntries[i];
while (e != null) {
putEntryNoCheck(e);
e = e.next;
}
}
}
}
private void putEntryNoCheck(Entry<T> e) {
int pos = calcHash(e.key);
e.next = entries[pos];
entries[pos] = e;
}
@Override
public T get(long keyBits) {
int pos = calcHash(keyBits);
Entry<T> e = entries[pos];
while (e != null && e.key != keyBits) {
e = e.next;
}
return e == null ? null : e.value;
}
@Override
public T put(long keyBits, T obj) {
int pos = calcHash(keyBits);
Entry<T> e = entries[pos];
while (e != null && e.key != keyBits) {
e = e.next;
}
modCount++;
if (e != null) {
T ret = e.value;
e.value = obj;
return ret;
}
checkRehash(size + 1);
putEntryNoCheck(new Entry<T>(keyBits, obj));
size++;
return null;
}
@Override
public T remove(long keyBits) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
//return null;
}
@Override
public int size() {
return size;
}
@Override
public Collection<T> values() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
//return null;
}
@Override
public void clear() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
//
}
@Override
public boolean containsKey(long keyBits) {
int pos = calcHash(keyBits);
Entry<T> e = entries[pos];
while (e != null && e.key != keyBits) {
e = e.next;
}
return e != null;
}
@Override
public boolean containsValue(T value) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
//return false;
}
@Override
public void putAll(PrimLongMap<? extends T> map) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
//
}
@Override
public Set<Long> keySet() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
//return null;
}
@Override
public Set<PrimLongEntry<T>> entrySet() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
//return null;
}
}

0 comments on commit 33f0db6

Please sign in to comment.