Synced first part of the next update
This commit is contained in:
parent
2a2d9e8d95
commit
29ddc55947
@ -6,12 +6,6 @@
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/test" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="test"/>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
org.gradle.jvmargs=-Xmx3G
|
||||
|
||||
maxMemory = 1024m
|
||||
testThreads = 2
|
||||
maxMemory = 2048m
|
||||
testThreads = 4
|
||||
@ -128,6 +128,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
for(int i = 0,m=modules.size();i<m;i++) {
|
||||
modules.get(i).setManager(manager);
|
||||
}
|
||||
manager.resolve();
|
||||
for(int i = 0,m=modules.size();i<m;i++) {
|
||||
biPackages.forEach(modules.get(i)::init);
|
||||
}
|
||||
|
||||
@ -1,54 +1,100 @@
|
||||
package speiger.src.builder;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.internal.Streams;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.IDependency.LoadingState;
|
||||
import speiger.src.builder.modules.BaseModule;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class SettingsManager
|
||||
{
|
||||
boolean loaded;
|
||||
Map<String, LoadingState> parsedData = new TreeMap<>();
|
||||
JsonObject data = new JsonObject();
|
||||
Set<String> moduleNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
|
||||
Set<IDependency> allDependencies = new LinkedHashSet<>();
|
||||
|
||||
public boolean isModuleEnabled(BaseModule base, ClassType keyType, ClassType valueType) {
|
||||
if(!loaded) return true;
|
||||
if(!isEnabled(data, base.getModuleName())) return false;
|
||||
JsonObject result = getObject(data, keyType.getClassPath(), false);
|
||||
if(!isEnabled(result, "Enabled")) return false;
|
||||
if(base.isBiModule()) {
|
||||
result = getObject(result, valueType.getClassPath(), false);
|
||||
if(!isEnabled(result, "Enabled")) return false;
|
||||
public void resolve() {
|
||||
if(!loaded) return;
|
||||
Set<IDependency> roots = new LinkedHashSet<>();
|
||||
Set<IDependency> leafs = new LinkedHashSet<>();
|
||||
for(IDependency entry : allDependencies) {
|
||||
if(entry.isRoot()) {
|
||||
roots.add(entry);
|
||||
}
|
||||
if(entry.isLeaf()) {
|
||||
leafs.add(entry);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This has to be 2 iteration passes.
|
||||
* Due to Key Value Pairs, first pass does all initials keys, and the second pass processes the values.
|
||||
* May require more passes but extremely unlikely
|
||||
*/
|
||||
for(int i = 0;i<2;i++) {
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
for(IDependency entry : roots) {
|
||||
entry.resolveRequirements(keyType, valueType);
|
||||
}
|
||||
}
|
||||
}
|
||||
result = getObject(result, base.getModuleName(), false);
|
||||
return (result.size() <= 0 || isEnabled(result, "Enabled")) && base.areDependenciesLoaded();
|
||||
}
|
||||
|
||||
public boolean isModuleEnabled(BaseModule base, ClassType keyType, ClassType valueType, String entry)
|
||||
{
|
||||
if(!loaded) return true;
|
||||
if(!isEnabled(data, base.getModuleName())) return false;
|
||||
JsonObject result = getObject(data, keyType.getClassPath(), false);
|
||||
if(!isEnabled(result, "Enabled")) return false;
|
||||
if(base.isBiModule()) {
|
||||
result = getObject(result, valueType.getClassPath(), false);
|
||||
if(!isEnabled(result, "Enabled")) return false;
|
||||
List<String> errors = new ArrayList<>();
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
for(IDependency entry : leafs) {
|
||||
entry.validateDependency(errors::add, keyType, valueType);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(errors.size() > 0) {
|
||||
throw new IllegalStateException("Issues with dependencies found: "+String.join("\n", errors));
|
||||
}
|
||||
result = getObject(result, base.getModuleName(), false);
|
||||
return (result.size() <= 0 || (isEnabled(result, "Enabled") && isEnabled(result, entry))) && base.areDependenciesLoaded();
|
||||
}
|
||||
|
||||
public void addModule(BaseModule module) {
|
||||
if(loaded) return;
|
||||
if(loaded) {
|
||||
if(module.isBiModule()) {
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, valueType)) continue;
|
||||
for(IDependency dependency : module.getDependencies(keyType, valueType)) {
|
||||
dependency.set(parsedData);
|
||||
allDependencies.add(dependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, keyType)) continue;
|
||||
for(IDependency dependency : module.getDependencies(keyType, keyType)) {
|
||||
dependency.set(parsedData);
|
||||
allDependencies.add(dependency);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
String moduleName = module.getModuleName();
|
||||
moduleNames.add(moduleName);
|
||||
data.addProperty(moduleName, true);
|
||||
@ -57,9 +103,9 @@ public class SettingsManager
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, valueType)) continue;
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.addProperty("Enabled", true);
|
||||
for(String key : module.getModuleKeys(keyType, valueType)) {
|
||||
obj.addProperty(key, true);
|
||||
for(IDependency dependency : module.getDependencies(keyType, valueType)) {
|
||||
String key = dependency.getName();
|
||||
if(key != null) obj.addProperty(key, true);
|
||||
}
|
||||
addModule(keyType, valueType, true, moduleName, obj);
|
||||
}
|
||||
@ -69,18 +115,61 @@ public class SettingsManager
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, keyType)) continue;
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.addProperty("Enabled", true);
|
||||
for(String key : module.getModuleKeys(keyType, keyType)) {
|
||||
obj.addProperty(key, true);
|
||||
for(IDependency dependency : module.getDependencies(keyType, keyType)) {
|
||||
String key = dependency.getName();
|
||||
if(key != null) obj.addProperty(key, true);
|
||||
}
|
||||
addModule(keyType, keyType, false, moduleName, obj);
|
||||
}
|
||||
}
|
||||
|
||||
public void printModuleSettings(List<BaseModule> modules) {
|
||||
JsonObject data = new JsonObject();
|
||||
for(BaseModule module : modules) {
|
||||
String moduleName = module.getModuleName();
|
||||
if(module.isBiModule()) {
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, valueType)) continue;
|
||||
JsonObject obj = new JsonObject();
|
||||
for(IDependency dependency : module.getDependencies(keyType, valueType)) {
|
||||
String key = dependency.getName();
|
||||
if(key != null) obj.addProperty(key, dependency.isLoaded(keyType, valueType).getJsonResult());
|
||||
}
|
||||
addModule(data, keyType, valueType, true, moduleName, obj);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, keyType)) continue;
|
||||
JsonObject obj = new JsonObject();
|
||||
for(IDependency dependency : module.getDependencies(keyType, keyType)) {
|
||||
String key = dependency.getName();
|
||||
if(key != null) obj.addProperty(key, dependency.isLoaded(keyType, keyType).getJsonResult());
|
||||
}
|
||||
addModule(data, keyType, keyType, false, moduleName, obj);
|
||||
}
|
||||
}
|
||||
try {
|
||||
System.out.println();
|
||||
JsonWriter writer = new JsonWriter(new OutputStreamWriter(System.out));
|
||||
writer.setIndent("\t");
|
||||
Streams.write(data, writer);
|
||||
writer.flush();
|
||||
System.out.println();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
try(BufferedReader reader = Files.newBufferedReader(Paths.get("ModulSettings.json"))) {
|
||||
data = JsonParser.parseReader(reader).getAsJsonObject();
|
||||
loaded = true;
|
||||
IDependency.flatten("", false, data, parsedData);
|
||||
JsonElement element = data.get("Default");
|
||||
LoadingState.setOptionalResolver(LoadingState.of(element == null ? true : element.getAsBoolean()));
|
||||
}
|
||||
catch(Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
@ -100,6 +189,14 @@ public class SettingsManager
|
||||
catch(Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
private void addModule(JsonObject data, ClassType keyType, ClassType valueType, boolean bi, String moduleName, JsonObject obj) {
|
||||
JsonObject result = getObject(data, keyType.getClassPath(), true);
|
||||
if(bi) {
|
||||
result = getObject(result, valueType.getClassPath(), true);
|
||||
}
|
||||
result.add(moduleName, obj);
|
||||
}
|
||||
|
||||
private void addModule(ClassType keyType, ClassType valueType, boolean bi, String moduleName, JsonObject obj) {
|
||||
JsonObject result = getObject(data, keyType.getClassPath(), true);
|
||||
if(bi) {
|
||||
@ -117,9 +214,4 @@ public class SettingsManager
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
private boolean isEnabled(JsonObject obj, String key) {
|
||||
if(obj.has(key)) return obj.getAsJsonPrimitive(key).getAsBoolean();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,137 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.TreeSet;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.Requirements.Requirement;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public abstract class BaseDependency implements IDependency {
|
||||
protected static boolean FETCH_FAILURES = false;
|
||||
protected static Set<String> FAILURE_KEYS = new TreeSet<>();
|
||||
|
||||
protected final String name;
|
||||
protected final boolean biType;
|
||||
protected Map<String, LoadingState> dependencies;
|
||||
protected List<IDependency> children = new ArrayList<>();
|
||||
protected List<Requirement> requirements = new ArrayList<>();
|
||||
protected ClassType keyType;
|
||||
protected ClassType valueType;
|
||||
|
||||
public BaseDependency(String name, boolean biType) {
|
||||
this.name = name;
|
||||
this.biType = biType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Map<String, LoadingState> dependency) {
|
||||
dependencies = dependency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDependency addDependency(Requirement require) {
|
||||
requirements.add(require);
|
||||
require.dependency.addChild(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChild(IDependency child) {
|
||||
children.add(child);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaf() {
|
||||
return children.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRoot() {
|
||||
return requirements.isEmpty();
|
||||
}
|
||||
|
||||
protected LoadingState getGlobalState() {
|
||||
return dependencies.getOrDefault(name, LoadingState.OPTIONAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalStateKey(ClassType keyType, ClassType valueType) {
|
||||
return (biType ? keyType.getClassPath()+"-"+valueType.getClassPath() : keyType.getClassPath())+"-"+name;
|
||||
}
|
||||
|
||||
protected LoadingState getLocalState(ClassType keyType, ClassType valueType) {
|
||||
return dependencies.getOrDefault(getLocalStateKey(keyType, valueType), LoadingState.OPTIONAL);
|
||||
}
|
||||
|
||||
protected LoadingState getReqirementState(ClassType keyType, ClassType valueType) {
|
||||
LoadingState state = requirements.isEmpty() ? LoadingState.REQUIRED : LoadingState.OPTIONAL;
|
||||
for(int i = 0,m=requirements.size();i<m;i++) {
|
||||
state = state.merge(requirements.get(i).test(keyType, valueType));
|
||||
}
|
||||
return state.resolveIfUndefined();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveRequirements(ClassType keyType, ClassType valueType) {
|
||||
if(!children.isEmpty()) {
|
||||
for(IDependency child : children) {
|
||||
if(child == this) continue;
|
||||
child.resolveRequirements(keyType, valueType);
|
||||
}
|
||||
}
|
||||
if(getLocalState(keyType, valueType) == LoadingState.REQUIRED) {
|
||||
for(Requirement req : requirements) {
|
||||
dependencies.putIfAbsent(req.key(keyType, valueType), LoadingState.REQUIRED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateDependency(Consumer<String> result, ClassType keyType, ClassType valueType) {
|
||||
if(getLocalState(keyType, valueType) == LoadingState.REQUIRED) {
|
||||
FETCH_FAILURES = true;
|
||||
for(Requirement req : requirements) {
|
||||
req.test(keyType, valueType);
|
||||
}
|
||||
FETCH_FAILURES = false;
|
||||
if(FAILURE_KEYS.size() > 0) {
|
||||
int size = FAILURE_KEYS.size();
|
||||
StringJoiner joiner = new StringJoiner("], [", "[", "]");
|
||||
FAILURE_KEYS.forEach(joiner::add);
|
||||
FAILURE_KEYS.clear();
|
||||
String joins = size > 1 ? "["+joiner.toString()+"]" : joiner.toString();
|
||||
|
||||
result.accept("["+getLocalStateKey(keyType, valueType)+"] Requires "+joins+" but it specifically has been disabled!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(ClassType key, ClassType value) {
|
||||
this.keyType = key;
|
||||
this.valueType = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
if(keyType == null || keyType == null) return false;
|
||||
return isLoaded(keyType, valueType).getJsonResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FunctionDependency extends BaseDependency {
|
||||
ModuleDependency owner;
|
||||
|
||||
public FunctionDependency(ModuleDependency owner, String name) {
|
||||
super(name, owner.biType);
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoadingState isLoaded(ClassType key, ClassType value) {
|
||||
if(dependencies == null) return LoadingState.REQUIRED;
|
||||
LoadingState result = getLocalState(key, value);
|
||||
if(FETCH_FAILURES && result == LoadingState.REJECTED) {
|
||||
FAILURE_KEYS.add(getLocalStateKey(key, value));
|
||||
}
|
||||
return result.resolveIfUndefined().merge(getReqirementState(key, value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalStateKey(ClassType keyType, ClassType valueType) {
|
||||
return (biType ? keyType.getClassPath()+"-"+valueType.getClassPath() : keyType.getClassPath())+"-"+owner.getName()+"-"+name;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.Requirements.Requirement;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public interface IDependency {
|
||||
|
||||
|
||||
public void set(Map<String, LoadingState> dependency);
|
||||
public void set(ClassType key, ClassType value);
|
||||
public LoadingState isLoaded(ClassType key, ClassType value);
|
||||
public String getLocalStateKey(ClassType keyType, ClassType valueType);
|
||||
public boolean isEnabled();
|
||||
public boolean isLeaf();
|
||||
public boolean isRoot();
|
||||
|
||||
public String getName();
|
||||
public void validateDependency(Consumer<String> result, ClassType keyType, ClassType valueType);
|
||||
public void resolveRequirements(ClassType keyType, ClassType valueType);
|
||||
|
||||
public void addChild(IDependency child);
|
||||
public <T extends IDependency> T addDependency(Requirement require);
|
||||
public default <T extends IDependency> T addKeyDependency(IDependency dependency) { return addDependency(new Requirement(dependency, Requirements.KEY_TEST, Requirements.KEY_GETTER)); }
|
||||
public default <T extends IDependency> T addValueDependency(IDependency dependency) { return addDependency(new Requirement(dependency, Requirements.VALUE_TEST, Requirements.VALUE_GETTER)); }
|
||||
public default <T extends IDependency> T addEntryDependency(IDependency dependency) { return addDependency(new Requirement(dependency, Requirements.ENTRY_TEST, Requirements.ENTRY_GETTER)); }
|
||||
public default <T extends IDependency> T addTypeDependency(IDependency dependency, ClassType type) { return addDependency(new Requirement(dependency, Requirements.typedTest(type), Requirements.typedKey(type))); }
|
||||
public default <T extends IDependency> T addOptionalTypeDependency(IDependency dependency, ClassType type, boolean key) { return addDependency(new Requirement(dependency, Requirements.optionalTest(type, key), Requirements.optionalKey(type, key))); }
|
||||
public default <T extends IDependency> T addOptionalTypeDependency(ClassType type, boolean key) { return addDependency(new Requirement(this, Requirements.optionalTest(type, key), Requirements.optionalKey(type, key))); }
|
||||
|
||||
|
||||
public static void flatten(String prefix, boolean applyMiddle, JsonObject object, Map<String, LoadingState> result) {
|
||||
if(applyMiddle) prefix+="-";
|
||||
for(Entry<String, JsonElement> entry : object.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
JsonElement value = entry.getValue();
|
||||
if(value instanceof JsonPrimitive) {
|
||||
String entryKey = prefix+key;
|
||||
if("Enabled".equalsIgnoreCase(key)) {
|
||||
entryKey = prefix.substring(0, prefix.length()-1);
|
||||
}
|
||||
result.put(entryKey, LoadingState.of(((JsonPrimitive)value).getAsBoolean()));
|
||||
}
|
||||
if(value instanceof JsonObject) {
|
||||
flatten(prefix+key, true, (JsonObject)value, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static enum LoadingState {
|
||||
OPTIONAL,
|
||||
REQUIRED,
|
||||
REJECTED;
|
||||
|
||||
private static LoadingState RESOLVED = LoadingState.REQUIRED;
|
||||
|
||||
public static LoadingState of(boolean value) {
|
||||
return value ? REQUIRED : REJECTED;
|
||||
}
|
||||
|
||||
public LoadingState merge(LoadingState merge) {
|
||||
return ordinal() > merge.ordinal() ? this : merge;
|
||||
}
|
||||
|
||||
public LoadingState replaceIfUndefined(LoadingState state) {
|
||||
return this == OPTIONAL ? state : this;
|
||||
}
|
||||
|
||||
public LoadingState resolveIfUndefined() {
|
||||
return this == OPTIONAL ? RESOLVED : this;
|
||||
}
|
||||
|
||||
public LoadingState mergeDown(LoadingState merge) {
|
||||
if(merge == REJECTED || ordinal() > merge.ordinal()) {
|
||||
return this;
|
||||
}
|
||||
return merge;
|
||||
}
|
||||
|
||||
public LoadingState mergeUp(LoadingState merge) {
|
||||
if(merge == REQUIRED || ordinal() > merge.ordinal()) {
|
||||
return this;
|
||||
}
|
||||
return merge;
|
||||
}
|
||||
|
||||
public static void setOptionalResolver(LoadingState state) {
|
||||
RESOLVED = state;
|
||||
}
|
||||
|
||||
public boolean getJsonResult() {
|
||||
LoadingState state = this == OPTIONAL ? RESOLVED : this;
|
||||
return state == REQUIRED;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.modules.BaseModule;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ModuleDependency extends BaseDependency {
|
||||
BaseModule owner;
|
||||
|
||||
public ModuleDependency(BaseModule owner, boolean biType) {
|
||||
super(owner.getModuleName(), biType);
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public FunctionDependency createDependency(String name) {
|
||||
FunctionDependency result = new FunctionDependency(this, name);
|
||||
if(biType) result.addEntryDependency(this);
|
||||
else result.addKeyDependency(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoadingState isLoaded(ClassType key, ClassType value) {
|
||||
if(dependencies == null) return LoadingState.REQUIRED;
|
||||
LoadingState result = getLocalState(key, value);
|
||||
if(FETCH_FAILURES && result == LoadingState.REJECTED) {
|
||||
FAILURE_KEYS.add(getLocalStateKey(key, value));
|
||||
}
|
||||
return result.replaceIfUndefined(getGlobalState()).resolveIfUndefined().merge(getReqirementState(key, value));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.IDependency.LoadingState;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class Requirements {
|
||||
public static final RequirementTest KEY_TEST = (T, K, V) -> T.isLoaded(K, K);
|
||||
public static final RequirementTest VALUE_TEST = (T, K, V) -> T.isLoaded(V, V);
|
||||
public static final RequirementTest ENTRY_TEST = (T, K, V) -> T.isLoaded(K, V);
|
||||
|
||||
public static RequirementTest typedTest(ClassType type) {
|
||||
return (T, K, V) -> T.isLoaded(type, type);
|
||||
}
|
||||
|
||||
public static RequirementTest optionalTest(ClassType type, boolean key) {
|
||||
return (T, K, V) -> (key ? K : V) != type ? T.isLoaded(type, type) : LoadingState.REQUIRED;
|
||||
}
|
||||
|
||||
public static final RequirementKey KEY_GETTER = (T, K, V) -> T.getLocalStateKey(K, K);
|
||||
public static final RequirementKey VALUE_GETTER = (T, K, V) -> T.getLocalStateKey(V, V);
|
||||
public static final RequirementKey ENTRY_GETTER = (T, K, V) -> T.getLocalStateKey(K, V);
|
||||
|
||||
public static RequirementKey typedKey(ClassType type) {
|
||||
return (T, K, V) -> T.getLocalStateKey(type, type);
|
||||
}
|
||||
|
||||
public static RequirementKey optionalKey(ClassType type, boolean key) {
|
||||
return (T, K, V) -> (key ? K : V) != type ? T.getLocalStateKey(type, type) : "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface RequirementTest {
|
||||
public LoadingState test(IDependency test, ClassType keyType, ClassType valueType);
|
||||
}
|
||||
|
||||
public static interface RequirementKey {
|
||||
public String key(IDependency test, ClassType keyType, ClassType valueType);
|
||||
}
|
||||
|
||||
public static interface RequirementResolver {
|
||||
public void resolve(IDependency test, Consumer<String> result, ClassType keyType, ClassType valueType);
|
||||
}
|
||||
|
||||
public static class Requirement {
|
||||
IDependency dependency;
|
||||
RequirementTest test;
|
||||
RequirementKey key;
|
||||
|
||||
public Requirement(IDependency dependency, RequirementTest test, RequirementKey key) {
|
||||
this.dependency = dependency;
|
||||
this.test = test;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public LoadingState test(ClassType keyType, ClassType valueType) {
|
||||
return test.test(dependency, keyType, valueType);
|
||||
}
|
||||
|
||||
public String key(ClassType keyType, ClassType valueType) {
|
||||
return key.key(dependency, keyType, valueType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,17 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class AsyncModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new AsyncModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(JavaModule.MODULE);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Async"; }
|
||||
@ -16,16 +24,16 @@ public class AsyncModule extends BaseModule
|
||||
@Override
|
||||
protected void loadFunctions() {}
|
||||
@Override
|
||||
public boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); }
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE); }
|
||||
@Override
|
||||
protected void loadBlockades() {
|
||||
if(!isModuleEnabled()) {
|
||||
if(!MODULE.isEnabled()) {
|
||||
addBlockedFiles("AsyncBuilder", "Task");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(isModuleEnabled()) {
|
||||
if(MODULE.isEnabled()) {
|
||||
addKeyFlag("ASYNC_MODULE");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.ModulePackage;
|
||||
import speiger.src.builder.RequiredType;
|
||||
import speiger.src.builder.SettingsManager;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.mappers.ArgumentMapper;
|
||||
import speiger.src.builder.mappers.InjectMapper;
|
||||
import speiger.src.builder.mappers.LineMapper;
|
||||
@ -30,6 +32,9 @@ public abstract class BaseModule
|
||||
this.entry = entry;
|
||||
keyType = entry.getKeyType();
|
||||
valueType = entry.getValueType();
|
||||
for(IDependency dependency : getDependencies(keyType, valueType)) {
|
||||
dependency.set(keyType, valueType);
|
||||
}
|
||||
loadVariables();
|
||||
loadClasses();
|
||||
loadTestClasses();
|
||||
@ -56,32 +61,12 @@ public abstract class BaseModule
|
||||
|
||||
public abstract String getModuleName();
|
||||
public boolean isBiModule() { return false; }
|
||||
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) { return Collections.emptySet(); }
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Collections.emptyList(); }
|
||||
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return true; }
|
||||
|
||||
public ClassType keyType() { return keyType; }
|
||||
public ClassType valueType() { return valueType; }
|
||||
|
||||
protected boolean isModuleEnabled() {
|
||||
return manager == null || manager.isModuleEnabled(this, keyType, valueType);
|
||||
}
|
||||
|
||||
protected boolean isModuleEnabled(String name) {
|
||||
return manager == null || manager.isModuleEnabled(this, keyType, valueType, name);
|
||||
}
|
||||
|
||||
protected boolean isDependencyLoaded(BaseModule module) {
|
||||
return isDependencyLoaded(module, true);
|
||||
}
|
||||
|
||||
protected boolean isDependencyLoaded(BaseModule module, boolean key) {
|
||||
return manager == null || (module.isBiModule() ? manager.isModuleEnabled(module, keyType, valueType) : (key ? manager.isModuleEnabled(module, keyType, keyType) : manager.isModuleEnabled(module, valueType, valueType)));
|
||||
}
|
||||
|
||||
public boolean areDependenciesLoaded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void addFlag(String name) {
|
||||
entry.addFlag(name);
|
||||
}
|
||||
@ -205,4 +190,9 @@ public abstract class BaseModule
|
||||
entry.addMapper(mapper);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
public static <T> T make(T input, Consumer<T> processor) {
|
||||
processor.accept(input);
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,52 +1,59 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class CollectionModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new CollectionModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false)
|
||||
.addKeyDependency(FunctionModule.MODULE)
|
||||
.addOptionalTypeDependency(FunctionModule.MODULE, ClassType.OBJECT, true)
|
||||
.addOptionalTypeDependency(FunctionModule.MODULE, ClassType.INT, true)
|
||||
.addOptionalTypeDependency(ClassType.OBJECT, true);
|
||||
public static final FunctionDependency STREAMS = MODULE.createDependency("Streams");
|
||||
public static final FunctionDependency SPLIT_ITERATORS = MODULE.createDependency("Splititerators").addKeyDependency(STREAMS);
|
||||
public static final FunctionDependency IARRAY = MODULE.createDependency("IArray");
|
||||
public static final FunctionDependency STRATEGY = MODULE.createDependency("Strategy");
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Collection"; }
|
||||
@Override
|
||||
protected void loadVariables() {}
|
||||
@Override
|
||||
public boolean areDependenciesLoaded(){ return isDependencyLoaded(JavaModule.INSTANCE); }
|
||||
|
||||
@Override
|
||||
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType)
|
||||
{
|
||||
return new TreeSet<>(Arrays.asList("Streams", "Splititerators", "IArray", "Strategy"));
|
||||
}
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, STREAMS, SPLIT_ITERATORS, IARRAY, STRATEGY); }
|
||||
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(isModuleEnabled()) addKeyFlag("COLLECTION_MODULE");
|
||||
if(isModuleEnabled("Streams")) addKeyFlag("STREAM_FEATURE");
|
||||
if(isModuleEnabled("Splititerators")) addKeyFlag("SPLIT_ITERATOR_FEATURE");
|
||||
if(isModuleEnabled("IArray")) addKeyFlag("IARRAY_FEATURE");
|
||||
if(MODULE.isEnabled()) addKeyFlag("COLLECTION_MODULE");
|
||||
if(STREAMS.isEnabled()) addKeyFlag("STREAM_FEATURE");
|
||||
if(SPLIT_ITERATORS.isEnabled()) addKeyFlag("SPLIT_ITERATOR_FEATURE");
|
||||
if(IARRAY.isEnabled()) addKeyFlag("IARRAY_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades() {
|
||||
if(!isModuleEnabled()) {
|
||||
if(!MODULE.isEnabled()) {
|
||||
addBlockedFiles("Iterable", "Iterables", "Iterator", "Iterators", "BidirectionalIterator", "ListIterator");
|
||||
addBlockedFiles("Arrays", "Collection", "AbstractCollection", "Collections", "Stack");
|
||||
addBlockedFiles("Arrays", "Collection", "OrderedCollection", "AbstractCollection", "Collections", "Stack");
|
||||
}
|
||||
if(!isModuleEnabled("Splititerators")) addBlockedFiles("Splititerator", "Splititerators");
|
||||
if(!isModuleEnabled("IArray")) addBlockedFiles("IArray");
|
||||
if(!isModuleEnabled("Strategy")) addBlockedFiles("Strategy");
|
||||
if(!SPLIT_ITERATORS.isEnabled()) addBlockedFiles("Splititerator", "Splititerators");
|
||||
if(!IARRAY.isEnabled()) addBlockedFiles("IArray");
|
||||
if(!STRATEGY.isEnabled()) addBlockedFiles("Strategy");
|
||||
|
||||
if(keyType.isObject()) {
|
||||
if(keyType.isObject())
|
||||
{
|
||||
addBlockedFiles("Stack");
|
||||
addBlockedFiles("CollectionStreamTester");
|
||||
}
|
||||
if(keyType == ClassType.BOOLEAN) {
|
||||
if(keyType == ClassType.BOOLEAN)
|
||||
{
|
||||
addBlockedFiles("CollectionRemoveIfTester", "CollectionStreamTester");
|
||||
addBlockedFilter(T -> T.endsWith("Tester") && T.startsWith("Iterable"));
|
||||
}
|
||||
@ -84,6 +91,7 @@ public class CollectionModule extends BaseModule
|
||||
{
|
||||
//Abstract Classes
|
||||
addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection");
|
||||
addAbstractMapper("REVERSED_ORDERED_COLLECTION", "Reverse%sOrderedCollection");
|
||||
|
||||
//Helper Classes
|
||||
addClassMapper("ARRAYS", "Arrays");
|
||||
@ -94,6 +102,7 @@ public class CollectionModule extends BaseModule
|
||||
|
||||
//Interfaces
|
||||
addClassMapper("COLLECTION", "Collection");
|
||||
addClassMapper("ORDERED_COLLECTION", "OrderedCollection");
|
||||
addClassMapper("ITERABLE", "Iterable");
|
||||
addClassMapper("SPLIT_ITERATOR", "Splititerator");
|
||||
addClassMapper("LIST_ITERATOR", "ListIterator");
|
||||
|
||||
@ -1,12 +1,18 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.RequiredType;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FunctionModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new FunctionModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(JavaModule.MODULE);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Function"; }
|
||||
@ -19,10 +25,16 @@ public class FunctionModule extends BaseModule
|
||||
@Override
|
||||
protected void loadTestClasses() {}
|
||||
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) {
|
||||
return Arrays.asList(MODULE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades()
|
||||
{
|
||||
if(keyType.isObject()) addBlockedFiles("Consumer", "Comparator");
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("Consumer", "BiConsumer", "Comparator", "Supplier", "Function", "UnaryOperator");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,11 +1,17 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class JavaModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new JavaModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Base"; }
|
||||
@ -17,6 +23,11 @@ public class JavaModule extends BaseModule
|
||||
loadBaseVariables();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) {
|
||||
return Arrays.asList(MODULE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFlags()
|
||||
{
|
||||
@ -185,6 +196,7 @@ public class JavaModule extends BaseModule
|
||||
addComment("@Type", "@param <%s> the keyType of elements maintained by this Collection");
|
||||
addValueComment("@ValueArrayType", "@param <%s> the keyType of array that the operation should be applied");
|
||||
addValueComment("@ValueType", "@param <%s> the keyType of elements maintained by this Collection");
|
||||
addSimpleMapper("@Java21", getVersion() >= 21 ? "@Override" : "");
|
||||
addAnnontion("@PrimitiveOverride", "@Override");
|
||||
addSimpleMapper("@PrimitiveDoc", "");
|
||||
addAnnontion("@Primitive", "@Deprecated");
|
||||
|
||||
@ -1,55 +1,57 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ListModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new ListModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(CollectionModule.MODULE).addKeyDependency(CollectionModule.SPLIT_ITERATORS);
|
||||
public static final FunctionDependency IMPLEMENTATION = MODULE.createDependency("Implementations");
|
||||
public static final FunctionDependency WRAPPERS = MODULE.createDependency("Wrappers");
|
||||
public static final FunctionDependency ARRAY_LIST = MODULE.createDependency("ArrayList").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_LIST = MODULE.createDependency("LinkedList").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency IMMUTABLE_LIST = MODULE.createDependency("ImmutableList").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency COPY_ON_WRITE_LIST = MODULE.createDependency("CopyOnWriteList").addKeyDependency(IMPLEMENTATION);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "List"; }
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, IMPLEMENTATION, WRAPPERS, ARRAY_LIST, LINKED_LIST, IMMUTABLE_LIST, COPY_ON_WRITE_LIST); }
|
||||
@Override
|
||||
protected void loadVariables() {}
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(isModuleEnabled()) addKeyFlag("LIST_MODULE");
|
||||
if(isModuleEnabled("Wrappers")) addKeyFlag("LISTS_FEATURE");
|
||||
boolean implementations = isModuleEnabled("Implementations");
|
||||
if(implementations && isModuleEnabled("ArrayList")) addKeyFlag("ARRAY_LIST_FEATURE");
|
||||
if(implementations && isModuleEnabled("LinkedList")) addKeyFlag("LINKED_LIST_FEATURE");
|
||||
if(implementations && isModuleEnabled("ImmutableList")) addKeyFlag("IMMUTABLE_LIST_FEATURE");
|
||||
if(implementations && isModuleEnabled("CopyOnWriteList")) addKeyFlag("COPY_ON_WRITE_LIST_FEATURE");
|
||||
if(MODULE.isEnabled()) addKeyFlag("LIST_MODULE");
|
||||
if(WRAPPERS.isEnabled()) addKeyFlag("LISTS_FEATURE");
|
||||
if(ARRAY_LIST.isEnabled()) addKeyFlag("ARRAY_LIST_FEATURE");
|
||||
if(LINKED_LIST.isEnabled()) addKeyFlag("LINKED_LIST_FEATURE");
|
||||
if(IMMUTABLE_LIST.isEnabled()) addKeyFlag("IMMUTABLE_LIST_FEATURE");
|
||||
if(COPY_ON_WRITE_LIST.isEnabled()) addKeyFlag("COPY_ON_WRITE_LIST_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades()
|
||||
{
|
||||
if(!isModuleEnabled("Wrappers")) addBlockedFiles("Lists");
|
||||
boolean implementations = !isModuleEnabled("Implementations");
|
||||
if(implementations || !isModuleEnabled("ArrayList")) addBlockedFiles("ArrayList");
|
||||
if(implementations || !isModuleEnabled("LinkedList")) addBlockedFiles("LinkedList");
|
||||
if(implementations || !isModuleEnabled("ImmutableList")) addBlockedFiles("ImmutableList");
|
||||
if(implementations || !isModuleEnabled("CopyOnWriteList")) addBlockedFiles("CopyOnWriteList");
|
||||
if(!isModuleEnabled()) addBlockedFiles("List", "AbstractList");
|
||||
if(!WRAPPERS.isEnabled()) addBlockedFiles("Lists");
|
||||
if(!ARRAY_LIST.isEnabled()) addBlockedFiles("ArrayList");
|
||||
if(!LINKED_LIST.isEnabled()) addBlockedFiles("LinkedList");
|
||||
if(!IMMUTABLE_LIST.isEnabled()) addBlockedFiles("ImmutableList");
|
||||
if(!COPY_ON_WRITE_LIST.isEnabled()) addBlockedFiles("CopyOnWriteList");
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("List", "AbstractList");
|
||||
|
||||
|
||||
if(keyType.isObject()) addBlockedFiles("ListFillBufferTester");
|
||||
if(keyType == ClassType.BOOLEAN) addBlockedFiles("ListFillBufferTester", "ListReplaceAllTester");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
|
||||
return new TreeSet<>(Arrays.asList("Implementations", "Wrappers", "ArrayList", "LinkedList", "ImmutableList", "CopyOnWriteList"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areDependenciesLoaded() {
|
||||
return isDependencyLoaded(CollectionModule.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadRemappers()
|
||||
|
||||
@ -1,15 +1,44 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class MapModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new MapModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, true)
|
||||
.addKeyDependency(SetModule.MODULE)
|
||||
.addValueDependency(CollectionModule.MODULE)
|
||||
.addEntryDependency(SetModule.MODULE)
|
||||
.addTypeDependency(SetModule.MODULE, ClassType.OBJECT);
|
||||
public static final FunctionDependency IMPLEMENTATION = MODULE.createDependency("Implementations");
|
||||
public static final FunctionDependency WRAPPERS = MODULE.createDependency("Wrappers").addKeyDependency(SetModule.WRAPPERS).addOptionalTypeDependency(SetModule.WRAPPERS, ClassType.OBJECT, true);
|
||||
|
||||
public static final FunctionDependency ORDERED_MAP = MODULE.createDependency("OrderedMap").addKeyDependency(SetModule.ORDERED_SET).addOptionalTypeDependency(SetModule.ORDERED_SET, ClassType.OBJECT, true);
|
||||
public static final FunctionDependency SORTED_MAP = MODULE.createDependency("SortedMap").addKeyDependency(SetModule.SORTED_SET).addOptionalTypeDependency(SetModule.SORTED_SET, ClassType.OBJECT, true);
|
||||
|
||||
public static final FunctionDependency ARRAY_MAP = MODULE.createDependency("ArrayMap").addEntryDependency(ORDERED_MAP).addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency IMMUTABLE_MAP = MODULE.createDependency("ImmutableMap").addEntryDependency(IMPLEMENTATION);
|
||||
|
||||
public static final FunctionDependency HASH_MAP = MODULE.createDependency("HashMap").addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_MAP = MODULE.createDependency("LinkedHashMap").addEntryDependency(HASH_MAP).addEntryDependency(ORDERED_MAP);
|
||||
|
||||
public static final FunctionDependency CUSTOM_MAP = MODULE.createDependency("CustomHashMap").addEntryDependency(IMPLEMENTATION).addKeyDependency(CollectionModule.STRATEGY);
|
||||
public static final FunctionDependency LINKED_CUSTOM_MAP = MODULE.createDependency("LinkedCustomHashMap").addEntryDependency(CUSTOM_MAP).addEntryDependency(ORDERED_MAP);
|
||||
|
||||
public static final FunctionDependency ENUM_MAP = MODULE.createDependency("EnumMap").addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_ENUM_MAP = MODULE.createDependency("LinkedEnumMap").addEntryDependency(ENUM_MAP).addEntryDependency(ORDERED_MAP);
|
||||
|
||||
public static final FunctionDependency CONCURRENT_MAP = MODULE.createDependency("ConcurrentMap").addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency AVL_TREE_MAP = MODULE.createDependency("AVLTreeMap").addEntryDependency(SORTED_MAP).addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency RB_TREE_MAP = MODULE.createDependency("RBTreeMap").addEntryDependency(SORTED_MAP).addEntryDependency(IMPLEMENTATION);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Map"; }
|
||||
@ -20,79 +49,52 @@ public class MapModule extends BaseModule
|
||||
@Override
|
||||
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return keyType != ClassType.BOOLEAN; }
|
||||
@Override
|
||||
public boolean areDependenciesLoaded() { return isDependencyLoaded(SetModule.INSTANCE) && isDependencyLoaded(CollectionModule.INSTANCE, false); }
|
||||
|
||||
@Override
|
||||
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
|
||||
Set<String> sets = new TreeSet<>();
|
||||
sets.addAll(Arrays.asList("Wrappers", "Implementations"));
|
||||
sets.addAll(Arrays.asList("OrderedMap", "SortedMap"));
|
||||
sets.addAll(Arrays.asList("ArrayMap", "ConcurrentMap", "ImmutableMap"));
|
||||
sets.addAll(Arrays.asList("HashMap", "LinkedHashMap"));
|
||||
sets.addAll(Arrays.asList("CustomHashMap", "LinkedCustomHashMap"));
|
||||
sets.addAll(Arrays.asList("EnumMap", "LinkedEnumMap"));
|
||||
sets.addAll(Arrays.asList("AVLTreeMap", "RBTreeMap"));
|
||||
return sets;
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) {
|
||||
List<IDependency> dependencies = new ArrayList<>(Arrays.asList(MODULE, ORDERED_MAP, SORTED_MAP, IMPLEMENTATION, WRAPPERS, ARRAY_MAP, IMMUTABLE_MAP, HASH_MAP, LINKED_MAP, CUSTOM_MAP, LINKED_CUSTOM_MAP, CONCURRENT_MAP, AVL_TREE_MAP, RB_TREE_MAP));
|
||||
if(keyType == ClassType.OBJECT) dependencies.addAll(Arrays.asList(ENUM_MAP, LINKED_ENUM_MAP));
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFlags()
|
||||
{
|
||||
if(isModuleEnabled()) addFlag("MAP_MODULE");
|
||||
if(isModuleEnabled("Wrappers")) addFlag("MAPS_FEATURE");
|
||||
boolean implementations = isModuleEnabled("Implementations");
|
||||
boolean hashMap = implementations && isModuleEnabled("HashMap");
|
||||
boolean customHashMap = implementations && isModuleEnabled("CustomHashMap");
|
||||
boolean enumMap = implementations && isModuleEnabled("EnumMap");
|
||||
if(MODULE.isEnabled()) addFlag("MAP_MODULE");
|
||||
if(WRAPPERS.isEnabled()) addFlag("MAPS_FEATURE");
|
||||
if(ORDERED_MAP.isEnabled()) addFlag("ORDERED_MAP_FEATURE");
|
||||
if(ARRAY_MAP.isEnabled()) addFlag("ARRAY_MAP_FEATURE");
|
||||
if(LINKED_MAP.isEnabled()) addFlag("LINKED_MAP_FEATURE");
|
||||
if(LINKED_CUSTOM_MAP.isEnabled()) addFlag("LINKED_CUSTOM_MAP_FEATURE");
|
||||
if(LINKED_ENUM_MAP.isEnabled()) addFlag("LINKED_ENUM_MAP_FEATURE");
|
||||
|
||||
if(isModuleEnabled("OrderedMap")) {
|
||||
addFlag("ORDERED_MAP_FEATURE");
|
||||
if(isModuleEnabled("ArrayMap")) addFlag("ARRAY_MAP_FEATURE");
|
||||
if(hashMap && isModuleEnabled("LinkedHashMap")) addFlag("LINKED_MAP_FEATURE");
|
||||
if(customHashMap && isModuleEnabled("LinkedCustomHashMap")) addFlag("LINKED_CUSTOM_MAP_FEATURE");
|
||||
if(enumMap && isModuleEnabled("LinkedEnumMap")) addFlag("LINKED_ENUM_MAP_FEATURE");
|
||||
}
|
||||
if(isModuleEnabled("SortedMap")) {
|
||||
addFlag("SORTED_MAP_FEATURE");
|
||||
if(implementations && isModuleEnabled("AVLTreeMap")) addFlag("AVL_TREE_MAP_FEATURE");
|
||||
if(implementations && isModuleEnabled("RBTreeMap")) addFlag("RB_TREE_MAP_FEATURE");
|
||||
}
|
||||
if(implementations && isModuleEnabled("ConcurrentMap")) addFlag("CONCURRENT_MAP_FEATURE");
|
||||
if(implementations && isModuleEnabled("ImmutableMap")) addFlag("IMMUTABLE_MAP_FEATURE");
|
||||
if(hashMap) addFlag("MAP_FEATURE");
|
||||
if(customHashMap) addFlag("CUSTOM_MAP_FEATURE");
|
||||
if(enumMap) addFlag("ENUM_MAP_FEATURE");
|
||||
if(SORTED_MAP.isEnabled()) addFlag("SORTED_MAP_FEATURE");
|
||||
if(AVL_TREE_MAP.isEnabled()) addFlag("AVL_TREE_MAP_FEATURE");
|
||||
if(RB_TREE_MAP.isEnabled()) addFlag("RB_TREE_MAP_FEATURE");
|
||||
|
||||
if(CONCURRENT_MAP.isEnabled()) addFlag("CONCURRENT_MAP_FEATURE");
|
||||
if(IMMUTABLE_MAP.isEnabled()) addFlag("IMMUTABLE_MAP_FEATURE");
|
||||
if(HASH_MAP.isEnabled()) addFlag("MAP_FEATURE");
|
||||
if(CUSTOM_MAP.isEnabled()) addFlag("CUSTOM_MAP_FEATURE");
|
||||
if(ENUM_MAP.isEnabled()) addFlag("ENUM_MAP_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades()
|
||||
{
|
||||
if(!isModuleEnabled()) addBlockedFiles("Map", "AbstractMap");
|
||||
if(!isModuleEnabled("Wrappers")) addBlockedFiles("Maps");
|
||||
boolean implementations = !isModuleEnabled("Implementations");
|
||||
if(implementations || !isModuleEnabled("ImmutableMap")) addBlockedFiles("ImmutableOpenHashMap");
|
||||
if(implementations || !isModuleEnabled("ConcurrentMap")) addBlockedFiles("ConcurrentMap", "ConcurrentOpenHashMap");
|
||||
|
||||
boolean ordered = !isModuleEnabled("OrderedMap");
|
||||
if(ordered) addBlockedFiles("OrderedMap");
|
||||
boolean hashMap = implementations || !isModuleEnabled("HashMap");
|
||||
if(hashMap) addBlockedFiles("OpenHashMap");
|
||||
if(hashMap || ordered || !isModuleEnabled("LinkedHashMap")) addBlockedFiles("LinkedOpenHashMap");
|
||||
|
||||
boolean customHashMap = implementations || !isModuleEnabled("CustomHashMap");
|
||||
if(customHashMap) addBlockedFiles("OpenCustomHashMap");
|
||||
if(customHashMap || ordered || !isModuleEnabled("LinkedCustomHashMap")) addBlockedFiles("LinkedOpenCustomHashMap");
|
||||
|
||||
boolean enumMap = implementations || !isModuleEnabled("EnumMap");
|
||||
if(enumMap) addBlockedFiles("EnumMap");
|
||||
if(enumMap || ordered || !isModuleEnabled("LinkedEnumMap")) addBlockedFiles("LinkedEnumMap");
|
||||
|
||||
if(ordered || !isModuleEnabled("ArrayMap")) addBlockedFiles("ArrayMap");
|
||||
|
||||
boolean sorted = !isModuleEnabled("SortedMap");
|
||||
if(sorted) addBlockedFiles("SortedMap", "NavigableMap");
|
||||
if(implementations || sorted || !isModuleEnabled("AVLTreeMap")) addBlockedFiles("AVLTreeMap");
|
||||
if(implementations || sorted || !isModuleEnabled("RBTreeMap")) addBlockedFiles("RBTreeMap");
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("Map", "AbstractMap");
|
||||
if(!WRAPPERS.isEnabled()) addBlockedFiles("Maps");
|
||||
if(!IMMUTABLE_MAP.isEnabled()) addBlockedFiles("ImmutableOpenHashMap");
|
||||
if(!CONCURRENT_MAP.isEnabled()) addBlockedFiles("ConcurrentMap", "ConcurrentOpenHashMap");
|
||||
if(!ORDERED_MAP.isEnabled()) addBlockedFiles("OrderedMap");
|
||||
if(!HASH_MAP.isEnabled()) addBlockedFiles("OpenHashMap");
|
||||
if(!LINKED_MAP.isEnabled()) addBlockedFiles("LinkedOpenHashMap");
|
||||
if(!CUSTOM_MAP.isEnabled()) addBlockedFiles("OpenCustomHashMap");
|
||||
if(!LINKED_CUSTOM_MAP.isEnabled()) addBlockedFiles("LinkedOpenCustomHashMap");
|
||||
if(!ENUM_MAP.isEnabled()) addBlockedFiles("EnumMap");
|
||||
if(!LINKED_ENUM_MAP.isEnabled()) addBlockedFiles("LinkedEnumMap");
|
||||
if(!ARRAY_MAP.isEnabled()) addBlockedFiles("ArrayMap");
|
||||
if(!SORTED_MAP.isEnabled()) addBlockedFiles("SortedMap", "NavigableMap");
|
||||
if(!AVL_TREE_MAP.isEnabled()) addBlockedFiles("AVLTreeMap");
|
||||
if(!RB_TREE_MAP.isEnabled()) addBlockedFiles("RBTreeMap");
|
||||
|
||||
if(keyType == ClassType.BOOLEAN)
|
||||
{
|
||||
@ -251,6 +253,7 @@ public class MapModule extends BaseModule
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "2");
|
||||
addAbstractBiMapper("REVERSED_ORDERED_MAP", "Reversed%sOrderedMap", "2");
|
||||
|
||||
//Helper Classes
|
||||
addBiClassMapper("MAPS", "Maps", "2");
|
||||
|
||||
@ -1,15 +1,26 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class PairModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new PairModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, true).addKeyDependency(JavaModule.MODULE);
|
||||
public static final FunctionDependency IMMUTABLE = MODULE.createDependency("Immutable");
|
||||
public static final FunctionDependency MUTABLE = MODULE.createDependency("Mutable");
|
||||
|
||||
|
||||
// public static final DependencyModule MODULE = new BiTypeModule(INSTANCE);
|
||||
// public static final DependencyFunction IMMUTABLE = MODULE.createFunction("Immutable");
|
||||
// public static final DependencyFunction MUTABLE = MODULE.createFunction("Mutable");
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Pair"; }
|
||||
@Override
|
||||
@ -21,20 +32,20 @@ public class PairModule extends BaseModule
|
||||
@Override
|
||||
protected void loadTestClasses() {}
|
||||
@Override
|
||||
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) { return new TreeSet<>(Arrays.asList("Mutable", "Immutable")); }
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, IMMUTABLE, MUTABLE); }
|
||||
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(isModuleEnabled()) addFlag("PAIR_MODULE");
|
||||
if(isModuleEnabled("Mutable")) addFlag("MUTABLE_PAIR");
|
||||
if(isModuleEnabled("Immutable")) addFlag("IMMUTABLE_PAIR");
|
||||
if(MODULE.isEnabled()) addFlag("PAIR_MODULE");
|
||||
if(MUTABLE.isEnabled()) addFlag("MUTABLE_PAIR");
|
||||
if(IMMUTABLE.isEnabled()) addFlag("IMMUTABLE_PAIR");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades() {
|
||||
if(!isModuleEnabled()) addBlockedFiles("Pair");
|
||||
if(!isModuleEnabled("Mutable")) addBlockedFiles("MutablePair");
|
||||
if(!isModuleEnabled("Immutable")) addBlockedFiles("ImmutablePair");
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("Pair");
|
||||
if(!MUTABLE.isEnabled()) addBlockedFiles("MutablePair");
|
||||
if(!IMMUTABLE.isEnabled()) addBlockedFiles("ImmutablePair");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,15 +1,26 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class PrioQueueModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new PrioQueueModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(CollectionModule.MODULE);
|
||||
public static final FunctionDependency IMPLEMENTATION = MODULE.createDependency("Implementations");
|
||||
public static final FunctionDependency WRAPPERS = MODULE.createDependency("Wrappers");
|
||||
public static final FunctionDependency DEQUEUE = MODULE.createDependency("Dequeue");
|
||||
|
||||
public static final FunctionDependency FIFO_QUEUE = MODULE.createDependency("FiFoQueue").addKeyDependency(DEQUEUE).addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency HEAP_QUEUE = MODULE.createDependency("HeapQueue").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency ARRAY_PRIO_QUEUE = MODULE.createDependency("ArrayPrioQueue").addKeyDependency(IMPLEMENTATION);
|
||||
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "PriorityQueue"; }
|
||||
@ -18,36 +29,26 @@ public class PrioQueueModule extends BaseModule
|
||||
@Override
|
||||
protected void loadFunctions() {}
|
||||
@Override
|
||||
public boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); }
|
||||
|
||||
@Override
|
||||
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
|
||||
return new TreeSet<>(Arrays.asList("Wrappers", "Implementations", "Dequeue", "FiFoQueue", "HeapQueue", "ArrayPrioQueue"));
|
||||
}
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, WRAPPERS, IMPLEMENTATION, DEQUEUE, FIFO_QUEUE, HEAP_QUEUE, ARRAY_PRIO_QUEUE); }
|
||||
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(isModuleEnabled()) addFlag("QUEUE_MODULE");
|
||||
if(isModuleEnabled("Wrappers")) addKeyFlag("QUEUES_FEATURE");
|
||||
boolean implementations = isModuleEnabled("Implementations");
|
||||
if(isModuleEnabled("Dequeue")) {
|
||||
addKeyFlag("DEQUEUE_FEATURE");
|
||||
if(implementations && isModuleEnabled("FiFoQueue")) addKeyFlag("FIFO_QUEUE_FEATURE");
|
||||
}
|
||||
if(implementations && isModuleEnabled("HeapQueue")) addKeyFlag("HEAP_QUEUE_FEATURE");
|
||||
if(implementations && isModuleEnabled("ArrayPrioQueue")) addKeyFlag("ARRAY_QUEUE_FEATURE");
|
||||
if(MODULE.isEnabled()) addFlag("QUEUE_MODULE");
|
||||
if(WRAPPERS.isEnabled()) addKeyFlag("QUEUES_FEATURE");
|
||||
if(DEQUEUE.isEnabled()) addKeyFlag("DEQUEUE_FEATURE");
|
||||
if(FIFO_QUEUE.isEnabled()) addKeyFlag("FIFO_QUEUE_FEATURE");
|
||||
if(HEAP_QUEUE.isEnabled()) addKeyFlag("HEAP_QUEUE_FEATURE");
|
||||
if(ARRAY_PRIO_QUEUE.isEnabled()) addKeyFlag("ARRAY_QUEUE_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades() {
|
||||
if(!isModuleEnabled()) addBlockedFiles("PriorityQueue", "AbstractPriorityQueue");
|
||||
if(!isModuleEnabled("Wrappers")) addBlockedFiles("PriorityQueues");
|
||||
boolean implementations = !isModuleEnabled("Implementations");
|
||||
boolean dequeue = !isModuleEnabled("Dequeue");
|
||||
if(dequeue) addBlockedFiles("PriorityDequeue");
|
||||
if(dequeue || implementations || !isModuleEnabled("FiFoQueue")) addBlockedFiles("ArrayFIFOQueue");
|
||||
if(implementations || !isModuleEnabled("HeapQueue")) addBlockedFiles("HeapPriorityQueue");
|
||||
if(implementations || !isModuleEnabled("ArrayPrioQueue")) addBlockedFiles("ArrayPriorityQueue");
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("PriorityQueue", "AbstractPriorityQueue");
|
||||
if(!WRAPPERS.isEnabled()) addBlockedFiles("PriorityQueues");
|
||||
if(!DEQUEUE.isEnabled()) addBlockedFiles("PriorityDequeue");
|
||||
if(!FIFO_QUEUE.isEnabled()) addBlockedFiles("ArrayFIFOQueue");
|
||||
if(!HEAP_QUEUE.isEnabled()) addBlockedFiles("HeapPriorityQueue");
|
||||
if(!ARRAY_PRIO_QUEUE.isEnabled()) addBlockedFiles("ArrayPriorityQueue");
|
||||
|
||||
if(keyType == ClassType.BOOLEAN) {
|
||||
addBlockedFiles("QueueTests");
|
||||
|
||||
@ -1,15 +1,30 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class SetModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new SetModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(CollectionModule.MODULE).addKeyDependency(CollectionModule.SPLIT_ITERATORS);
|
||||
public static final FunctionDependency IMPLEMENTATION = MODULE.createDependency("Implementations");
|
||||
public static final FunctionDependency WRAPPERS = MODULE.createDependency("Wrappers");
|
||||
public static final FunctionDependency ORDERED_SET = MODULE.createDependency("OrderedSet");
|
||||
public static final FunctionDependency SORTED_SET = MODULE.createDependency("SortedSet");
|
||||
public static final FunctionDependency ARRAY_SET = MODULE.createDependency("ArraySet").addKeyDependency(ORDERED_SET).addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency IMMUTABLE_SET = MODULE.createDependency("ImmutableSet").addKeyDependency(ORDERED_SET).addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency HASH_SET = MODULE.createDependency("HashSet").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_SET = MODULE.createDependency("LinkedHashSet").addKeyDependency(ORDERED_SET).addKeyDependency(HASH_SET);
|
||||
public static final FunctionDependency CUSTOM_SET = MODULE.createDependency("CustomHashSet").addKeyDependency(IMPLEMENTATION).addKeyDependency(CollectionModule.STRATEGY);
|
||||
public static final FunctionDependency LINKED_CUSTOM_SET = MODULE.createDependency("LinkedCustomHashSet").addKeyDependency(ORDERED_SET).addKeyDependency(CUSTOM_SET);
|
||||
public static final FunctionDependency AVL_TREE_SET = MODULE.createDependency("AVLTreeSet").addKeyDependency(SORTED_SET).addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency RB_TREE_SET = MODULE.createDependency("RBTreeSet").addKeyDependency(SORTED_SET).addKeyDependency(IMPLEMENTATION);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Set"; }
|
||||
@ -19,68 +34,40 @@ public class SetModule extends BaseModule
|
||||
@Override
|
||||
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return keyType != ClassType.BOOLEAN; }
|
||||
@Override
|
||||
public boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); }
|
||||
@Override
|
||||
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
|
||||
Set<String> sets = new TreeSet<>();
|
||||
sets.addAll(Arrays.asList("Wrappers", "Implementations"));
|
||||
sets.addAll(Arrays.asList("OrderedSet", "SortedSet"));
|
||||
sets.addAll(Arrays.asList("ArraySet", "ImmutableSet"));
|
||||
sets.addAll(Arrays.asList("HashSet", "LinkedHashSet"));
|
||||
sets.addAll(Arrays.asList("CustomHashSet", "LinkedCustomHashSet"));
|
||||
sets.addAll(Arrays.asList("AVLTreeSet", "RBTreeSet"));
|
||||
return sets;
|
||||
}
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, WRAPPERS, ORDERED_SET, SORTED_SET, IMPLEMENTATION, ARRAY_SET, IMMUTABLE_SET, HASH_SET, LINKED_SET, CUSTOM_SET, LINKED_CUSTOM_SET, AVL_TREE_SET, RB_TREE_SET); }
|
||||
|
||||
@Override
|
||||
protected void loadFlags()
|
||||
{
|
||||
if(isModuleEnabled()) addFlag("SET_MODULE");
|
||||
if(isModuleEnabled("Wrappers")) addFlag("SETS_FEATURE");
|
||||
boolean implementations = isModuleEnabled("Implementations");
|
||||
boolean hashSet = implementations && isModuleEnabled("HashSet");
|
||||
boolean customHashSet = implementations && isModuleEnabled("CustomHashSet");
|
||||
|
||||
if(isModuleEnabled("OrderedSet")) {
|
||||
addFlag("ORDERED_SET_FEATURE");
|
||||
if(implementations && isModuleEnabled("ArraySet")) addFlag("ARRAY_SET_FEATURE");
|
||||
if(hashSet && isModuleEnabled("LinkedHashSet")) addFlag("LINKED_SET_FEATURE");
|
||||
if(customHashSet && isModuleEnabled("LinkedCustomHashSet")) addFlag("LINKED_CUSTOM_SET_FEATURE");
|
||||
}
|
||||
if(isModuleEnabled("SortedSet")) {
|
||||
addFlag("SORTED_SET_FEATURE");
|
||||
if(implementations && isModuleEnabled("AVLTreeSet")) addFlag("AVL_TREE_SET_FEATURE");
|
||||
if(implementations && isModuleEnabled("RBTreeSet")) addFlag("RB_TREE_SET_FEATURE");
|
||||
}
|
||||
if(implementations && isModuleEnabled("ImmutableSet")) addFlag("IMMUTABLE_SET_FEATURE");
|
||||
if(hashSet) addFlag("HASH_SET_FEATURE");
|
||||
if(customHashSet) addFlag("CUSTOM_HASH_SET_FEATURE");
|
||||
if(MODULE.isEnabled()) addFlag("SET_MODULE");
|
||||
if(WRAPPERS.isEnabled()) addFlag("SETS_FEATURE");
|
||||
if(ORDERED_SET.isEnabled()) addFlag("ORDERED_SET_FEATURE");
|
||||
if(SORTED_SET.isEnabled()) addFlag("SORTED_SET_FEATURE");
|
||||
if(IMMUTABLE_SET.isEnabled()) addFlag("IMMUTABLE_SET_FEATURE");
|
||||
if(ARRAY_SET.isEnabled()) addFlag("ARRAY_SET_FEATURE");
|
||||
if(HASH_SET.isEnabled()) addFlag("HASH_SET_FEATURE");
|
||||
if(LINKED_SET.isEnabled()) addFlag("LINKED_SET_FEATURE");
|
||||
if(CUSTOM_SET.isEnabled()) addFlag("CUSTOM_HASH_SET_FEATURE");
|
||||
if(LINKED_CUSTOM_SET.isEnabled()) addFlag("LINKED_CUSTOM_SET_FEATURE");
|
||||
if(AVL_TREE_SET.isEnabled()) addFlag("AVL_TREE_SET_FEATURE");
|
||||
if(RB_TREE_SET.isEnabled()) addFlag("RB_TREE_SET_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades()
|
||||
{
|
||||
if(!isModuleEnabled()) addBlockedFiles("Set", "AbstractSet");
|
||||
if(!isModuleEnabled("Wrappers")) addBlockedFiles("Sets");
|
||||
boolean implementations = !isModuleEnabled("Implementations");
|
||||
if(implementations || !isModuleEnabled("ImmutableSet")) addBlockedFiles("ImmutableOpenHashSet");
|
||||
|
||||
boolean ordered = !isModuleEnabled("OrderedSet");
|
||||
if(ordered) addBlockedFiles("OrderedSet");
|
||||
boolean hashSet = implementations || !isModuleEnabled("HashSet");
|
||||
if(hashSet) addBlockedFiles("OpenHashSet");
|
||||
if(hashSet || ordered || !isModuleEnabled("LinkedHashSet")) addBlockedFiles("LinkedOpenHashSet");
|
||||
|
||||
boolean customHashSet = implementations || !isModuleEnabled("CustomHashSet");
|
||||
if(customHashSet) addBlockedFiles("OpenCustomHashSet");
|
||||
if(customHashSet || ordered || !isModuleEnabled("LinkedCustomHashSet")) addBlockedFiles("LinkedOpenCustomHashSet");
|
||||
|
||||
if(implementations || ordered || !isModuleEnabled("ArraySet")) addBlockedFiles("ArraySet");
|
||||
|
||||
boolean sorted = !isModuleEnabled("SortedSet");
|
||||
if(sorted) addBlockedFiles("SortedSet", "NavigableSet");
|
||||
if(implementations || sorted || !isModuleEnabled("AVLTreeSet")) addBlockedFiles("AVLTreeSet");
|
||||
if(implementations || sorted || !isModuleEnabled("RBTreeSet")) addBlockedFiles("RBTreeSet");
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("Set", "AbstractSet");
|
||||
if(!WRAPPERS.isEnabled()) addBlockedFiles("Sets");
|
||||
if(!IMMUTABLE_SET.isEnabled()) addBlockedFiles("ImmutableOpenHashSet");
|
||||
if(!ORDERED_SET.isEnabled()) addBlockedFiles("OrderedSet");
|
||||
if(!HASH_SET.isEnabled()) addBlockedFiles("OpenHashSet");
|
||||
if(!LINKED_SET.isEnabled()) addBlockedFiles("LinkedOpenHashSet");
|
||||
if(!CUSTOM_SET.isEnabled()) addBlockedFiles("OpenCustomHashSet");
|
||||
if(!LINKED_CUSTOM_SET.isEnabled()) addBlockedFiles("LinkedOpenCustomHashSet");
|
||||
if(!ARRAY_SET.isEnabled()) addBlockedFiles("ArraySet");
|
||||
if(!SORTED_SET.isEnabled()) addBlockedFiles("SortedSet", "NavigableSet");
|
||||
if(!AVL_TREE_SET.isEnabled()) addBlockedFiles("AVLTreeSet");
|
||||
if(!RB_TREE_SET.isEnabled()) addBlockedFiles("RBTreeSet");
|
||||
|
||||
if(keyType == ClassType.BOOLEAN)
|
||||
{
|
||||
@ -161,6 +148,7 @@ public class SetModule extends BaseModule
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractMapper("ABSTRACT_SET", "Abstract%sSet");
|
||||
addAbstractMapper("REVERSED_ORDERED_SET", "Reversed%sOrderedSet");
|
||||
|
||||
//Helper Classes
|
||||
addClassMapper("SETS", "Sets");
|
||||
|
||||
@ -1,12 +1,18 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import java.util.function.Supplier;
|
||||
#endif
|
||||
import java.util.Objects;
|
||||
import java.util.AbstractCollection;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
@ -262,5 +268,79 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
if (a.length > size()) a[size()] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ORDERED_MAP_FEATURE
|
||||
public static class REVERSED_ORDERED_COLLECTION KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements ORDERED_COLLECTION KEY_GENERIC_TYPE {
|
||||
ORDERED_COLLECTION KEY_GENERIC_TYPE collection;
|
||||
Supplier<ITERATOR KEY_GENERIC_TYPE> reverseIterator;
|
||||
|
||||
public REVERSED_ORDERED_COLLECTION(ORDERED_COLLECTION KEY_GENERIC_TYPE collection, Supplier<ITERATOR KEY_GENERIC_TYPE> reverseIterator) {
|
||||
this.collection = collection;
|
||||
this.reverseIterator = reverseIterator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) { return collection.add(o); }
|
||||
@Override
|
||||
public ORDERED_COLLECTION KEY_GENERIC_TYPE reversed() { return collection; }
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE e) { collection.addLast(e); }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE e) { collection.addFirst(e); }
|
||||
@Override
|
||||
#if !TYPE_OBJECT
|
||||
public boolean contains(KEY_TYPE e) { return collection.contains(e); }
|
||||
#else
|
||||
public boolean contains(Object e) { return collection.contains(e); }
|
||||
#endif
|
||||
@Override
|
||||
#if !TYPE_OBJECT
|
||||
public boolean REMOVE_KEY(KEY_TYPE e) { return collection.REMOVE_KEY(e); }
|
||||
#else
|
||||
public boolean remove(Object e) { return collection.remove(e); }
|
||||
#endif
|
||||
@Override
|
||||
public void clear() { collection.clear(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() { return collection.GET_LAST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { return collection.REMOVE_LAST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() { return collection.GET_FIRST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { return collection.REMOVE_FIRST_KEY(); }
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() { return reverseIterator.get(); }
|
||||
@Override
|
||||
public int size() { return collection.size(); }
|
||||
}
|
||||
|
||||
public static class ReverseBiIterator KEY_GENERIC_TYPE implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE it;
|
||||
|
||||
public ReverseBiIterator(LIST_ITERATOR KEY_GENERIC_TYPE it) {
|
||||
this.it = it;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() { return it.PREVIOUS(); }
|
||||
@Override
|
||||
public boolean hasNext() { return it.hasPrevious(); }
|
||||
@Override
|
||||
public boolean hasPrevious() { return it.hasNext(); }
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() { return it.NEXT(); }
|
||||
@Override
|
||||
public void remove() { it.remove(); }
|
||||
@Override
|
||||
public int nextIndex() { return it.previousIndex(); }
|
||||
@Override
|
||||
public int previousIndex() { return it.nextIndex(); }
|
||||
@Override
|
||||
public void set(KEY_TYPE e) { it.set(e); }
|
||||
@Override
|
||||
public void add(KEY_TYPE e) { it.add(e); }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1,19 +1,11 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
/**
|
||||
* A Type-Specific {@link ObjectBidirectionalIterator} to reduce (un)boxing
|
||||
*/
|
||||
public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE, ObjectBidirectionalIterator<CLASS_TYPE>
|
||||
#else
|
||||
/**
|
||||
* This is a basically a {@link java.util.ListIterator} without the index functions.
|
||||
* Allowing to have a simple Bidirectional Iterator without having to keep track of the Iteration index.
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
* Returns true if the Iterator has a Previous element
|
||||
@ -29,11 +21,11 @@ public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE
|
||||
public KEY_TYPE PREVIOUS();
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
/**
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
* @return the Previous element of the iterator.+
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_TYPE previous() {
|
||||
return KEY_TO_OBJ(PREVIOUS());
|
||||
|
||||
@ -0,0 +1,83 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
import java.util.SequencedCollection;
|
||||
|
||||
public interface ORDERED_COLLECTION KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, SequencedCollection<CLASS_TYPE> {
|
||||
#else
|
||||
public interface ORDERED_COLLECTION KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE {
|
||||
#endif
|
||||
@Java21
|
||||
ORDERED_COLLECTION KEY_GENERIC_TYPE reversed();
|
||||
|
||||
/**
|
||||
* A method to add an element to the start of a collection
|
||||
* @param e that should be added at the start.
|
||||
*/
|
||||
public void addFirst(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* A method to add an element to the end of a collection
|
||||
* @param e that should be added at the end.
|
||||
*/
|
||||
public void addLast(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* A method to get the first element in the collection
|
||||
* @return first element in the collection
|
||||
*/
|
||||
public KEY_TYPE GET_FIRST_KEY();
|
||||
/**
|
||||
* A method to get and remove the first element in the collection
|
||||
* @return first element in the collection
|
||||
*/
|
||||
public KEY_TYPE REMOVE_FIRST_KEY();
|
||||
/**
|
||||
* A method to get the last element in the collection
|
||||
* @return last element in the collection
|
||||
*/
|
||||
public KEY_TYPE GET_LAST_KEY();
|
||||
/**
|
||||
* A method to get and remove the last element in the collection
|
||||
* @return last element in the collection
|
||||
*/
|
||||
public KEY_TYPE REMOVE_LAST_KEY();
|
||||
|
||||
#if JAVA_VERSION>=21 && !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addFirst(CLASS_TYPE e) {
|
||||
addFirst(OBJ_TO_KEY(e));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addLast(CLASS_TYPE e) {
|
||||
addLast(OBJ_TO_KEY(e));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getFirst() {
|
||||
return KEY_TO_OBJ(GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getLast() {
|
||||
return KEY_TO_OBJ(GET_LAST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeFirst() {
|
||||
return KEY_TO_OBJ(REMOVE_FIRST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeLast() {
|
||||
return KEY_TO_OBJ(REMOVE_LAST_KEY());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -11,11 +11,15 @@ import java.util.RandomAccess;
|
||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
#endif
|
||||
#if INT_LIST_MODULE && !TYPE_INT
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
@ -532,9 +536,10 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
@Override
|
||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 16464); }
|
||||
#endif
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||
|
||||
@ -535,7 +535,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
* @return if the element was found.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
@Primitive
|
||||
public boolean contains(Object o) {
|
||||
return indexOf(o) != -1;
|
||||
}
|
||||
@ -546,7 +546,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
* @return the index of the element if found. (if not found then -1)
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
@Primitive
|
||||
public int indexOf(Object o) {
|
||||
KEY_TYPE[] data = this.data;
|
||||
#if TYPE_OBJECT
|
||||
@ -570,7 +570,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
* @return the last index of the element if found. (if not found then -1)
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
@Primitive
|
||||
public int lastIndexOf(Object o) {
|
||||
KEY_TYPE[] data = this.data;
|
||||
#if TYPE_OBJECT
|
||||
|
||||
@ -13,11 +13,13 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
import java.util.NoSuchElementException;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import java.util.Spliterator;
|
||||
#if PRIMITIVES
|
||||
import java.util.Spliterator.JAVA_SPLIT_ITERATOR;
|
||||
#endif
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
import java.util.function.Predicate;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.IntFunction;
|
||||
@ -60,12 +62,14 @@ import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.utils.Stack;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
#if PRIMITIVES
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
import java.util.stream.StreamSupport;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
@ -416,6 +420,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return new ListIter(getNode(index), index);
|
||||
}
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
#if PRIMITIVES
|
||||
/**
|
||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||
@ -436,6 +441,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return new TypeSplitIteratorBRACES(this, first, 0); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1253,6 +1259,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
private static class TypeSplitIterator KEY_GENERIC_TYPE implements SPLIT_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
static final int BATCH_UNIT = 1 << 10;
|
||||
@ -1397,4 +1404,5 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
@ -15,7 +15,10 @@ import java.util.function.UnaryOperator;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ORDERED_COLLECTION;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
@ -27,7 +30,9 @@ import speiger.src.collections.PACKAGE.utils.LISTS;
|
||||
#if INT_LIST_MODULE && !TYPE_INT
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
#endif
|
||||
@ -36,7 +41,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
* A Type Specific List interface that reduces boxing/unboxing and adds a couple extra quality of life features
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List<CLASS_TYPE>
|
||||
public interface LIST KEY_GENERIC_TYPE extends ORDERED_COLLECTION KEY_GENERIC_TYPE, List<CLASS_TYPE>
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
@ -101,6 +106,24 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
*/
|
||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A method to add an element to the start of a list
|
||||
* @param e that should be added at the start.
|
||||
*/
|
||||
@Override
|
||||
public default void addFirst(KEY_TYPE e) {
|
||||
add(0, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* A method to add an element to the end of a list
|
||||
* @param e that should be added at the end.
|
||||
*/
|
||||
@Override
|
||||
public default void addLast(KEY_TYPE e) {
|
||||
add(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns the first element of a List.
|
||||
* This function was introduced due to how annoying it is to get/remove the last element of a list.
|
||||
@ -504,9 +527,56 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean add(CLASS_TYPE e) {
|
||||
return COLLECTION.super.add(e);
|
||||
return ORDERED_COLLECTION.super.add(e);
|
||||
}
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
#if !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addFirst(CLASS_TYPE e) {
|
||||
addFirst(OBJ_TO_KEY(e));
|
||||
}
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addLast(CLASS_TYPE e) {
|
||||
addLast(OBJ_TO_KEY(e));
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getFirst() {
|
||||
return KEY_TO_OBJ(GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getLast() {
|
||||
return KEY_TO_OBJ(GET_LAST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeFirst() {
|
||||
return KEY_TO_OBJ(REMOVE_FIRST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeLast() {
|
||||
return KEY_TO_OBJ(REMOVE_LAST_KEY());
|
||||
}
|
||||
|
||||
#endif
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
@ -554,7 +624,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean contains(Object o) {
|
||||
return COLLECTION.super.contains(o);
|
||||
return ORDERED_COLLECTION.super.contains(o);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
@ -564,7 +634,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean remove(Object o) {
|
||||
return COLLECTION.super.remove(o);
|
||||
return ORDERED_COLLECTION.super.remove(o);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
@ -594,10 +664,12 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
*/
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
#endif
|
||||
}
|
||||
@ -14,6 +14,15 @@ import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
#endif
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#if MAPS_FEATURE
|
||||
@ -42,7 +51,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
*/
|
||||
public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CLASS_TYPE, CLASS_VALUE_TYPE> implements MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
protected VALUE_TYPE defaultReturnValue = EMPTY_VALUE;
|
||||
protected VALUE_TYPE defaultReturnValue = INVALID_VALUE;
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE getDefaultReturnValue() {
|
||||
@ -119,7 +128,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
public void putAll(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, int offset, int size) {
|
||||
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||
SanityChecks.checkArrayCapacity(values.length, offset, size);
|
||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||
for(int i = 0;i<size;i++) put(OBJ_TO_KEY(keys[i]), OBJ_TO_VALUE(values[i]));
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -543,6 +552,132 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static class REVERSED_ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE {
|
||||
ORDERED_MAP KEY_VALUE_GENERIC_TYPE map;
|
||||
|
||||
public REVERSED_ORDERED_MAP(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
this.map = map;
|
||||
}
|
||||
@Override
|
||||
public ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE setDefaultReturnValue(VALUE_TYPE v) {
|
||||
map.setDefaultReturnValue(v);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public VALUE_TYPE getDefaultReturnValue() { return map.getDefaultReturnValue(); }
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value) { return map.put(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE putIfAbsent(KEY_TYPE key, VALUE_TYPE value) { return map.putIfAbsent(key, value); }
|
||||
#if VALUE_PRIMITIVES
|
||||
@Override
|
||||
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { return map.addTo(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value) { return map.subFrom(key, value); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE REMOVE_VALUE(KEY_TYPE key) { return map.REMOVE_VALUE(key); }
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE key, VALUE_TYPE value) { return map.remove(key, value); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.REMOVE_VALUEOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
#if TYPE_OBJECT
|
||||
public boolean containsKey(Object key) { return map.containsKey(key); }
|
||||
#else
|
||||
public boolean containsKey(KEY_TYPE key) { return map.containsKey(key); }
|
||||
#endif
|
||||
@Override
|
||||
#if VALUE_OBJECT
|
||||
public boolean containsValue(Object value) { return map.containsValue(value); }
|
||||
#else
|
||||
public boolean containsValue(VALUE_TYPE value) { return map.containsValue(value); }
|
||||
#endif
|
||||
@Override
|
||||
public boolean replace(KEY_TYPE key, VALUE_TYPE oldValue, VALUE_TYPE newValue) { return map.replace(key, oldValue, newValue); }
|
||||
@Override
|
||||
public VALUE_TYPE replace(KEY_TYPE key, VALUE_TYPE value) { return map.replace(key, value); }
|
||||
@Override
|
||||
public void REPLACE_VALUES(MAP KEY_VALUE_GENERIC_TYPE m) { map.REPLACE_VALUES(m); }
|
||||
@Override
|
||||
public void REPLACE_VALUES(UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { map.REPLACE_VALUES(mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE(key, mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE_IF_ABSENT(key, mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { return map.SUPPLY_IF_ABSENT(key, valueProvider); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE_IF_PRESENT(key, mappingFunction); }
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTENonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE_IF_ABSENTNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { return map.SUPPLY_IF_ABSENTNonDefault(key, valueProvider); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE_IF_PRESENTNonDefault(key, mappingFunction); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { return map.MERGE(key, value, mappingFunction); }
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE GET_VALUE(KEY_TYPE key) { return map.GET_VALUE(key); }
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { return map.putAndMoveToLast(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { return map.putAndMoveToFirst(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) { return map.putLast(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) { return map.putFirst(key, value); }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { return map.moveToLast(key); }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { return map.moveToFirst(key); }
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { return map.getAndMoveToLast(key); }
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { return map.getAndMoveToFirst(key); }
|
||||
@Override
|
||||
public KEY_TYPE FIRST_ENTRY_KEY() { return map.LAST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { return map.POLL_LAST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE LAST_ENTRY_KEY() { return map.FIRST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return map.lastEntry(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { return map.pollLastEntry(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { return map.pollFirstEntry(); }
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() { return new AbstractObjectSet.ReversedObjectOrderedSet<>(map.ENTRY_SET()); }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() { return new ABSTRACT_SET.REVERSED_ORDERED_SETBRACES(map.keySet()); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() { return map.values().reversed(); }
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE reversed() { return map; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A Simple Type Specific Entry class to reduce boxing/unboxing
|
||||
* @Type(T)
|
||||
|
||||
@ -40,7 +40,7 @@ import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
@ -295,6 +295,54 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) {
|
||||
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) {
|
||||
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) {
|
||||
if(isEmpty() || strategy.equals(FIRST_ENTRY_KEY(), key)) return false;
|
||||
@ -430,6 +478,52 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.ENTRY_KEY(), EMPTY_KEY_VALUE)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
values[nullIndex] = EMPTY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.ENTRY_KEY(), EMPTY_KEY_VALUE)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
values[nullIndex] = EMPTY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -443,9 +537,9 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -630,24 +724,24 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() {
|
||||
return new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() {
|
||||
return new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return entry;
|
||||
@ -655,7 +749,12 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -665,7 +764,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -919,7 +1018,12 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -941,22 +1045,22 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
return FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
return POLL_FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
return LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
return POLL_LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@ -1100,39 +1204,47 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE implements VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE {
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(VALUE_TYPE e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
public boolean contains(VALUE_TYPE e) { return containsValue(e); }
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(VALUE_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(VALUE_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return LINKED_CUSTOM_HASH_MAP.this.size();
|
||||
}
|
||||
|
||||
public int size() { return LINKED_CUSTOM_HASH_MAP.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
LINKED_CUSTOM_HASH_MAP.this.clear();
|
||||
public void clear() { LINKED_CUSTOM_HASH_MAP.this.clear(); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE reversed() { return new VALUE_ABSTRACT_COLLECTION.VALUE_REVERSED_ORDERED_COLLECTIONVALUE_BRACES(this, this::reverseIterator); }
|
||||
private VALUE_ITERATOR VALUE_GENERIC_TYPE reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_FIRST_KEY() { return FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_FIRST_KEY() {
|
||||
VALUE_TYPE result = FIRST_ENTRY_VALUE();
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_LAST_KEY() { return LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_LAST_KEY() {
|
||||
VALUE_TYPE result = LAST_ENTRY_VALUE();
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1278,7 +1390,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1305,7 +1417,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1335,7 +1447,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
private class KeyIterator extends MapIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1357,7 +1469,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
@ -1378,16 +1490,20 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(KEY_TYPE from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -1415,11 +1531,11 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1479,20 +1595,30 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -39,7 +39,7 @@ import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
@ -272,6 +272,54 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) {
|
||||
if(KEY_EQUALS_NULL(key)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
while(KEY_EQUALS_NULL(key)) {
|
||||
if(KEY_EQUALS(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) {
|
||||
if(KEY_EQUALS_NULL(key)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
while(KEY_EQUALS_NULL(key)) {
|
||||
if(KEY_EQUALS(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) {
|
||||
if(isEmpty() || KEY_EQUALS(FIRST_ENTRY_KEY(), key)) return false;
|
||||
@ -434,6 +482,52 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(KEY_EQUALS_NULL(result.ENTRY_KEY())) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
values[nullIndex] = EMPTY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(KEY_EQUALS_NULL(result.ENTRY_KEY())) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
values[nullIndex] = EMPTY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -447,9 +541,9 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -634,24 +728,24 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() {
|
||||
return new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() {
|
||||
return new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return entry;
|
||||
@ -659,7 +753,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -669,7 +768,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -918,7 +1017,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -940,22 +1044,22 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
return FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
return POLL_FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
return LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
return POLL_LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@ -1099,41 +1203,50 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE implements VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE {
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(VALUE_TYPE e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(VALUE_TYPE e) { return containsValue(e); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(VALUE_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(VALUE_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return LINKED_HASH_MAP.this.size();
|
||||
}
|
||||
|
||||
public int size() { return LINKED_HASH_MAP.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
LINKED_HASH_MAP.this.clear();
|
||||
public void clear() { LINKED_HASH_MAP.this.clear(); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE reversed() { return new VALUE_ABSTRACT_COLLECTION.VALUE_REVERSED_ORDERED_COLLECTIONVALUE_BRACES(this, this::reverseIterator); }
|
||||
private VALUE_ITERATOR VALUE_GENERIC_TYPE reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_FIRST_KEY() { return FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_FIRST_KEY() {
|
||||
VALUE_TYPE result = FIRST_ENTRY_VALUE();
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_LAST_KEY() { return LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_LAST_KEY() {
|
||||
VALUE_TYPE result = LAST_ENTRY_VALUE();
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1278,7 +1391,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1305,7 +1418,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1335,7 +1448,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
private class KeyIterator extends MapIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1357,7 +1470,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
@ -1377,13 +1490,16 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(KEY_TYPE from) {
|
||||
@ -1414,11 +1530,11 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1478,20 +1594,30 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -65,7 +65,7 @@ import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||
#if !SAME_TYPE
|
||||
@ -119,7 +119,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
/** KeySet cache */
|
||||
protected transient ORDERED_SET KEY_GENERIC_TYPE keySet;
|
||||
/** Values cache */
|
||||
protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
protected transient VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
|
||||
/** Amount of Elements stored in the HashMap */
|
||||
protected int size;
|
||||
@ -320,6 +320,10 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@ -443,6 +447,23 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -456,7 +477,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
}
|
||||
@ -621,24 +642,29 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
public boolean moveToLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() {
|
||||
return new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() {
|
||||
return new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() { throw new UnsupportedOperationException(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() { throw new UnsupportedOperationException(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -648,7 +674,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -875,7 +901,12 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -895,20 +926,20 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
return FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
return LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
@ -1050,39 +1081,42 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE implements VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE {
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(VALUE_TYPE e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(VALUE_TYPE e) { return containsValue(e); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(VALUE_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(VALUE_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return IMMUTABLE_HASH_MAP.this.size();
|
||||
}
|
||||
|
||||
public int size() { return IMMUTABLE_HASH_MAP.this.size(); }
|
||||
@Override
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE reversed() { return new VALUE_ABSTRACT_COLLECTION.VALUE_REVERSED_ORDERED_COLLECTIONVALUE_BRACES(this, this::reverseIterator); }
|
||||
private VALUE_ITERATOR VALUE_GENERIC_TYPE reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_FIRST_KEY() { return FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_LAST_KEY() { return LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) {
|
||||
int index = firstIndex;
|
||||
@ -1226,7 +1260,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1252,7 +1286,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1279,7 +1313,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
private class KeyIterator extends MapIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1301,7 +1335,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
@ -1322,13 +1356,16 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(KEY_TYPE from) {
|
||||
@ -1359,11 +1396,11 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1380,20 +1417,30 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -46,7 +46,7 @@ import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||
#if !SAME_TYPE
|
||||
@ -105,7 +105,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
/** KeySet cache */
|
||||
protected ORDERED_SET KEY_GENERIC_TYPE keySet;
|
||||
/** Values cache */
|
||||
protected VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
protected VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
/** EntrySet cache */
|
||||
protected FastOrderedSet KEY_VALUE_GENERIC_TYPE entrySet;
|
||||
|
||||
@ -275,6 +275,27 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return lastValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) {
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
insertIndex(0, key, value);
|
||||
size++;
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) {
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
insertIndex(size++, key, value);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
@ -402,6 +423,34 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[0], values[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[size-1], values[size-1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[0], values[0]);
|
||||
removeIndex(0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[size-1], values[size-1]);
|
||||
removeIndex(size-1);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE REMOVE_VALUE(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
@ -461,7 +510,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
}
|
||||
@ -828,24 +877,24 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() {
|
||||
return new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() {
|
||||
return new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return entry;
|
||||
@ -853,7 +902,12 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -863,7 +917,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1073,7 +1127,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) { return ARRAY_MAP.this.moveToLast(o); }
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() { return new KeyIterator(); }
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() { return new KeyIterator(true); }
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() { return new KeyIterator(false); }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return new KeyIterator(fromElement); }
|
||||
@Override
|
||||
@ -1081,13 +1137,13 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
@Override
|
||||
public void clear() { ARRAY_MAP.this.clear(); }
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() { return FIRST_ENTRY_KEY(); }
|
||||
public KEY_TYPE GET_FIRST_KEY() { return FIRST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() { return POLL_FIRST_ENTRY_KEY(); }
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { return POLL_FIRST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() { return LAST_ENTRY_KEY(); }
|
||||
public KEY_TYPE GET_LAST_KEY() { return LAST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { return POLL_LAST_ENTRY_KEY(); }
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { return POLL_LAST_ENTRY_KEY(); }
|
||||
|
||||
@Override
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
@ -1197,40 +1253,49 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE implements VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE {
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(VALUE_TYPE e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(VALUE_TYPE e) { return containsValue(e); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(VALUE_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(VALUE_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return ARRAY_MAP.this.size();
|
||||
}
|
||||
|
||||
public int size() { return ARRAY_MAP.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
ARRAY_MAP.this.clear();
|
||||
public void clear() { ARRAY_MAP.this.clear(); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE reversed() { return new VALUE_ABSTRACT_COLLECTION.VALUE_REVERSED_ORDERED_COLLECTIONVALUE_BRACES(this, this::reverseIterator); }
|
||||
private VALUE_ITERATOR VALUE_GENERIC_TYPE reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_FIRST_KEY() { return FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_FIRST_KEY() {
|
||||
VALUE_TYPE result = FIRST_ENTRY_VALUE();
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_LAST_KEY() { return LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_LAST_KEY() {
|
||||
VALUE_TYPE result = LAST_ENTRY_VALUE();
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1332,10 +1397,8 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(KEY_TYPE from) {
|
||||
index = findIndex(from);
|
||||
}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(KEY_TYPE element) { super(element); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||
@ -1358,11 +1421,8 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = null;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(KEY_TYPE from) {
|
||||
index = findIndex(from);
|
||||
if(index == -1) throw new NoSuchElementException();
|
||||
}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(KEY_TYPE element) { super(element); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||
@ -1389,11 +1449,8 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
private class KeyIterator extends MapIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(KEY_TYPE element) {
|
||||
index = findIndex(element);
|
||||
if(index == -1) throw new NoSuchElementException();
|
||||
}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(KEY_TYPE element) { super(element); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
@ -1413,6 +1470,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE {
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
public ValueIterator(KEY_TYPE element) { super(element); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
return values[previousEntry()];
|
||||
@ -1431,23 +1491,37 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
this.index = start ? 0 : size;
|
||||
}
|
||||
|
||||
MapIterator(KEY_TYPE element) {
|
||||
this.forward = true;
|
||||
index = findIndex(element);
|
||||
if(index == -1) throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return index < size;
|
||||
return forward ? index < size : index > 0;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
return forward ? index > 0 : index < size;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
return index;
|
||||
if(forward) return index;
|
||||
return size - index;
|
||||
}
|
||||
|
||||
public int previousIndex() {
|
||||
return index-1;
|
||||
if(forward) return index-1;
|
||||
return (size - index)-1;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
@ -1460,26 +1534,42 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
if(forward) {
|
||||
index--;
|
||||
return (lastReturned = index);
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = index;
|
||||
return index++;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) {
|
||||
lastReturned = index;
|
||||
return index++;
|
||||
}
|
||||
index--;
|
||||
return (lastReturned = index);
|
||||
}
|
||||
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
return forward ? moveForward(amount) : moveBackwards(amount);
|
||||
}
|
||||
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
return forward ? moveBackwards(amount) : moveForward(amount);
|
||||
}
|
||||
|
||||
private int moveForward(int amount) {
|
||||
int steps = Math.min(amount, size() - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||
return steps;
|
||||
}
|
||||
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
private int moveBackwards(int amount) {
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||
|
||||
@ -18,7 +18,7 @@ import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
#if !VALUE_OBJECT && !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||
@ -216,6 +216,28 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(T key, VALUE_TYPE value) {
|
||||
int index = key.ordinal();
|
||||
if(isSet(index)) return values[index];
|
||||
set(index);
|
||||
values[index] = value;
|
||||
onNodeAdded(index);
|
||||
moveToFirstIndex(index);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putLast(T key, VALUE_TYPE value) {
|
||||
int index = key.ordinal();
|
||||
if(isSet(index)) return values[index];
|
||||
set(index);
|
||||
values[index] = value;
|
||||
onNodeAdded(index);
|
||||
moveToLastIndex(index);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(T key) {
|
||||
int index = key.ordinal();
|
||||
@ -312,6 +334,42 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
firstIndex = (int)links[pos];
|
||||
if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
values[result.ENTRY_KEY().ordinal()] = EMPTY_VALUE;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
firstIndex = (int)links[pos];
|
||||
if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
values[result.ENTRY_KEY().ordinal()] = EMPTY_VALUE;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -325,9 +383,9 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -431,24 +489,24 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() {
|
||||
return new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() {
|
||||
return new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return entry;
|
||||
@ -456,7 +514,12 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -466,7 +529,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -593,7 +656,12 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -614,22 +682,22 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
@Override
|
||||
public T FIRST_KEY() {
|
||||
public T GET_FIRST_KEY() {
|
||||
return FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T POLL_FIRST_KEY() {
|
||||
public T REMOVE_FIRST_KEY() {
|
||||
return POLL_FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T LAST_KEY() {
|
||||
public T GET_LAST_KEY() {
|
||||
return LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T POLL_LAST_KEY() {
|
||||
public T REMOVE_LAST_KEY() {
|
||||
return POLL_LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@ -656,41 +724,50 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
#endif
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE implements VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE {
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(VALUE_TYPE e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(VALUE_TYPE e) { return containsValue(e); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(VALUE_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(VALUE_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return LINKED_ENUM_MAP.this.size();
|
||||
}
|
||||
|
||||
public int size() { return LINKED_ENUM_MAP.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
LINKED_ENUM_MAP.this.clear();
|
||||
public void clear() { LINKED_ENUM_MAP.this.clear(); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE reversed() { return new VALUE_ABSTRACT_COLLECTION.VALUE_REVERSED_ORDERED_COLLECTIONVALUE_BRACES(this, this::reverseIterator); }
|
||||
private VALUE_ITERATOR VALUE_GENERIC_TYPE reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_FIRST_KEY() { return FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_FIRST_KEY() {
|
||||
VALUE_TYPE result = FIRST_ENTRY_VALUE();
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_LAST_KEY() { return LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_LAST_KEY() {
|
||||
VALUE_TYPE result = LAST_ENTRY_VALUE();
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return result;
|
||||
}
|
||||
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
public void forEach(Consumer VALUE_SUPER_GENERIC_TYPE action) {
|
||||
@ -715,7 +792,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(T from) {
|
||||
super(from);
|
||||
}
|
||||
@ -742,7 +819,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(T from) {
|
||||
super(from);
|
||||
}
|
||||
@ -772,7 +849,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
private class KeyIterator extends MapIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(T from) {
|
||||
super(from);
|
||||
}
|
||||
@ -794,7 +871,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
@ -815,16 +892,20 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(T from) {
|
||||
this.forward = true;
|
||||
previous = from.ordinal() - 1;
|
||||
index = from.ordinal();
|
||||
next = from.ordinal();
|
||||
@ -832,11 +913,11 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -871,20 +952,30 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -154,7 +154,7 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
* @return the last present value or default return value.
|
||||
*/
|
||||
public default CLASS_VALUE_TYPE put(Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> entry) {
|
||||
return put(entry.getKey(), entry.getValue());
|
||||
return put(OBJ_TO_KEY(entry.getKey()), OBJ_TO_VALUE(entry.getValue()));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,8 +1,15 @@
|
||||
package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
import java.util.Map;
|
||||
import java.util.SequencedMap;
|
||||
|
||||
#endif
|
||||
#if MAPS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
#endif
|
||||
@ -17,7 +24,11 @@ import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
#if JAVA_VERSION>=21
|
||||
public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERIC_TYPE, SequencedMap<CLASS_TYPE, CLASS_VALUE_TYPE>
|
||||
#else
|
||||
public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
* A customized put method that allows you to insert into the first index.
|
||||
@ -37,6 +48,26 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
||||
*/
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value);
|
||||
|
||||
/**
|
||||
* A alternative to putAndMoveToFirst.
|
||||
* This method simply puts an entry at the first spot of the Map but only if the entry is missing.
|
||||
* @param key the key that should be inserted
|
||||
* @param value the value that should be inserted
|
||||
* @return the previous present or default return value
|
||||
* @see java.util.Map#put(Object, Object)
|
||||
*/
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value);
|
||||
|
||||
/**
|
||||
* A alternative to putAndMoveToLast.
|
||||
* This method simply puts an entry at the last spot of the Map but only if the entry is missing.
|
||||
* @param key the key that should be inserted
|
||||
* @param value the value that should be inserted
|
||||
* @return the previous present or default return value
|
||||
* @see java.util.Map#put(Object, Object)
|
||||
*/
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value);
|
||||
|
||||
/**
|
||||
* A specific move method to move a given key/value to the first index.
|
||||
* @param key that should be moved to the first index
|
||||
@ -97,13 +128,34 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
||||
*/
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE();
|
||||
|
||||
@Java21
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry();
|
||||
@Java21
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry();
|
||||
@Java21
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry();
|
||||
@Java21
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry();
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy();
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet();
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values();
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET();
|
||||
@Java21
|
||||
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE reversed() { return new ABSTRACT_MAP.REVERSED_ORDERED_MAPKV_BRACES(this); }
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
@Override
|
||||
default ORDERED_SET KEY_GENERIC_TYPE sequencedKeySet() { return keySet(); }
|
||||
@Override
|
||||
default VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE sequencedValues() { return values(); }
|
||||
@Override
|
||||
default ObjectOrderedSet<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> sequencedEntrySet() { return (ObjectOrderedSet<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>>)(Object)ENTRY_SET(); }
|
||||
|
||||
#endif
|
||||
#if MAPS_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped SortedMap that is Synchronized
|
||||
@ -130,6 +182,22 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
||||
@Override
|
||||
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
#if JAVA_VERSION>=21
|
||||
#if !SAME_TYPE || !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_VALUE_TYPE putFirst(CLASS_TYPE k, CLASS_VALUE_TYPE v) {
|
||||
return putFirst(OBJ_TO_KEY(k), OBJ_TO_VALUE(v));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_VALUE_TYPE putLast(CLASS_TYPE k, CLASS_VALUE_TYPE v) {
|
||||
return putLast(OBJ_TO_KEY(k), OBJ_TO_VALUE(v));
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/**
|
||||
* Fast Ordered Entry Set that allows for a faster Entry Iterator by recycling the Entry Object and just exchanging 1 internal value
|
||||
|
||||
@ -6,6 +6,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
|
||||
/**
|
||||
@ -47,4 +48,95 @@ public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#if ORDERED_SET_FEATURE
|
||||
public static class REVERSED_ORDERED_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE {
|
||||
protected ORDERED_SET KEY_GENERIC_TYPE set;
|
||||
|
||||
public REVERSED_ORDERED_SET(ORDERED_SET KEY_GENERIC_TYPE set) {
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public REVERSED_ORDERED_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) {
|
||||
return set.iterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return set.reverseIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return set.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
#if !TYPE_OBJECT
|
||||
public boolean remove(KEY_TYPE o) {
|
||||
#else
|
||||
public boolean remove(Object o) {
|
||||
#endif
|
||||
return set.remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
return set.add(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||
return set.addAndMoveToLast(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToLast(KEY_TYPE o) {
|
||||
return set.addAndMoveToFirst(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) {
|
||||
return set.moveToLast(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) {
|
||||
return set.moveToFirst(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
return set.GET_LAST_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
return set.REMOVE_LAST_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
return set.GET_FIRST_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
return set.REMOVE_FIRST_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE reversed() {
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return set.size();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -219,13 +219,13 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return data[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return data[size - 1];
|
||||
}
|
||||
@ -354,7 +354,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
KEY_TYPE result = data[0];
|
||||
System.arraycopy(data, 1, data, 0, --size);
|
||||
@ -365,7 +365,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
size--;
|
||||
#if TYPE_OBJECT
|
||||
@ -511,13 +511,18 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator(0);
|
||||
return new SetIterator(true, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new SetIterator(false, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) {
|
||||
int index = findIndex(fromElement);
|
||||
if(index != -1) return new SetIterator(index);
|
||||
if(index != -1) return new SetIterator(true, index);
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@ -570,45 +575,57 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
}
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
boolean forward;
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
public SetIterator(int index) {
|
||||
public SetIterator(boolean forward, int index) {
|
||||
this.forward = forward;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < size();
|
||||
return forward ? index < size() : index > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) {
|
||||
lastReturned = index;
|
||||
return data[index++];
|
||||
}
|
||||
index--;
|
||||
return data[(lastReturned = index)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
return forward ? index > 0 : index < size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
--index;
|
||||
if(forward) {
|
||||
index--;
|
||||
return data[(lastReturned = index)];
|
||||
}
|
||||
lastReturned = index;
|
||||
return data[index++];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return index;
|
||||
if(forward) return index;
|
||||
return size - index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return index-1;
|
||||
if(forward) return index-1;
|
||||
return (size - index)-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -637,15 +654,23 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
return forward ? moveForward(amount) : moveBackwards(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
return forward ? moveBackwards(amount) : moveForward(amount);
|
||||
}
|
||||
|
||||
private int moveForward(int amount) {
|
||||
int steps = Math.min(amount, size() - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||
return steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
private int moveBackwards(int amount) {
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||
|
||||
@ -285,22 +285,22 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[firstIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean remove(Object o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@ -455,7 +455,12 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator();
|
||||
return new SetIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new SetIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -521,16 +526,20 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
}
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
int index = -1;
|
||||
|
||||
SetIterator() {
|
||||
next = firstIndex;
|
||||
SetIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
SetIterator(KEY_TYPE from) {
|
||||
this.forward = true;
|
||||
if(KEY_EQUALS_NULL(from)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -559,48 +568,60 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
int result = forward ? moveForward(amount) : moveBackwards(amount);
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = forward ? moveBackwards(amount) : moveForward(amount);
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveForward(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveBackwards(int amount) {
|
||||
int result = 0;
|
||||
while(previous != -1 && result != amount) {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
ensureIndexKnown();
|
||||
return index;
|
||||
if(forward) return index;
|
||||
return size - index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
ensureIndexKnown();
|
||||
return index - 1;
|
||||
if(forward) return index-1;
|
||||
return (size - index)-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -609,8 +630,8 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return keys[current];
|
||||
}
|
||||
@ -618,12 +639,22 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
if(index == -1) {
|
||||
if(previous == -1) {
|
||||
|
||||
@ -291,7 +291,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) {
|
||||
if(isEmpty() || strategy.equals(FIRST_KEY(), o)) return false;
|
||||
if(isEmpty() || strategy.equals(GET_FIRST_KEY(), o)) return false;
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
@ -313,7 +313,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) {
|
||||
if(isEmpty() || strategy.equals(LAST_KEY(), o)) return false;
|
||||
if(isEmpty() || strategy.equals(GET_LAST_KEY(), o)) return false;
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
@ -370,13 +370,13 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[firstIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
@ -392,13 +392,13 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
@ -697,7 +697,12 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator();
|
||||
return new SetIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new SetIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -722,16 +727,20 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
int index = -1;
|
||||
|
||||
SetIterator() {
|
||||
next = firstIndex;
|
||||
SetIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
SetIterator(KEY_TYPE from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -760,48 +769,60 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
int result = forward ? moveForward(amount) : moveBackwards(amount);
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = forward ? moveBackwards(amount) : moveForward(amount);
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveForward(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveBackwards(int amount) {
|
||||
int result = 0;
|
||||
while(previous != -1 && result != amount) {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
ensureIndexKnown();
|
||||
return index;
|
||||
if(forward) return index;
|
||||
return size - index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
ensureIndexKnown();
|
||||
return index - 1;
|
||||
if(forward) return index-1;
|
||||
return (size - index)-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -850,8 +871,8 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return keys[current];
|
||||
}
|
||||
@ -859,12 +880,22 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
if(index == -1) {
|
||||
if(previous == -1) {
|
||||
|
||||
@ -262,7 +262,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) {
|
||||
if(isEmpty() || KEY_EQUALS(FIRST_KEY(), o)) return false;
|
||||
if(isEmpty() || KEY_EQUALS(GET_FIRST_KEY(), o)) return false;
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
@ -284,7 +284,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) {
|
||||
if(isEmpty() || KEY_EQUALS(LAST_KEY(), o)) return false;
|
||||
if(isEmpty() || KEY_EQUALS(GET_LAST_KEY(), o)) return false;
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
@ -341,13 +341,13 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[firstIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
@ -363,13 +363,13 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
@ -668,7 +668,12 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator();
|
||||
return new SetIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new SetIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -693,16 +698,20 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
int index = -1;
|
||||
|
||||
SetIterator() {
|
||||
next = firstIndex;
|
||||
SetIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
SetIterator(KEY_TYPE from) {
|
||||
this.forward = true;
|
||||
if(KEY_EQUALS_NULL(from)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -731,48 +740,60 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
int result = forward ? moveForward(amount) : moveBackwards(amount);
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = forward ? moveBackwards(amount) : moveForward(amount);
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveForward(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveBackwards(int amount) {
|
||||
int result = 0;
|
||||
while(previous != -1 && result != amount) {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
ensureIndexKnown();
|
||||
return index;
|
||||
if(forward) return index;
|
||||
return size - index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
ensureIndexKnown();
|
||||
return index - 1;
|
||||
if(forward) return index-1;
|
||||
return (size - index)-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -821,8 +842,8 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return keys[current];
|
||||
}
|
||||
@ -830,12 +851,22 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
if(index == -1) {
|
||||
if(previous == -1) {
|
||||
|
||||
@ -3,11 +3,13 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
import java.util.NavigableSet;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
#if SETS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
|
||||
/**
|
||||
* A Type Specific Navigable Set interface with a couple helper methods
|
||||
@ -145,6 +147,7 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
|
||||
public default NAVIGABLE_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
@ -152,6 +155,7 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
|
||||
@ -1,11 +1,18 @@
|
||||
package speiger.src.collections.PACKAGE.sets;
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
import java.util.SequencedSet;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET.REVERSED_ORDERED_SET;
|
||||
#if SETS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
|
||||
/**
|
||||
* A Special Set Interface giving Access to some really usefull functions
|
||||
@ -15,7 +22,11 @@ import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
*
|
||||
* @Type(T)
|
||||
*/
|
||||
#if JAVA_VERSION>=21
|
||||
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, SequencedSet<CLASS_TYPE>
|
||||
#else
|
||||
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
* A customized add method that allows you to insert into the first index.
|
||||
@ -52,6 +63,7 @@ public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator();
|
||||
|
||||
/**
|
||||
* A type Specific Iterator starting from a given key
|
||||
@ -61,6 +73,7 @@ public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||
*/
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement);
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
@ -68,26 +81,80 @@ public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A method to get the first element in the set
|
||||
* @return first element in the set
|
||||
*/
|
||||
public KEY_TYPE FIRST_KEY();
|
||||
public KEY_TYPE GET_FIRST_KEY();
|
||||
/**
|
||||
* A method to get and remove the first element in the set
|
||||
* @return first element in the set
|
||||
*/
|
||||
public KEY_TYPE POLL_FIRST_KEY();
|
||||
public KEY_TYPE REMOVE_FIRST_KEY();
|
||||
/**
|
||||
* A method to get the last element in the set
|
||||
* @return last element in the set
|
||||
*/
|
||||
public KEY_TYPE LAST_KEY();
|
||||
public KEY_TYPE GET_LAST_KEY();
|
||||
/**
|
||||
* A method to get and remove the last element in the set
|
||||
* @return last element in the set
|
||||
*/
|
||||
public KEY_TYPE POLL_LAST_KEY();
|
||||
public KEY_TYPE REMOVE_LAST_KEY();
|
||||
|
||||
#if JAVA_VERSION>=21 && !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addFirst(CLASS_TYPE e) { addAndMoveToFirst(OBJ_TO_KEY(e)); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addLast(CLASS_TYPE e) { addAndMoveToLast(OBJ_TO_KEY(e)); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getFirst() { return GET_FIRST_KEY(); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getLast() { return GET_LAST_KEY(); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeFirst() { return REMOVE_FIRST_KEY(); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeLast() { return REMOVE_LAST_KEY(); }
|
||||
|
||||
#endif
|
||||
@Java21
|
||||
public default ORDERED_SET KEY_GENERIC_TYPE reversed() { return new REVERSED_ORDERED_SETBRACES(this); }
|
||||
|
||||
#if SETS_FEATURE
|
||||
/**
|
||||
|
||||
@ -4,11 +4,13 @@ import java.util.Set;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
#if SETS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
|
||||
|
||||
/**
|
||||
@ -88,10 +90,12 @@ public interface SET KEY_GENERIC_TYPE extends Set<CLASS_TYPE>, COLLECTION KEY_GE
|
||||
public default SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
*/
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
#endif
|
||||
}
|
||||
@ -3,7 +3,9 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
#else
|
||||
@ -12,7 +14,9 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#if SETS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Type Specific SortedSet implementation to reduce boxing/unboxing
|
||||
@ -67,6 +71,7 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
|
||||
public default SORTED_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
@ -74,6 +79,7 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type Specific SubSet method to reduce boxing/unboxing
|
||||
|
||||
@ -23,6 +23,9 @@ import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.ORDERED_COLLECTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
@ -76,6 +79,37 @@ public class COLLECTIONS
|
||||
return c instanceof UnmodifiableCollection ? c : new UnmodifiableCollectionBRACES(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Immutable Ordered Collection instance based on the instance given.
|
||||
* @param c that should be made immutable/unmodifiable
|
||||
* @Type(T)
|
||||
* @return a unmodifiable Ordered collection wrapper. If the Collection already a unmodifiable wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ORDERED_COLLECTION KEY_GENERIC_TYPE unmodifiable(ORDERED_COLLECTION KEY_GENERIC_TYPE c) {
|
||||
return c instanceof UnmodifiableOrderedCollection ? c : new UnmodifiableOrderedCollectionBRACES(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized ordered Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
* @Type(T)
|
||||
* @return a synchronized ordered collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ORDERED_COLLECTION KEY_GENERIC_TYPE synchronize(ORDERED_COLLECTION KEY_GENERIC_TYPE c) {
|
||||
return c instanceof SynchronizedOrderedCollection ? c : new SynchronizedOrderedCollectionBRACES(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized ordered Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
* @param mutex is the controller of the synchronization block.
|
||||
* @Type(T)
|
||||
* @return a synchronized ordered collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ORDERED_COLLECTION KEY_GENERIC_TYPE synchronize(ORDERED_COLLECTION KEY_GENERIC_TYPE c, Object mutex) {
|
||||
return c instanceof SynchronizedOrderedCollection ? c : new SynchronizedOrderedCollectionBRACES(c, mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
@ -668,6 +702,38 @@ public class COLLECTIONS
|
||||
@Override
|
||||
public SingletonCollection KEY_GENERIC_TYPE copy() { return new SingletonCollectionBRACES(element); }
|
||||
}
|
||||
/**
|
||||
* Synchronized Ordered Collection Wrapper for the synchronizedCollection function
|
||||
* @Type(T)
|
||||
*/
|
||||
public static class SynchronizedOrderedCollection KEY_GENERIC_TYPE extends SynchronizedCollection KEY_GENERIC_TYPE implements ORDERED_COLLECTION KEY_GENERIC_TYPE {
|
||||
ORDERED_COLLECTION KEY_GENERIC_TYPE c;
|
||||
|
||||
SynchronizedOrderedCollection(ORDERED_COLLECTION KEY_GENERIC_TYPE c, Object mutex) {
|
||||
super(c, mutex);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
SynchronizedOrderedCollection(ORDERED_COLLECTION KEY_GENERIC_TYPE c) {
|
||||
super(c);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORDERED_COLLECTION KEY_GENERIC_TYPE reversed() { return COLLECTIONS.synchronize(c.reversed(), mutex); }
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE e) { synchronized(mutex) { this.c.addFirst(e); } }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE e) { synchronized(mutex) { this.c.addLast(e); } }
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() { synchronized(mutex) { return this.c.GET_FIRST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { synchronized(mutex) { return this.c.REMOVE_FIRST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() { synchronized(mutex) { return this.c.GET_LAST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { synchronized(mutex) { return this.c.REMOVE_LAST_KEY(); } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronized Collection Wrapper for the synchronizedCollection function
|
||||
@ -810,6 +876,34 @@ public class COLLECTIONS
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.count(filter); } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmodifyable Ordered Collection Wrapper for the unmodifyableCollection method
|
||||
* @Type(T)
|
||||
*/
|
||||
public static class UnmodifiableOrderedCollection KEY_GENERIC_TYPE extends UnmodifiableCollection KEY_GENERIC_TYPE implements ORDERED_COLLECTION KEY_GENERIC_TYPE {
|
||||
ORDERED_COLLECTION KEY_GENERIC_TYPE c;
|
||||
|
||||
UnmodifiableOrderedCollection(ORDERED_COLLECTION KEY_GENERIC_TYPE c) {
|
||||
super(c);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORDERED_COLLECTION KEY_GENERIC_TYPE reversed() { return COLLECTIONS.unmodifiable(c.reversed()); }
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() { return c.GET_FIRST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() { return c.GET_LAST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmodifyable Collection Wrapper for the unmodifyableCollection method
|
||||
* @Type(T)
|
||||
|
||||
@ -342,6 +342,8 @@ public class ITERABLES
|
||||
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument APPLY test applyAsByte applyAsShort applyAsInt applyAsLong applyAsFloat applyAsDouble
|
||||
#argument DATA_TYPE Boolean Byte Short Int Long Float Double
|
||||
#argument FILTER_TYPE BOOLEAN_COLLECTION_MODULE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
|
||||
#if FILTER_TYPE
|
||||
private static class MAPPED_TYPEIterable<E> implements OUTPUT_ITERABLE, ISizeProvider
|
||||
{
|
||||
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
||||
@ -369,6 +371,7 @@ public class ITERABLES
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
private static class MappedIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>, ISizeProvider
|
||||
|
||||
@ -25,7 +25,7 @@ import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
#argument PACKAGE bytes shorts ints longs floats doubles
|
||||
#argument MAPPER ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument FILTER_TYPE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
|
||||
#if BOOLEAN_COLLECTION_MODULE
|
||||
#if FILTER_TYPE
|
||||
import speiger.src.collections.objects.functions.function.MAPPER;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#endif
|
||||
@ -65,7 +65,7 @@ public class ITERATORS
|
||||
* @Type(T)
|
||||
* @return an empty iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES EmptyIterator KEY_GENERIC_TYPE empty() {
|
||||
public static GENERIC_KEY_BRACES LIST_ITERATOR KEY_GENERIC_TYPE empty() {
|
||||
#if TYPE_OBJECT
|
||||
return (EmptyIterator<KEY_TYPE>)EMPTY;
|
||||
#else
|
||||
@ -400,7 +400,7 @@ public class ITERATORS
|
||||
* @ArrayType(T)
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE... a) {
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE wrap(KEY_TYPE... a) {
|
||||
return wrap(a, 0, a.length);
|
||||
}
|
||||
|
||||
@ -412,7 +412,7 @@ public class ITERATORS
|
||||
* @ArrayType(T)
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int start, int end) {
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int start, int end) {
|
||||
return new ArrayIteratorBRACES(a, start, end);
|
||||
}
|
||||
|
||||
@ -925,6 +925,8 @@ public class ITERATORS
|
||||
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument APPLY test applyAsByte applyAsShort applyAsInt applyAsLong applyAsFloat applyAsDouble
|
||||
#argument DATA_TYPE boolean byte short int long float double
|
||||
#argument FILTER_TYPE BOOLEAN_COLLECTION_MODULE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
|
||||
#if FILTER_TYPE
|
||||
private static class MAPPED_TYPEIterator<E> implements OUTPUT_ITERATOR
|
||||
{
|
||||
ITERATOR<E> iterator;
|
||||
@ -951,6 +953,7 @@ public class ITERATORS
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
private static class FlatMappedIterator KSS_GENERIC_TYPE<E, T,[SPACE]V extends Iterable<T>> implements ObjectIterator<T>
|
||||
|
||||
@ -45,7 +45,7 @@ public class LISTS
|
||||
* @Type(T)
|
||||
* @return an empty list
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES EmptyList KEY_GENERIC_TYPE empty() {
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE empty() {
|
||||
#if TYPE_OBJECT
|
||||
return (EmptyList<KEY_TYPE>)EMPTY;
|
||||
#else
|
||||
|
||||
@ -371,17 +371,19 @@ public class SETS
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator() { return ITERATORS.unmodifiable(s.reverseIterator()); }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
|
||||
public KEY_TYPE GET_FIRST_KEY() { return s.GET_FIRST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
|
||||
public KEY_TYPE GET_LAST_KEY() { return s.GET_LAST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -660,17 +662,19 @@ public class SETS
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator() { synchronized(mutex) { return s.reverseIterator(); } }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
|
||||
public KEY_TYPE GET_FIRST_KEY() { synchronized(mutex) { return s.GET_FIRST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { synchronized(mutex) { return s.REMOVE_FIRST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
|
||||
public KEY_TYPE GET_LAST_KEY() { synchronized(mutex) { return s.GET_LAST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { synchronized(mutex) { return s.REMOVE_LAST_KEY(); } }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -56,6 +56,9 @@ import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
#endif
|
||||
@ -553,6 +556,10 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@ -573,13 +580,25 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { return map.lastEntry(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { return map.copy(); }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keys == null) keys = SETS.unmodifiable(map.keySet());
|
||||
return (ORDERED_SET KEY_GENERIC_TYPE)keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(values == null) values = VALUE_COLLECTIONS.unmodifiable(map.values());
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)values;
|
||||
}
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new UnmodifyableOrderedEntrySetKV_BRACES(map.ENTRY_SET());
|
||||
@ -749,15 +768,17 @@ public class MAPS
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() { return ObjectIterators.unmodifiable(set.iterator()); }
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() { return ObjectIterators.unmodifiable(set.reverseIterator()); }
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement) { return ObjectIterators.unmodifiable(set.iterator(fromElement)); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() { return set.first(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() { return set.getFirst(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() { throw new UnsupportedOperationException(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() { return set.last(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() { return set.getLast(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() { throw new UnsupportedOperationException(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -938,6 +959,10 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToLast(key, value); } }
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putFirst(key, value); } }
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putLast(key, value); } }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.moveToFirst(key); } }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { synchronized(mutex) { return map.moveToLast(key); } }
|
||||
@ -958,13 +983,25 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { synchronized(mutex) { return map.LAST_ENTRY_VALUE(); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { synchronized(mutex) { return map.firstEntry(); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { synchronized(mutex) { return map.lastEntry(); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { synchronized(mutex) { return map.pollFirstEntry(); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { synchronized(mutex) { return map.pollLastEntry(); } }
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { synchronized(mutex) { return map.copy(); } }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keys == null) keys = SETS.synchronize(map.keySet(), mutex);
|
||||
return (ORDERED_SET KEY_GENERIC_TYPE)keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(values == null) values = VALUE_COLLECTIONS.synchronize(map.values(), mutex);
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)values;
|
||||
}
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = ObjectSets.synchronize(map.ENTRY_SET(), mutex);
|
||||
|
||||
@ -1,16 +1,29 @@
|
||||
package speiger.src.testers.PACKAGE.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.testing.AbstractTester;
|
||||
import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
|
||||
import com.google.common.collect.testing.Helpers;
|
||||
import com.google.common.collect.testing.OneSizeTestContainerGenerator;
|
||||
import com.google.common.collect.testing.SampleElements;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
import com.google.common.collect.testing.features.Feature;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.PACKAGE.utils.LISTS;
|
||||
import speiger.src.testers.PACKAGE.generators.TEST_ORDERED_SET_GENERATOR;
|
||||
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPEOrderedSetMoveTester;
|
||||
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPEOrderedSetIterationTester;
|
||||
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPEOrderedSetNavigationTester;
|
||||
import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS;
|
||||
import speiger.src.testers.utils.SpecialFeature;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ORDERED_SET_TEST_BUILDER KEY_GENERIC_TYPE extends SET_TEST_BUILDER KEY_GENERIC_TYPE {
|
||||
@ -35,4 +48,68 @@ public class ORDERED_SET_TEST_BUILDER KEY_GENERIC_TYPE extends SET_TEST_BUILDER
|
||||
#endignore
|
||||
return super.createTestSuite();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<TestSuite> createDerivedSuites(
|
||||
FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Collection<CLASS_TYPE>, CLASS_TYPE>> parentBuilder) {
|
||||
List<TestSuite> derivedSuites = super.createDerivedSuites(parentBuilder);
|
||||
|
||||
if (!parentBuilder.getFeatures().contains(SpecialFeature.REVERSE)) {
|
||||
derivedSuites.add(createReverseSuite(parentBuilder));
|
||||
}
|
||||
|
||||
return derivedSuites;
|
||||
}
|
||||
|
||||
private TestSuite createReverseSuite(FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Collection<CLASS_TYPE>, CLASS_TYPE>> parentBuilder) {
|
||||
TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE delegate = (TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE) parentBuilder.getSubjectGenerator().getInnerGenerator();
|
||||
|
||||
List<Feature<?>> features = new ArrayList<>();
|
||||
features.add(SpecialFeature.REVERSE);
|
||||
features.addAll(parentBuilder.getFeatures());
|
||||
features.remove(SpecialFeature.COPYING);
|
||||
features.remove(SpecialFeature.CHILDREN_COPY);
|
||||
|
||||
return ORDERED_SET_TEST_BUILDER.using(new TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE() {
|
||||
@Override
|
||||
public SampleElements<CLASS_TYPE> samples() {
|
||||
return delegate.samples();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() {
|
||||
return delegate.getSamples();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) {
|
||||
return insertionOrder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<CLASS_TYPE> order(List<CLASS_TYPE> insertionOrder) {
|
||||
return insertionOrder;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements) {
|
||||
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(elements);
|
||||
LISTS.reverse(list);
|
||||
return delegate.create(list.TO_ARRAY()).reversed();
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE create(Object... elements) {
|
||||
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
for (Object e : elements) {
|
||||
list.add(CLASS_TO_KEY(e));
|
||||
}
|
||||
LISTS.reverse(list);
|
||||
return delegate.create(list.toArray()).reversed();
|
||||
}
|
||||
}).named(parentBuilder.getName() + " reversing").withFeatures(features)
|
||||
.suppressing(parentBuilder.getSuppressedTests()).createTestSuite();
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,21 +238,17 @@ public class MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MapTestSuiteBuilder
|
||||
private static Set<Feature<?>> computeEntrySetFeatures(Set<Feature<?>> mapFeatures) {
|
||||
Set<Feature<?>> entrySetFeatures = MapTestSuiteBuilder.computeCommonDerivedCollectionFeatures(mapFeatures);
|
||||
#ignore
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_ENTRY_QUERIES)) {
|
||||
entrySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||
}
|
||||
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) {
|
||||
entrySetFeatures.add(SpecialFeature.COPYING);
|
||||
}
|
||||
else {
|
||||
entrySetFeatures.remove(SpecialFeature.COPYING);
|
||||
}
|
||||
if(mapFeatures.contains(SpecialFeature.MODIFIABLE)) {
|
||||
entrySetFeatures.add(SpecialFeature.MODIFIABLE);
|
||||
}
|
||||
else {
|
||||
entrySetFeatures.remove(SpecialFeature.MODIFIABLE);
|
||||
}
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_ENTRY_QUERIES)) entrySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) entrySetFeatures.add(SpecialFeature.COPYING);
|
||||
else entrySetFeatures.remove(SpecialFeature.COPYING);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.MODIFIABLE)) entrySetFeatures.add(SpecialFeature.MODIFIABLE);
|
||||
else entrySetFeatures.remove(SpecialFeature.MODIFIABLE);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.REVERSE)) entrySetFeatures.add(SpecialFeature.REVERSE);
|
||||
else entrySetFeatures.remove(SpecialFeature.REVERSE);
|
||||
|
||||
entrySetFeatures.add(SpecialFeature.MAP_ENTRY);
|
||||
#endignore
|
||||
return entrySetFeatures;
|
||||
@ -262,23 +258,17 @@ public class MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MapTestSuiteBuilder
|
||||
Set<Feature<?>> keySetFeatures = MapTestSuiteBuilder.computeCommonDerivedCollectionFeatures(mapFeatures);
|
||||
#ignore
|
||||
keySetFeatures.add(CollectionFeature.SUBSET_VIEW);
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEYS)) {
|
||||
keySetFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||
} else if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEY_QUERIES)) {
|
||||
keySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||
}
|
||||
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) {
|
||||
keySetFeatures.add(SpecialFeature.COPYING);
|
||||
}
|
||||
else {
|
||||
keySetFeatures.remove(SpecialFeature.COPYING);
|
||||
}
|
||||
if(mapFeatures.contains(SpecialFeature.MODIFIABLE)) {
|
||||
keySetFeatures.add(SpecialFeature.MODIFIABLE);
|
||||
}
|
||||
else {
|
||||
keySetFeatures.remove(SpecialFeature.MODIFIABLE);
|
||||
}
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEYS)) keySetFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||
else if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEY_QUERIES)) keySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) keySetFeatures.add(SpecialFeature.COPYING);
|
||||
else keySetFeatures.remove(SpecialFeature.COPYING);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.MODIFIABLE)) keySetFeatures.add(SpecialFeature.MODIFIABLE);
|
||||
else keySetFeatures.remove(SpecialFeature.MODIFIABLE);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.REVERSE)) keySetFeatures.add(SpecialFeature.REVERSE);
|
||||
else keySetFeatures.remove(SpecialFeature.REVERSE);
|
||||
#endignore
|
||||
return keySetFeatures;
|
||||
}
|
||||
@ -287,18 +277,15 @@ public class MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MapTestSuiteBuilder
|
||||
private static Set<Feature<?>> computeValuesCollectionFeatures(Set<Feature<?>> mapFeatures) {
|
||||
Set<Feature<?>> valuesCollectionFeatures = MapTestSuiteBuilder.computeCommonDerivedCollectionFeatures(mapFeatures);
|
||||
#ignore
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUE_QUERIES)) {
|
||||
valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||
}
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) {
|
||||
valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||
}
|
||||
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) {
|
||||
valuesCollectionFeatures.add(SpecialFeature.COPYING);
|
||||
}
|
||||
else {
|
||||
valuesCollectionFeatures.remove(SpecialFeature.COPYING);
|
||||
}
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUE_QUERIES)) valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) valuesCollectionFeatures.add(SpecialFeature.COPYING);
|
||||
else valuesCollectionFeatures.remove(SpecialFeature.COPYING);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.REVERSE)) valuesCollectionFeatures.add(SpecialFeature.REVERSE);
|
||||
else valuesCollectionFeatures.remove(SpecialFeature.REVERSE);
|
||||
#endignore
|
||||
return valuesCollectionFeatures;
|
||||
}
|
||||
|
||||
@ -1,9 +1,14 @@
|
||||
package speiger.src.testers.PACKAGE.builder.maps;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.testing.AbstractTester;
|
||||
import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
|
||||
import com.google.common.collect.testing.OneSizeTestContainerGenerator;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
import com.google.common.collect.testing.features.Feature;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
@ -12,6 +17,7 @@ import speiger.src.testers.PACKAGE.builder.SET_TEST_BUILDER;
|
||||
import speiger.src.testers.PACKAGE.generators.TEST_ORDERED_SET_GENERATOR;
|
||||
import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR;
|
||||
import speiger.src.testers.PACKAGE.generators.maps.TEST_ORDERED_MAP_GENERATOR;
|
||||
import speiger.src.testers.PACKAGE.impl.maps.DERIVED_MAP_GENERATORS;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester;
|
||||
#if !TYPE_OBJECT
|
||||
@ -20,6 +26,7 @@ import speiger.src.testers.objects.generators.TestObjectSetGenerator;
|
||||
import speiger.src.testers.objects.builder.ObjectOrderedSetTestSuiteBuilder;
|
||||
import speiger.src.testers.objects.generators.TestObjectOrderedSetGenerator;
|
||||
#endif
|
||||
import speiger.src.testers.utils.SpecialFeature;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE
|
||||
@ -45,6 +52,15 @@ public class ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BU
|
||||
return super.createTestSuite();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>>> parentBuilder) {
|
||||
List<TestSuite> derivedSuites = super.createDerivedSuites(parentBuilder);
|
||||
if (!parentBuilder.getFeatures().contains(SpecialFeature.REVERSE)) {
|
||||
derivedSuites.add(createReverseSuite(parentBuilder));
|
||||
}
|
||||
return derivedSuites;
|
||||
}
|
||||
|
||||
protected ObjectSetTestSuiteBuilder<MAP.Entry KEY_VALUE_GENERIC_TYPE> createDerivedEntrySetSuite(TestObjectSetGenerator<MAP.Entry KEY_VALUE_GENERIC_TYPE> entrySetGenerator) {
|
||||
return ObjectOrderedSetTestSuiteBuilder.using((TestObjectOrderedSetGenerator<MAP.Entry KEY_VALUE_GENERIC_TYPE>)entrySetGenerator);
|
||||
}
|
||||
@ -52,4 +68,17 @@ public class ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BU
|
||||
protected SET_TEST_BUILDER KEY_GENERIC_TYPE createDerivedKeySetSuite(TEST_SET_GENERATOR KEY_GENERIC_TYPE generator) {
|
||||
return ORDERED_SET_TEST_BUILDER.using((TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE)generator);
|
||||
}
|
||||
|
||||
private TestSuite createReverseSuite(FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>>> parentBuilder) {
|
||||
TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE delegate = (TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) parentBuilder.getSubjectGenerator().getInnerGenerator();
|
||||
|
||||
List<Feature<?>> features = new ArrayList<>();
|
||||
features.add(SpecialFeature.REVERSE);
|
||||
features.addAll(parentBuilder.getFeatures());
|
||||
features.remove(SpecialFeature.COPYING);
|
||||
features.remove(SpecialFeature.CHILDREN_COPY);
|
||||
return ORDERED_MAP_TEST_BUILDER.using(new DERIVED_MAP_GENERATORS.ReverseTestOrderedMapGenerator(delegate))
|
||||
.named(parentBuilder.getName() + " reversed").withFeatures(features)
|
||||
.suppressing(parentBuilder.getSuppressedTests()).createTestSuite();
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP.Entry;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
@ -206,6 +207,22 @@ public class DERIVED_MAP_GENERATORS {
|
||||
}
|
||||
}
|
||||
|
||||
public static class ReverseTestOrderedMapGenerator KEY_VALUE_GENERIC_TYPE extends MapGenerator KEY_VALUE_GENERIC_TYPE implements TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE {
|
||||
TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent;
|
||||
|
||||
public ReverseTestOrderedMapGenerator(TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent) {
|
||||
super(parent);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE create(Entry KEY_VALUE_GENERIC_TYPE... elements) {
|
||||
ObjectList<Entry KEY_VALUE_GENERIC_TYPE> entries = new ObjectArrayList<Entry KEY_VALUE_GENERIC_TYPE>(elements);
|
||||
ObjectLists.reverse(entries);
|
||||
return ((ORDERED_MAP KEY_VALUE_GENERIC_TYPE)parent.create(entries.toArray(Entry[]::new))).reversed();
|
||||
}
|
||||
}
|
||||
|
||||
public static class MapGenerator KEY_VALUE_GENERIC_TYPE implements TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent;
|
||||
|
||||
@ -45,10 +45,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testaddMoveToFirstMissing()
|
||||
{
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(true, orderedSet.addAndMoveToFirst(e4()));
|
||||
assertNotEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(e4(), orderedSet.FIRST_KEY());
|
||||
assertNotEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(e4(), orderedSet.GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -57,10 +57,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testaddMoveToFirstPreset()
|
||||
{
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(false, orderedSet.addAndMoveToFirst(c));
|
||||
assertNotEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(c, orderedSet.FIRST_KEY());
|
||||
assertNotEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(c, orderedSet.GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -69,10 +69,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testaddMoveToLastMissing()
|
||||
{
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(true, orderedSet.addAndMoveToLast(e4()));
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(e4(), orderedSet.LAST_KEY());
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(e4(), orderedSet.GET_LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -81,10 +81,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testaddMoveToLastPreset()
|
||||
{
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(false, orderedSet.addAndMoveToLast(a));
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(a, orderedSet.LAST_KEY());
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(a, orderedSet.GET_LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -93,9 +93,9 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveToFirstMissing()
|
||||
{
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(false, orderedSet.moveToFirst(e4()));
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -104,10 +104,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveToFirstPreset()
|
||||
{
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(true, orderedSet.moveToFirst(c));
|
||||
assertNotEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(c, orderedSet.FIRST_KEY());
|
||||
assertNotEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(c, orderedSet.GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -116,9 +116,9 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveToLastMissing()
|
||||
{
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(false, orderedSet.moveToLast(e4()));
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -127,10 +127,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveToLastPreset()
|
||||
{
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(true, orderedSet.moveToLast(a));
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(a, orderedSet.LAST_KEY());
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(a, orderedSet.GET_LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -139,10 +139,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveCenterToLast()
|
||||
{
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertTrue(orderedSet.moveToLast(e1()));
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(e1(), orderedSet.LAST_KEY());
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(e1(), orderedSet.GET_LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -151,10 +151,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveCenterToFirst()
|
||||
{
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertTrue(orderedSet.moveToFirst(e1()));
|
||||
assertNotEquals(c, orderedSet.FIRST_KEY());
|
||||
assertEquals(e1(), orderedSet.FIRST_KEY());
|
||||
assertNotEquals(c, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(e1(), orderedSet.GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -163,13 +163,13 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveForthAndBack()
|
||||
{
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertTrue(orderedSet.moveToLast(e0()));
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(a, orderedSet.LAST_KEY());
|
||||
assertNotEquals(a, orderedSet.FIRST_KEY());
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(a, orderedSet.GET_LAST_KEY());
|
||||
assertNotEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertTrue(orderedSet.moveToFirst(e0()));
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -178,13 +178,13 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveBackAndForth()
|
||||
{
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertTrue(orderedSet.moveToFirst(e2()));
|
||||
assertNotEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(c, orderedSet.FIRST_KEY());
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertNotEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(c, orderedSet.GET_FIRST_KEY());
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertTrue(orderedSet.moveToLast(e2()));
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -193,13 +193,13 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testAddForthAndBack()
|
||||
{
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertFalse(orderedSet.addAndMoveToLast(e0()));
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(a, orderedSet.LAST_KEY());
|
||||
assertNotEquals(a, orderedSet.FIRST_KEY());
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(a, orderedSet.GET_LAST_KEY());
|
||||
assertNotEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertFalse(orderedSet.addAndMoveToFirst(e0()));
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -208,13 +208,13 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testAddBackAndForth()
|
||||
{
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertFalse(orderedSet.addAndMoveToFirst(e2()));
|
||||
assertNotEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(c, orderedSet.FIRST_KEY());
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertNotEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(c, orderedSet.GET_FIRST_KEY());
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertFalse(orderedSet.addAndMoveToLast(e2()));
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
|
||||
@ -68,7 +68,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
int polled = 0;
|
||||
int expectedPolls = orderedSet.size();
|
||||
while(polled < expectedPolls) {
|
||||
orderedSet.POLL_FIRST_KEY();
|
||||
orderedSet.REMOVE_FIRST_KEY();
|
||||
polled++;
|
||||
}
|
||||
assertTrue("Map should be empty", orderedSet.isEmpty());
|
||||
@ -82,7 +82,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
int polled = 0;
|
||||
int expectedPolls = orderedSet.size();
|
||||
while(polled < expectedPolls) {
|
||||
orderedSet.POLL_LAST_KEY();
|
||||
orderedSet.REMOVE_LAST_KEY();
|
||||
polled++;
|
||||
}
|
||||
assertTrue("Map should be empty", orderedSet.isEmpty());
|
||||
@ -94,8 +94,8 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testEmptySetPollFirst() {
|
||||
try {
|
||||
orderedSet.POLL_FIRST_KEY();
|
||||
fail("OrderedSet.POLL_FIRST_KEY should throw NoSuchElementException");
|
||||
orderedSet.REMOVE_FIRST_KEY();
|
||||
fail("OrderedSet.REMOVE_FIRST_KEY should throw NoSuchElementException");
|
||||
} catch (NoSuchElementException e) {
|
||||
}
|
||||
expectUnchanged();
|
||||
@ -107,8 +107,8 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testEmptySetPollLast() {
|
||||
try {
|
||||
orderedSet.POLL_LAST_KEY();
|
||||
fail("OrderedSet.POLL_LAST_KEY should throw NoSuchElementException");
|
||||
orderedSet.REMOVE_LAST_KEY();
|
||||
fail("OrderedSet.REMOVE_LAST_KEY should throw NoSuchElementException");
|
||||
} catch (NoSuchElementException e) {
|
||||
}
|
||||
expectUnchanged();
|
||||
@ -119,8 +119,8 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testUnsupportedSetPollFirst() {
|
||||
try {
|
||||
orderedSet.POLL_FIRST_KEY();
|
||||
fail("OrderedSet.POLL_FIRST_KEY should throw UnsupportedOperationException");
|
||||
orderedSet.REMOVE_FIRST_KEY();
|
||||
fail("OrderedSet.REMOVE_FIRST_KEY should throw UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
}
|
||||
expectUnchanged();
|
||||
@ -131,8 +131,8 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testUnsupportedSetPollLast() {
|
||||
try {
|
||||
orderedSet.POLL_LAST_KEY();
|
||||
fail("OrderedSet.POLL_LAST_KEY should throw UnsupportedOperationException");
|
||||
orderedSet.REMOVE_LAST_KEY();
|
||||
fail("OrderedSet.REMOVE_LAST_KEY should throw UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
}
|
||||
expectUnchanged();
|
||||
@ -143,7 +143,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
@CollectionSize.Require(ONE)
|
||||
#endignore
|
||||
public void testSingletonSetPollFirst() {
|
||||
assertEquals(a, orderedSet.POLL_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.REMOVE_FIRST_KEY());
|
||||
assertTrue(orderedSet.isEmpty());
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
@CollectionSize.Require(ONE)
|
||||
#endignore
|
||||
public void testSingletonSetPollLast() {
|
||||
assertEquals(a, orderedSet.POLL_LAST_KEY());
|
||||
assertEquals(a, orderedSet.REMOVE_LAST_KEY());
|
||||
assertTrue(orderedSet.isEmpty());
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
@CollectionSize.Require(SEVERAL)
|
||||
#endignore
|
||||
public void testPollFirst() {
|
||||
assertEquals(a, orderedSet.POLL_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.REMOVE_FIRST_KEY());
|
||||
assertEquals(values.subList(1, values.size()), HELPERS.copyToList(orderedSet));
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
@CollectionSize.Require(SEVERAL)
|
||||
#endignore
|
||||
public void testPollLast() {
|
||||
assertEquals(c, orderedSet.POLL_LAST_KEY());
|
||||
assertEquals(c, orderedSet.REMOVE_LAST_KEY());
|
||||
assertEquals(values.subList(0, values.size()-1), HELPERS.copyToList(orderedSet));
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testPollFirstUnsupported() {
|
||||
try {
|
||||
orderedSet.POLL_FIRST_KEY();
|
||||
orderedSet.REMOVE_FIRST_KEY();
|
||||
fail();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
}
|
||||
@ -190,7 +190,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testPollLastUnsupported() {
|
||||
try {
|
||||
orderedSet.POLL_LAST_KEY();
|
||||
orderedSet.REMOVE_LAST_KEY();
|
||||
fail();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
}
|
||||
@ -201,7 +201,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testEmptySetFirst() {
|
||||
try {
|
||||
orderedSet.FIRST_KEY();
|
||||
orderedSet.GET_FIRST_KEY();
|
||||
fail();
|
||||
} catch (NoSuchElementException e) {
|
||||
}
|
||||
@ -212,7 +212,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testEmptySetLast() {
|
||||
try {
|
||||
orderedSet.LAST_KEY();
|
||||
orderedSet.GET_LAST_KEY();
|
||||
fail();
|
||||
} catch (NoSuchElementException e) {
|
||||
}
|
||||
@ -222,27 +222,27 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
@CollectionSize.Require(ONE)
|
||||
#endignore
|
||||
public void testSingletonSetFirst() {
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@CollectionSize.Require(ONE)
|
||||
#endignore
|
||||
public void testSingletonSetLast() {
|
||||
assertEquals(a, orderedSet.LAST_KEY());
|
||||
assertEquals(a, orderedSet.GET_LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@CollectionSize.Require(SEVERAL)
|
||||
#endignore
|
||||
public void testFirst() {
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@CollectionSize.Require(SEVERAL)
|
||||
#endignore
|
||||
public void testLast() {
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,11 @@
|
||||
package speiger.src.collections.booleans.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.Objects;
|
||||
import java.util.AbstractCollection;
|
||||
|
||||
import speiger.src.collections.booleans.lists.BooleanListIterator;
|
||||
import speiger.src.collections.booleans.functions.BooleanConsumer;
|
||||
import speiger.src.collections.booleans.utils.BooleanIterators;
|
||||
import speiger.src.collections.booleans.utils.BooleanArrays;
|
||||
@ -249,4 +251,68 @@ public abstract class AbstractBooleanCollection extends AbstractCollection<Boole
|
||||
if (a.length > size()) a[size()] = false;
|
||||
return a;
|
||||
}
|
||||
|
||||
public static class ReverseBooleanOrderedCollection extends AbstractBooleanCollection implements BooleanOrderedCollection {
|
||||
BooleanOrderedCollection collection;
|
||||
Supplier<BooleanIterator> reverseIterator;
|
||||
|
||||
public ReverseBooleanOrderedCollection(BooleanOrderedCollection collection, Supplier<BooleanIterator> reverseIterator) {
|
||||
this.collection = collection;
|
||||
this.reverseIterator = reverseIterator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(boolean o) { return collection.add(o); }
|
||||
@Override
|
||||
public BooleanOrderedCollection reversed() { return collection; }
|
||||
@Override
|
||||
public void addFirst(boolean e) { collection.addLast(e); }
|
||||
@Override
|
||||
public void addLast(boolean e) { collection.addFirst(e); }
|
||||
@Override
|
||||
public boolean contains(boolean e) { return collection.contains(e); }
|
||||
@Override
|
||||
public boolean remBoolean(boolean e) { return collection.remBoolean(e); }
|
||||
@Override
|
||||
public void clear() { collection.clear(); }
|
||||
@Override
|
||||
public boolean getFirstBoolean() { return collection.getLastBoolean(); }
|
||||
@Override
|
||||
public boolean removeFirstBoolean() { return collection.removeLastBoolean(); }
|
||||
@Override
|
||||
public boolean getLastBoolean() { return collection.getFirstBoolean(); }
|
||||
@Override
|
||||
public boolean removeLastBoolean() { return collection.removeFirstBoolean(); }
|
||||
@Override
|
||||
public BooleanIterator iterator() { return reverseIterator.get(); }
|
||||
@Override
|
||||
public int size() { return collection.size(); }
|
||||
}
|
||||
|
||||
public static class ReverseBiIterator implements BooleanListIterator {
|
||||
BooleanListIterator it;
|
||||
|
||||
public ReverseBiIterator(BooleanListIterator it) {
|
||||
this.it = it;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextBoolean() { return it.previousBoolean(); }
|
||||
@Override
|
||||
public boolean hasNext() { return it.hasPrevious(); }
|
||||
@Override
|
||||
public boolean hasPrevious() { return it.hasNext(); }
|
||||
@Override
|
||||
public boolean previousBoolean() { return it.nextBoolean(); }
|
||||
@Override
|
||||
public void remove() { it.remove(); }
|
||||
@Override
|
||||
public int nextIndex() { return it.previousIndex(); }
|
||||
@Override
|
||||
public int previousIndex() { return it.nextIndex(); }
|
||||
@Override
|
||||
public void set(boolean e) { it.set(e); }
|
||||
@Override
|
||||
public void add(boolean e) { it.add(e); }
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
package speiger.src.collections.booleans.collections;
|
||||
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
/**
|
||||
* A Type-Specific {@link ObjectBidirectionalIterator} to reduce (un)boxing
|
||||
* This is a basically a {@link java.util.ListIterator} without the index functions.
|
||||
* Allowing to have a simple Bidirectional Iterator without having to keep track of the Iteration index.
|
||||
*/
|
||||
public interface BooleanBidirectionalIterator extends BooleanIterator, ObjectBidirectionalIterator<Boolean>
|
||||
public interface BooleanBidirectionalIterator extends BooleanIterator
|
||||
{
|
||||
/**
|
||||
* Returns true if the Iterator has a Previous element
|
||||
@ -19,11 +19,11 @@ public interface BooleanBidirectionalIterator extends BooleanIterator, ObjectBid
|
||||
*/
|
||||
public boolean previousBoolean();
|
||||
|
||||
/** {@inheritDoc}
|
||||
/**
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
* @return the Previous element of the iterator.+
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default Boolean previous() {
|
||||
return Boolean.valueOf(previousBoolean());
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
package speiger.src.collections.booleans.collections;
|
||||
|
||||
public interface BooleanOrderedCollection extends BooleanCollection {
|
||||
|
||||
BooleanOrderedCollection reversed();
|
||||
|
||||
/**
|
||||
* A method to add an element to the start of a collection
|
||||
* @param e that should be added at the start.
|
||||
*/
|
||||
public void addFirst(boolean e);
|
||||
|
||||
/**
|
||||
* A method to add an element to the end of a collection
|
||||
* @param e that should be added at the end.
|
||||
*/
|
||||
public void addLast(boolean e);
|
||||
|
||||
/**
|
||||
* A method to get the first element in the collection
|
||||
* @return first element in the collection
|
||||
*/
|
||||
public boolean getFirstBoolean();
|
||||
/**
|
||||
* A method to get and remove the first element in the collection
|
||||
* @return first element in the collection
|
||||
*/
|
||||
public boolean removeFirstBoolean();
|
||||
/**
|
||||
* A method to get the last element in the collection
|
||||
* @return last element in the collection
|
||||
*/
|
||||
public boolean getLastBoolean();
|
||||
/**
|
||||
* A method to get and remove the last element in the collection
|
||||
* @return last element in the collection
|
||||
*/
|
||||
public boolean removeLastBoolean();
|
||||
|
||||
}
|
||||
@ -466,7 +466,6 @@ public abstract class AbstractBooleanList extends AbstractBooleanCollection impl
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanSplititerator spliterator() { return BooleanSplititerators.createSplititerator(this, 16464); }
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import java.util.Objects;
|
||||
import java.util.Comparator;
|
||||
|
||||
import speiger.src.collections.booleans.collections.BooleanCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanOrderedCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanSplititerator;
|
||||
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
|
||||
import speiger.src.collections.booleans.functions.BooleanComparator;
|
||||
@ -17,7 +18,7 @@ import speiger.src.collections.booleans.utils.BooleanSplititerators;
|
||||
/**
|
||||
* A Type Specific List interface that reduces boxing/unboxing and adds a couple extra quality of life features
|
||||
*/
|
||||
public interface BooleanList extends BooleanCollection, List<Boolean>
|
||||
public interface BooleanList extends BooleanOrderedCollection, List<Boolean>
|
||||
{
|
||||
/**
|
||||
* A Type-Specific add Function to reduce (un)boxing
|
||||
@ -80,6 +81,24 @@ public interface BooleanList extends BooleanCollection, List<Boolean>
|
||||
*/
|
||||
public boolean addAll(int index, BooleanList c);
|
||||
|
||||
/**
|
||||
* A method to add an element to the start of a list
|
||||
* @param e that should be added at the start.
|
||||
*/
|
||||
@Override
|
||||
public default void addFirst(boolean e) {
|
||||
add(0, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* A method to add an element to the end of a list
|
||||
* @param e that should be added at the end.
|
||||
*/
|
||||
@Override
|
||||
public default void addLast(boolean e) {
|
||||
add(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns the first element of a List.
|
||||
* This function was introduced due to how annoying it is to get/remove the last element of a list.
|
||||
@ -392,7 +411,7 @@ public interface BooleanList extends BooleanCollection, List<Boolean>
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean add(Boolean e) {
|
||||
return BooleanCollection.super.add(e);
|
||||
return BooleanOrderedCollection.super.add(e);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
@ -442,7 +461,7 @@ public interface BooleanList extends BooleanCollection, List<Boolean>
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean contains(Object o) {
|
||||
return BooleanCollection.super.contains(o);
|
||||
return BooleanOrderedCollection.super.contains(o);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
@ -452,7 +471,7 @@ public interface BooleanList extends BooleanCollection, List<Boolean>
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean remove(Object o) {
|
||||
return BooleanCollection.super.remove(o);
|
||||
return BooleanOrderedCollection.super.remove(o);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
||||
@ -10,6 +10,7 @@ import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.collections.booleans.collections.AbstractBooleanCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanOrderedCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
import speiger.src.collections.booleans.functions.BooleanComparator;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
@ -48,6 +49,34 @@ public class BooleanCollections
|
||||
return c instanceof UnmodifiableCollection ? c : new UnmodifiableCollection(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Immutable Ordered Collection instance based on the instance given.
|
||||
* @param c that should be made immutable/unmodifiable
|
||||
* @return a unmodifiable Ordered collection wrapper. If the Collection already a unmodifiable wrapper then it just returns itself.
|
||||
*/
|
||||
public static BooleanOrderedCollection unmodifiable(BooleanOrderedCollection c) {
|
||||
return c instanceof UnmodifiableOrderedCollection ? c : new UnmodifiableOrderedCollection(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized ordered Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
* @return a synchronized ordered collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static BooleanOrderedCollection synchronize(BooleanOrderedCollection c) {
|
||||
return c instanceof SynchronizedOrderedCollection ? c : new SynchronizedOrderedCollection(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized ordered Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
* @param mutex is the controller of the synchronization block.
|
||||
* @return a synchronized ordered collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static BooleanOrderedCollection synchronize(BooleanOrderedCollection c, Object mutex) {
|
||||
return c instanceof SynchronizedOrderedCollection ? c : new SynchronizedOrderedCollection(c, mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
@ -288,6 +317,37 @@ public class BooleanCollections
|
||||
@Override
|
||||
public SingletonCollection copy() { return new SingletonCollection(element); }
|
||||
}
|
||||
/**
|
||||
* Synchronized Ordered Collection Wrapper for the synchronizedCollection function
|
||||
*/
|
||||
public static class SynchronizedOrderedCollection extends SynchronizedCollection implements BooleanOrderedCollection {
|
||||
BooleanOrderedCollection c;
|
||||
|
||||
SynchronizedOrderedCollection(BooleanOrderedCollection c, Object mutex) {
|
||||
super(c, mutex);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
SynchronizedOrderedCollection(BooleanOrderedCollection c) {
|
||||
super(c);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanOrderedCollection reversed() { return BooleanCollections.synchronize(c.reversed(), mutex); }
|
||||
@Override
|
||||
public void addFirst(boolean e) { synchronized(mutex) { this.c.addFirst(e); } }
|
||||
@Override
|
||||
public void addLast(boolean e) { synchronized(mutex) { this.c.addLast(e); } }
|
||||
@Override
|
||||
public boolean getFirstBoolean() { synchronized(mutex) { return this.c.getFirstBoolean(); } }
|
||||
@Override
|
||||
public boolean removeFirstBoolean() { synchronized(mutex) { return this.c.removeFirstBoolean(); } }
|
||||
@Override
|
||||
public boolean getLastBoolean() { synchronized(mutex) { return this.c.getLastBoolean(); } }
|
||||
@Override
|
||||
public boolean removeLastBoolean() { synchronized(mutex) { return this.c.removeLastBoolean(); } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronized Collection Wrapper for the synchronizedCollection function
|
||||
@ -407,6 +467,33 @@ public class BooleanCollections
|
||||
public int count(BooleanPredicate filter) { synchronized(mutex) { return c.count(filter); } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmodifyable Ordered Collection Wrapper for the unmodifyableCollection method
|
||||
*/
|
||||
public static class UnmodifiableOrderedCollection extends UnmodifiableCollection implements BooleanOrderedCollection {
|
||||
BooleanOrderedCollection c;
|
||||
|
||||
UnmodifiableOrderedCollection(BooleanOrderedCollection c) {
|
||||
super(c);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanOrderedCollection reversed() { return BooleanCollections.unmodifiable(c.reversed()); }
|
||||
@Override
|
||||
public void addFirst(boolean e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(boolean e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean getFirstBoolean() { return c.getFirstBoolean(); }
|
||||
@Override
|
||||
public boolean removeFirstBoolean() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean getLastBoolean() { return c.getLastBoolean(); }
|
||||
@Override
|
||||
public boolean removeLastBoolean() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmodifyable Collection Wrapper for the unmodifyableCollection method
|
||||
*/
|
||||
|
||||
@ -34,7 +34,7 @@ public class BooleanIterators
|
||||
* Returns a Immutable EmptyIterator instance that is automatically casted.
|
||||
* @return an empty iterator
|
||||
*/
|
||||
public static EmptyIterator empty() {
|
||||
public static BooleanListIterator empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
@ -303,7 +303,7 @@ public class BooleanIterators
|
||||
* @param a the array that should be wrapped
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static ArrayIterator wrap(boolean... a) {
|
||||
public static BooleanIterator wrap(boolean... a) {
|
||||
return wrap(a, 0, a.length);
|
||||
}
|
||||
|
||||
@ -314,7 +314,7 @@ public class BooleanIterators
|
||||
* @param end the index that should be ended.
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static ArrayIterator wrap(boolean[] a, int start, int end) {
|
||||
public static BooleanIterator wrap(boolean[] a, int start, int end) {
|
||||
return new ArrayIterator(a, start, end);
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ public class BooleanLists
|
||||
* Returns a Immutable EmptyList instance that is automatically casted.
|
||||
* @return an empty list
|
||||
*/
|
||||
public static EmptyList empty() {
|
||||
public static BooleanList empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
package speiger.src.collections.bytes.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.Objects;
|
||||
import java.util.AbstractCollection;
|
||||
|
||||
import speiger.src.collections.bytes.lists.ByteListIterator;
|
||||
import speiger.src.collections.bytes.functions.ByteConsumer;
|
||||
import speiger.src.collections.bytes.utils.ByteIterators;
|
||||
import speiger.src.collections.bytes.utils.ByteArrays;
|
||||
@ -249,4 +251,68 @@ public abstract class AbstractByteCollection extends AbstractCollection<Byte> im
|
||||
if (a.length > size()) a[size()] = (byte)0;
|
||||
return a;
|
||||
}
|
||||
|
||||
public static class ReverseByteOrderedCollection extends AbstractByteCollection implements ByteOrderedCollection {
|
||||
ByteOrderedCollection collection;
|
||||
Supplier<ByteIterator> reverseIterator;
|
||||
|
||||
public ReverseByteOrderedCollection(ByteOrderedCollection collection, Supplier<ByteIterator> reverseIterator) {
|
||||
this.collection = collection;
|
||||
this.reverseIterator = reverseIterator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(byte o) { return collection.add(o); }
|
||||
@Override
|
||||
public ByteOrderedCollection reversed() { return collection; }
|
||||
@Override
|
||||
public void addFirst(byte e) { collection.addLast(e); }
|
||||
@Override
|
||||
public void addLast(byte e) { collection.addFirst(e); }
|
||||
@Override
|
||||
public boolean contains(byte e) { return collection.contains(e); }
|
||||
@Override
|
||||
public boolean remByte(byte e) { return collection.remByte(e); }
|
||||
@Override
|
||||
public void clear() { collection.clear(); }
|
||||
@Override
|
||||
public byte getFirstByte() { return collection.getLastByte(); }
|
||||
@Override
|
||||
public byte removeFirstByte() { return collection.removeLastByte(); }
|
||||
@Override
|
||||
public byte getLastByte() { return collection.getFirstByte(); }
|
||||
@Override
|
||||
public byte removeLastByte() { return collection.removeFirstByte(); }
|
||||
@Override
|
||||
public ByteIterator iterator() { return reverseIterator.get(); }
|
||||
@Override
|
||||
public int size() { return collection.size(); }
|
||||
}
|
||||
|
||||
public static class ReverseBiIterator implements ByteListIterator {
|
||||
ByteListIterator it;
|
||||
|
||||
public ReverseBiIterator(ByteListIterator it) {
|
||||
this.it = it;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte nextByte() { return it.previousByte(); }
|
||||
@Override
|
||||
public boolean hasNext() { return it.hasPrevious(); }
|
||||
@Override
|
||||
public boolean hasPrevious() { return it.hasNext(); }
|
||||
@Override
|
||||
public byte previousByte() { return it.nextByte(); }
|
||||
@Override
|
||||
public void remove() { it.remove(); }
|
||||
@Override
|
||||
public int nextIndex() { return it.previousIndex(); }
|
||||
@Override
|
||||
public int previousIndex() { return it.nextIndex(); }
|
||||
@Override
|
||||
public void set(byte e) { it.set(e); }
|
||||
@Override
|
||||
public void add(byte e) { it.add(e); }
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
package speiger.src.collections.bytes.collections;
|
||||
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
/**
|
||||
* A Type-Specific {@link ObjectBidirectionalIterator} to reduce (un)boxing
|
||||
* This is a basically a {@link java.util.ListIterator} without the index functions.
|
||||
* Allowing to have a simple Bidirectional Iterator without having to keep track of the Iteration index.
|
||||
*/
|
||||
public interface ByteBidirectionalIterator extends ByteIterator, ObjectBidirectionalIterator<Byte>
|
||||
public interface ByteBidirectionalIterator extends ByteIterator
|
||||
{
|
||||
/**
|
||||
* Returns true if the Iterator has a Previous element
|
||||
@ -19,11 +19,11 @@ public interface ByteBidirectionalIterator extends ByteIterator, ObjectBidirecti
|
||||
*/
|
||||
public byte previousByte();
|
||||
|
||||
/** {@inheritDoc}
|
||||
/**
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
* @return the Previous element of the iterator.+
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default Byte previous() {
|
||||
return Byte.valueOf(previousByte());
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
package speiger.src.collections.bytes.collections;
|
||||
|
||||
public interface ByteOrderedCollection extends ByteCollection {
|
||||
|
||||
ByteOrderedCollection reversed();
|
||||
|
||||
/**
|
||||
* A method to add an element to the start of a collection
|
||||
* @param e that should be added at the start.
|
||||
*/
|
||||
public void addFirst(byte e);
|
||||
|
||||
/**
|
||||
* A method to add an element to the end of a collection
|
||||
* @param e that should be added at the end.
|
||||
*/
|
||||
public void addLast(byte e);
|
||||
|
||||
/**
|
||||
* A method to get the first element in the collection
|
||||
* @return first element in the collection
|
||||
*/
|
||||
public byte getFirstByte();
|
||||
/**
|
||||
* A method to get and remove the first element in the collection
|
||||
* @return first element in the collection
|
||||
*/
|
||||
public byte removeFirstByte();
|
||||
/**
|
||||
* A method to get the last element in the collection
|
||||
* @return last element in the collection
|
||||
*/
|
||||
public byte getLastByte();
|
||||
/**
|
||||
* A method to get and remove the last element in the collection
|
||||
* @return last element in the collection
|
||||
*/
|
||||
public byte removeLastByte();
|
||||
|
||||
}
|
||||
@ -466,7 +466,6 @@ public abstract class AbstractByteList extends AbstractByteCollection implements
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteSplititerator spliterator() { return ByteSplititerators.createSplititerator(this, 16464); }
|
||||
|
||||
|
||||
@ -24,8 +24,7 @@ import speiger.src.collections.bytes.functions.ByteConsumer;
|
||||
import speiger.src.collections.bytes.utils.ByteArrays;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.StreamSupport;
|
||||
import speiger.src.collections.bytes.collections.ByteSplititerator;
|
||||
import java.util.stream.StreamSupport;import speiger.src.collections.bytes.collections.ByteSplititerator;
|
||||
import speiger.src.collections.bytes.utils.ByteSplititerators;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
@ -372,8 +371,7 @@ public class ByteLinkedList extends AbstractByteList implements BytePriorityDequ
|
||||
* Returns a Java-Type-Specific Parallel Stream to reduce boxing/unboxing.
|
||||
* @return a Stream of the closest java type
|
||||
*/
|
||||
public IntStream parallelPrimitiveStream() { return StreamSupport.intStream(new SplitIterator(this, first, 0), true); }
|
||||
/**
|
||||
public IntStream parallelPrimitiveStream() { return StreamSupport.intStream(new SplitIterator(this, first, 0), true); } /**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
*/
|
||||
|
||||
@ -9,6 +9,7 @@ import java.util.Comparator;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import speiger.src.collections.bytes.collections.ByteCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteOrderedCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteSplititerator;
|
||||
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
|
||||
import speiger.src.collections.bytes.functions.ByteComparator;
|
||||
@ -21,7 +22,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
/**
|
||||
* A Type Specific List interface that reduces boxing/unboxing and adds a couple extra quality of life features
|
||||
*/
|
||||
public interface ByteList extends ByteCollection, List<Byte>
|
||||
public interface ByteList extends ByteOrderedCollection, List<Byte>
|
||||
{
|
||||
/**
|
||||
* A Type-Specific add Function to reduce (un)boxing
|
||||
@ -84,6 +85,24 @@ public interface ByteList extends ByteCollection, List<Byte>
|
||||
*/
|
||||
public boolean addAll(int index, ByteList c);
|
||||
|
||||
/**
|
||||
* A method to add an element to the start of a list
|
||||
* @param e that should be added at the start.
|
||||
*/
|
||||
@Override
|
||||
public default void addFirst(byte e) {
|
||||
add(0, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* A method to add an element to the end of a list
|
||||
* @param e that should be added at the end.
|
||||
*/
|
||||
@Override
|
||||
public default void addLast(byte e) {
|
||||
add(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns the first element of a List.
|
||||
* This function was introduced due to how annoying it is to get/remove the last element of a list.
|
||||
@ -414,7 +433,7 @@ public interface ByteList extends ByteCollection, List<Byte>
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean add(Byte e) {
|
||||
return ByteCollection.super.add(e);
|
||||
return ByteOrderedCollection.super.add(e);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
@ -464,7 +483,7 @@ public interface ByteList extends ByteCollection, List<Byte>
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean contains(Object o) {
|
||||
return ByteCollection.super.contains(o);
|
||||
return ByteOrderedCollection.super.contains(o);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
@ -474,7 +493,7 @@ public interface ByteList extends ByteCollection, List<Byte>
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean remove(Object o) {
|
||||
return ByteCollection.super.remove(o);
|
||||
return ByteOrderedCollection.super.remove(o);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
||||
@ -9,6 +9,11 @@ import speiger.src.collections.bytes.functions.consumer.ByteBooleanConsumer;
|
||||
import speiger.src.collections.bytes.functions.function.BytePredicate;
|
||||
import speiger.src.collections.bytes.functions.function.ByteBooleanUnaryOperator;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2BooleanMap;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2BooleanOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.booleans.collections.BooleanOrderedCollection;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteSet;
|
||||
import speiger.src.collections.bytes.utils.maps.Byte2BooleanMaps;
|
||||
@ -85,7 +90,7 @@ public abstract class AbstractByte2BooleanMap extends AbstractMap<Byte, Boolean>
|
||||
public void putAll(Byte[] keys, Boolean[] values, int offset, int size) {
|
||||
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||
SanityChecks.checkArrayCapacity(values.length, offset, size);
|
||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||
for(int i = 0;i<size;i++) put(keys[i].byteValue(), values[i].booleanValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -408,6 +413,112 @@ public abstract class AbstractByte2BooleanMap extends AbstractMap<Byte, Boolean>
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static class ReversedByte2BooleanOrderedMap extends AbstractByte2BooleanMap implements Byte2BooleanOrderedMap {
|
||||
Byte2BooleanOrderedMap map;
|
||||
|
||||
public ReversedByte2BooleanOrderedMap(Byte2BooleanOrderedMap map) {
|
||||
this.map = map;
|
||||
}
|
||||
@Override
|
||||
public AbstractByte2BooleanMap setDefaultReturnValue(boolean v) {
|
||||
map.setDefaultReturnValue(v);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public boolean getDefaultReturnValue() { return map.getDefaultReturnValue(); }
|
||||
@Override
|
||||
public Byte2BooleanOrderedMap copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean put(byte key, boolean value) { return map.put(key, value); }
|
||||
@Override
|
||||
public boolean putIfAbsent(byte key, boolean value) { return map.putIfAbsent(key, value); }
|
||||
@Override
|
||||
public boolean remove(byte key) { return map.remove(key); }
|
||||
@Override
|
||||
public boolean remove(byte key, boolean value) { return map.remove(key, value); }
|
||||
@Override
|
||||
public boolean removeOrDefault(byte key, boolean defaultValue) { return map.removeOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public boolean containsKey(byte key) { return map.containsKey(key); }
|
||||
@Override
|
||||
public boolean containsValue(boolean value) { return map.containsValue(value); }
|
||||
@Override
|
||||
public boolean replace(byte key, boolean oldValue, boolean newValue) { return map.replace(key, oldValue, newValue); }
|
||||
@Override
|
||||
public boolean replace(byte key, boolean value) { return map.replace(key, value); }
|
||||
@Override
|
||||
public void replaceBooleans(Byte2BooleanMap m) { map.replaceBooleans(m); }
|
||||
@Override
|
||||
public void replaceBooleans(ByteBooleanUnaryOperator mappingFunction) { map.replaceBooleans(mappingFunction); }
|
||||
@Override
|
||||
public boolean computeBoolean(byte key, ByteBooleanUnaryOperator mappingFunction) { return map.computeBoolean(key, mappingFunction); }
|
||||
@Override
|
||||
public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { return map.computeBooleanIfAbsent(key, mappingFunction); }
|
||||
@Override
|
||||
public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { return map.supplyBooleanIfAbsent(key, valueProvider); }
|
||||
@Override
|
||||
public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { return map.computeBooleanIfPresent(key, mappingFunction); }
|
||||
@Override
|
||||
public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { return map.computeBooleanNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valueProvider) { return map.supplyBooleanIfAbsentNonDefault(key, valueProvider); }
|
||||
@Override
|
||||
public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public boolean mergeBoolean(byte key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { return map.mergeBoolean(key, value, mappingFunction); }
|
||||
@Override
|
||||
public boolean getOrDefault(byte key, boolean defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public boolean get(byte key) { return map.get(key); }
|
||||
@Override
|
||||
public boolean putAndMoveToFirst(byte key, boolean value) { return map.putAndMoveToLast(key, value); }
|
||||
@Override
|
||||
public boolean putAndMoveToLast(byte key, boolean value) { return map.putAndMoveToFirst(key, value); }
|
||||
@Override
|
||||
public boolean putFirst(byte key, boolean value) { return map.putLast(key, value); }
|
||||
@Override
|
||||
public boolean putLast(byte key, boolean value) { return map.putFirst(key, value); }
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) { return map.moveToLast(key); }
|
||||
@Override
|
||||
public boolean moveToLast(byte key) { return map.moveToFirst(key); }
|
||||
@Override
|
||||
public boolean getAndMoveToFirst(byte key) { return map.getAndMoveToLast(key); }
|
||||
@Override
|
||||
public boolean getAndMoveToLast(byte key) { return map.getAndMoveToFirst(key); }
|
||||
@Override
|
||||
public byte firstByteKey() { return map.lastByteKey(); }
|
||||
@Override
|
||||
public byte pollFirstByteKey() { return map.pollLastByteKey(); }
|
||||
@Override
|
||||
public byte lastByteKey() { return map.firstByteKey(); }
|
||||
@Override
|
||||
public byte pollLastByteKey() { return map.pollFirstByteKey(); }
|
||||
@Override
|
||||
public boolean firstBooleanValue() { return map.lastBooleanValue(); }
|
||||
@Override
|
||||
public boolean lastBooleanValue() { return map.firstBooleanValue(); }
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry firstEntry() { return map.lastEntry(); }
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry lastEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry pollFirstEntry() { return map.pollLastEntry(); }
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry pollLastEntry() { return map.pollFirstEntry(); }
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2BooleanMap.Entry> byte2BooleanEntrySet() { return new AbstractObjectSet.ReversedObjectOrderedSet<>(map.byte2BooleanEntrySet()); }
|
||||
@Override
|
||||
public ByteOrderedSet keySet() { return new AbstractByteSet.ReversedByteOrderedSet(map.keySet()); }
|
||||
@Override
|
||||
public BooleanOrderedCollection values() { return map.values().reversed(); }
|
||||
@Override
|
||||
public Byte2BooleanOrderedMap reversed() { return map; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A Simple Type Specific Entry class to reduce boxing/unboxing
|
||||
*/
|
||||
|
||||
@ -9,6 +9,11 @@ import speiger.src.collections.bytes.functions.consumer.ByteByteConsumer;
|
||||
import speiger.src.collections.bytes.functions.function.ByteUnaryOperator;
|
||||
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2ByteMap;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2ByteOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.bytes.collections.ByteOrderedCollection;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteSet;
|
||||
import speiger.src.collections.bytes.utils.maps.Byte2ByteMaps;
|
||||
@ -25,7 +30,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
*/
|
||||
public abstract class AbstractByte2ByteMap extends AbstractMap<Byte, Byte> implements Byte2ByteMap
|
||||
{
|
||||
protected byte defaultReturnValue = (byte)0;
|
||||
protected byte defaultReturnValue = (byte)-1;
|
||||
|
||||
@Override
|
||||
public byte getDefaultReturnValue() {
|
||||
@ -89,7 +94,7 @@ public abstract class AbstractByte2ByteMap extends AbstractMap<Byte, Byte> imple
|
||||
public void putAll(Byte[] keys, Byte[] values, int offset, int size) {
|
||||
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||
SanityChecks.checkArrayCapacity(values.length, offset, size);
|
||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||
for(int i = 0;i<size;i++) put(keys[i].byteValue(), values[i].byteValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -412,6 +417,116 @@ public abstract class AbstractByte2ByteMap extends AbstractMap<Byte, Byte> imple
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static class ReversedByte2ByteOrderedMap extends AbstractByte2ByteMap implements Byte2ByteOrderedMap {
|
||||
Byte2ByteOrderedMap map;
|
||||
|
||||
public ReversedByte2ByteOrderedMap(Byte2ByteOrderedMap map) {
|
||||
this.map = map;
|
||||
}
|
||||
@Override
|
||||
public AbstractByte2ByteMap setDefaultReturnValue(byte v) {
|
||||
map.setDefaultReturnValue(v);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public byte getDefaultReturnValue() { return map.getDefaultReturnValue(); }
|
||||
@Override
|
||||
public Byte2ByteOrderedMap copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public byte put(byte key, byte value) { return map.put(key, value); }
|
||||
@Override
|
||||
public byte putIfAbsent(byte key, byte value) { return map.putIfAbsent(key, value); }
|
||||
@Override
|
||||
public byte addTo(byte key, byte value) { return map.addTo(key, value); }
|
||||
@Override
|
||||
public byte subFrom(byte key, byte value) { return map.subFrom(key, value); }
|
||||
@Override
|
||||
public byte remove(byte key) { return map.remove(key); }
|
||||
@Override
|
||||
public boolean remove(byte key, byte value) { return map.remove(key, value); }
|
||||
@Override
|
||||
public byte removeOrDefault(byte key, byte defaultValue) { return map.removeOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public boolean containsKey(byte key) { return map.containsKey(key); }
|
||||
@Override
|
||||
public boolean containsValue(byte value) { return map.containsValue(value); }
|
||||
@Override
|
||||
public boolean replace(byte key, byte oldValue, byte newValue) { return map.replace(key, oldValue, newValue); }
|
||||
@Override
|
||||
public byte replace(byte key, byte value) { return map.replace(key, value); }
|
||||
@Override
|
||||
public void replaceBytes(Byte2ByteMap m) { map.replaceBytes(m); }
|
||||
@Override
|
||||
public void replaceBytes(ByteByteUnaryOperator mappingFunction) { map.replaceBytes(mappingFunction); }
|
||||
@Override
|
||||
public byte computeByte(byte key, ByteByteUnaryOperator mappingFunction) { return map.computeByte(key, mappingFunction); }
|
||||
@Override
|
||||
public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { return map.computeByteIfAbsent(key, mappingFunction); }
|
||||
@Override
|
||||
public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { return map.supplyByteIfAbsent(key, valueProvider); }
|
||||
@Override
|
||||
public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { return map.computeByteIfPresent(key, mappingFunction); }
|
||||
@Override
|
||||
public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { return map.computeByteNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { return map.supplyByteIfAbsentNonDefault(key, valueProvider); }
|
||||
@Override
|
||||
public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { return map.computeByteIfPresentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public byte mergeByte(byte key, byte value, ByteByteUnaryOperator mappingFunction) { return map.mergeByte(key, value, mappingFunction); }
|
||||
@Override
|
||||
public byte getOrDefault(byte key, byte defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public byte get(byte key) { return map.get(key); }
|
||||
@Override
|
||||
public byte putAndMoveToFirst(byte key, byte value) { return map.putAndMoveToLast(key, value); }
|
||||
@Override
|
||||
public byte putAndMoveToLast(byte key, byte value) { return map.putAndMoveToFirst(key, value); }
|
||||
@Override
|
||||
public byte putFirst(byte key, byte value) { return map.putLast(key, value); }
|
||||
@Override
|
||||
public byte putLast(byte key, byte value) { return map.putFirst(key, value); }
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) { return map.moveToLast(key); }
|
||||
@Override
|
||||
public boolean moveToLast(byte key) { return map.moveToFirst(key); }
|
||||
@Override
|
||||
public byte getAndMoveToFirst(byte key) { return map.getAndMoveToLast(key); }
|
||||
@Override
|
||||
public byte getAndMoveToLast(byte key) { return map.getAndMoveToFirst(key); }
|
||||
@Override
|
||||
public byte firstByteKey() { return map.lastByteKey(); }
|
||||
@Override
|
||||
public byte pollFirstByteKey() { return map.pollLastByteKey(); }
|
||||
@Override
|
||||
public byte lastByteKey() { return map.firstByteKey(); }
|
||||
@Override
|
||||
public byte pollLastByteKey() { return map.pollFirstByteKey(); }
|
||||
@Override
|
||||
public byte firstByteValue() { return map.lastByteValue(); }
|
||||
@Override
|
||||
public byte lastByteValue() { return map.firstByteValue(); }
|
||||
@Override
|
||||
public Byte2ByteMap.Entry firstEntry() { return map.lastEntry(); }
|
||||
@Override
|
||||
public Byte2ByteMap.Entry lastEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public Byte2ByteMap.Entry pollFirstEntry() { return map.pollLastEntry(); }
|
||||
@Override
|
||||
public Byte2ByteMap.Entry pollLastEntry() { return map.pollFirstEntry(); }
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2ByteMap.Entry> byte2ByteEntrySet() { return new AbstractObjectSet.ReversedObjectOrderedSet<>(map.byte2ByteEntrySet()); }
|
||||
@Override
|
||||
public ByteOrderedSet keySet() { return new AbstractByteSet.ReversedByteOrderedSet(map.keySet()); }
|
||||
@Override
|
||||
public ByteOrderedCollection values() { return map.values().reversed(); }
|
||||
@Override
|
||||
public Byte2ByteOrderedMap reversed() { return map; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A Simple Type Specific Entry class to reduce boxing/unboxing
|
||||
*/
|
||||
|
||||
@ -9,6 +9,11 @@ import speiger.src.collections.bytes.functions.consumer.ByteCharConsumer;
|
||||
import speiger.src.collections.bytes.functions.function.Byte2CharFunction;
|
||||
import speiger.src.collections.bytes.functions.function.ByteCharUnaryOperator;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2CharMap;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2CharOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.chars.collections.CharOrderedCollection;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteSet;
|
||||
import speiger.src.collections.bytes.utils.maps.Byte2CharMaps;
|
||||
@ -27,7 +32,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
*/
|
||||
public abstract class AbstractByte2CharMap extends AbstractMap<Byte, Character> implements Byte2CharMap
|
||||
{
|
||||
protected char defaultReturnValue = (char)0;
|
||||
protected char defaultReturnValue = (char)-1;
|
||||
|
||||
@Override
|
||||
public char getDefaultReturnValue() {
|
||||
@ -91,7 +96,7 @@ public abstract class AbstractByte2CharMap extends AbstractMap<Byte, Character>
|
||||
public void putAll(Byte[] keys, Character[] values, int offset, int size) {
|
||||
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||
SanityChecks.checkArrayCapacity(values.length, offset, size);
|
||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||
for(int i = 0;i<size;i++) put(keys[i].byteValue(), values[i].charValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -414,6 +419,116 @@ public abstract class AbstractByte2CharMap extends AbstractMap<Byte, Character>
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static class ReversedByte2CharOrderedMap extends AbstractByte2CharMap implements Byte2CharOrderedMap {
|
||||
Byte2CharOrderedMap map;
|
||||
|
||||
public ReversedByte2CharOrderedMap(Byte2CharOrderedMap map) {
|
||||
this.map = map;
|
||||
}
|
||||
@Override
|
||||
public AbstractByte2CharMap setDefaultReturnValue(char v) {
|
||||
map.setDefaultReturnValue(v);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public char getDefaultReturnValue() { return map.getDefaultReturnValue(); }
|
||||
@Override
|
||||
public Byte2CharOrderedMap copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public char put(byte key, char value) { return map.put(key, value); }
|
||||
@Override
|
||||
public char putIfAbsent(byte key, char value) { return map.putIfAbsent(key, value); }
|
||||
@Override
|
||||
public char addTo(byte key, char value) { return map.addTo(key, value); }
|
||||
@Override
|
||||
public char subFrom(byte key, char value) { return map.subFrom(key, value); }
|
||||
@Override
|
||||
public char remove(byte key) { return map.remove(key); }
|
||||
@Override
|
||||
public boolean remove(byte key, char value) { return map.remove(key, value); }
|
||||
@Override
|
||||
public char removeOrDefault(byte key, char defaultValue) { return map.removeOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public boolean containsKey(byte key) { return map.containsKey(key); }
|
||||
@Override
|
||||
public boolean containsValue(char value) { return map.containsValue(value); }
|
||||
@Override
|
||||
public boolean replace(byte key, char oldValue, char newValue) { return map.replace(key, oldValue, newValue); }
|
||||
@Override
|
||||
public char replace(byte key, char value) { return map.replace(key, value); }
|
||||
@Override
|
||||
public void replaceChars(Byte2CharMap m) { map.replaceChars(m); }
|
||||
@Override
|
||||
public void replaceChars(ByteCharUnaryOperator mappingFunction) { map.replaceChars(mappingFunction); }
|
||||
@Override
|
||||
public char computeChar(byte key, ByteCharUnaryOperator mappingFunction) { return map.computeChar(key, mappingFunction); }
|
||||
@Override
|
||||
public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { return map.computeCharIfAbsent(key, mappingFunction); }
|
||||
@Override
|
||||
public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { return map.supplyCharIfAbsent(key, valueProvider); }
|
||||
@Override
|
||||
public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { return map.computeCharIfPresent(key, mappingFunction); }
|
||||
@Override
|
||||
public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { return map.computeCharNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { return map.supplyCharIfAbsentNonDefault(key, valueProvider); }
|
||||
@Override
|
||||
public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { return map.computeCharIfPresentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public char mergeChar(byte key, char value, CharCharUnaryOperator mappingFunction) { return map.mergeChar(key, value, mappingFunction); }
|
||||
@Override
|
||||
public char getOrDefault(byte key, char defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public char get(byte key) { return map.get(key); }
|
||||
@Override
|
||||
public char putAndMoveToFirst(byte key, char value) { return map.putAndMoveToLast(key, value); }
|
||||
@Override
|
||||
public char putAndMoveToLast(byte key, char value) { return map.putAndMoveToFirst(key, value); }
|
||||
@Override
|
||||
public char putFirst(byte key, char value) { return map.putLast(key, value); }
|
||||
@Override
|
||||
public char putLast(byte key, char value) { return map.putFirst(key, value); }
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) { return map.moveToLast(key); }
|
||||
@Override
|
||||
public boolean moveToLast(byte key) { return map.moveToFirst(key); }
|
||||
@Override
|
||||
public char getAndMoveToFirst(byte key) { return map.getAndMoveToLast(key); }
|
||||
@Override
|
||||
public char getAndMoveToLast(byte key) { return map.getAndMoveToFirst(key); }
|
||||
@Override
|
||||
public byte firstByteKey() { return map.lastByteKey(); }
|
||||
@Override
|
||||
public byte pollFirstByteKey() { return map.pollLastByteKey(); }
|
||||
@Override
|
||||
public byte lastByteKey() { return map.firstByteKey(); }
|
||||
@Override
|
||||
public byte pollLastByteKey() { return map.pollFirstByteKey(); }
|
||||
@Override
|
||||
public char firstCharValue() { return map.lastCharValue(); }
|
||||
@Override
|
||||
public char lastCharValue() { return map.firstCharValue(); }
|
||||
@Override
|
||||
public Byte2CharMap.Entry firstEntry() { return map.lastEntry(); }
|
||||
@Override
|
||||
public Byte2CharMap.Entry lastEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public Byte2CharMap.Entry pollFirstEntry() { return map.pollLastEntry(); }
|
||||
@Override
|
||||
public Byte2CharMap.Entry pollLastEntry() { return map.pollFirstEntry(); }
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2CharMap.Entry> byte2CharEntrySet() { return new AbstractObjectSet.ReversedObjectOrderedSet<>(map.byte2CharEntrySet()); }
|
||||
@Override
|
||||
public ByteOrderedSet keySet() { return new AbstractByteSet.ReversedByteOrderedSet(map.keySet()); }
|
||||
@Override
|
||||
public CharOrderedCollection values() { return map.values().reversed(); }
|
||||
@Override
|
||||
public Byte2CharOrderedMap reversed() { return map; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A Simple Type Specific Entry class to reduce boxing/unboxing
|
||||
*/
|
||||
|
||||
@ -9,6 +9,11 @@ import speiger.src.collections.bytes.functions.consumer.ByteDoubleConsumer;
|
||||
import speiger.src.collections.bytes.functions.function.Byte2DoubleFunction;
|
||||
import speiger.src.collections.bytes.functions.function.ByteDoubleUnaryOperator;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2DoubleMap;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2DoubleOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.doubles.collections.DoubleOrderedCollection;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteSet;
|
||||
import speiger.src.collections.bytes.utils.maps.Byte2DoubleMaps;
|
||||
@ -27,7 +32,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
*/
|
||||
public abstract class AbstractByte2DoubleMap extends AbstractMap<Byte, Double> implements Byte2DoubleMap
|
||||
{
|
||||
protected double defaultReturnValue = 0D;
|
||||
protected double defaultReturnValue = -1D;
|
||||
|
||||
@Override
|
||||
public double getDefaultReturnValue() {
|
||||
@ -91,7 +96,7 @@ public abstract class AbstractByte2DoubleMap extends AbstractMap<Byte, Double> i
|
||||
public void putAll(Byte[] keys, Double[] values, int offset, int size) {
|
||||
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||
SanityChecks.checkArrayCapacity(values.length, offset, size);
|
||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||
for(int i = 0;i<size;i++) put(keys[i].byteValue(), values[i].doubleValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -414,6 +419,116 @@ public abstract class AbstractByte2DoubleMap extends AbstractMap<Byte, Double> i
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static class ReversedByte2DoubleOrderedMap extends AbstractByte2DoubleMap implements Byte2DoubleOrderedMap {
|
||||
Byte2DoubleOrderedMap map;
|
||||
|
||||
public ReversedByte2DoubleOrderedMap(Byte2DoubleOrderedMap map) {
|
||||
this.map = map;
|
||||
}
|
||||
@Override
|
||||
public AbstractByte2DoubleMap setDefaultReturnValue(double v) {
|
||||
map.setDefaultReturnValue(v);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public double getDefaultReturnValue() { return map.getDefaultReturnValue(); }
|
||||
@Override
|
||||
public Byte2DoubleOrderedMap copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public double put(byte key, double value) { return map.put(key, value); }
|
||||
@Override
|
||||
public double putIfAbsent(byte key, double value) { return map.putIfAbsent(key, value); }
|
||||
@Override
|
||||
public double addTo(byte key, double value) { return map.addTo(key, value); }
|
||||
@Override
|
||||
public double subFrom(byte key, double value) { return map.subFrom(key, value); }
|
||||
@Override
|
||||
public double remove(byte key) { return map.remove(key); }
|
||||
@Override
|
||||
public boolean remove(byte key, double value) { return map.remove(key, value); }
|
||||
@Override
|
||||
public double removeOrDefault(byte key, double defaultValue) { return map.removeOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public boolean containsKey(byte key) { return map.containsKey(key); }
|
||||
@Override
|
||||
public boolean containsValue(double value) { return map.containsValue(value); }
|
||||
@Override
|
||||
public boolean replace(byte key, double oldValue, double newValue) { return map.replace(key, oldValue, newValue); }
|
||||
@Override
|
||||
public double replace(byte key, double value) { return map.replace(key, value); }
|
||||
@Override
|
||||
public void replaceDoubles(Byte2DoubleMap m) { map.replaceDoubles(m); }
|
||||
@Override
|
||||
public void replaceDoubles(ByteDoubleUnaryOperator mappingFunction) { map.replaceDoubles(mappingFunction); }
|
||||
@Override
|
||||
public double computeDouble(byte key, ByteDoubleUnaryOperator mappingFunction) { return map.computeDouble(key, mappingFunction); }
|
||||
@Override
|
||||
public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { return map.computeDoubleIfAbsent(key, mappingFunction); }
|
||||
@Override
|
||||
public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { return map.supplyDoubleIfAbsent(key, valueProvider); }
|
||||
@Override
|
||||
public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { return map.computeDoubleIfPresent(key, mappingFunction); }
|
||||
@Override
|
||||
public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { return map.computeDoubleNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvider) { return map.supplyDoubleIfAbsentNonDefault(key, valueProvider); }
|
||||
@Override
|
||||
public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public double mergeDouble(byte key, double value, DoubleDoubleUnaryOperator mappingFunction) { return map.mergeDouble(key, value, mappingFunction); }
|
||||
@Override
|
||||
public double getOrDefault(byte key, double defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public double get(byte key) { return map.get(key); }
|
||||
@Override
|
||||
public double putAndMoveToFirst(byte key, double value) { return map.putAndMoveToLast(key, value); }
|
||||
@Override
|
||||
public double putAndMoveToLast(byte key, double value) { return map.putAndMoveToFirst(key, value); }
|
||||
@Override
|
||||
public double putFirst(byte key, double value) { return map.putLast(key, value); }
|
||||
@Override
|
||||
public double putLast(byte key, double value) { return map.putFirst(key, value); }
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) { return map.moveToLast(key); }
|
||||
@Override
|
||||
public boolean moveToLast(byte key) { return map.moveToFirst(key); }
|
||||
@Override
|
||||
public double getAndMoveToFirst(byte key) { return map.getAndMoveToLast(key); }
|
||||
@Override
|
||||
public double getAndMoveToLast(byte key) { return map.getAndMoveToFirst(key); }
|
||||
@Override
|
||||
public byte firstByteKey() { return map.lastByteKey(); }
|
||||
@Override
|
||||
public byte pollFirstByteKey() { return map.pollLastByteKey(); }
|
||||
@Override
|
||||
public byte lastByteKey() { return map.firstByteKey(); }
|
||||
@Override
|
||||
public byte pollLastByteKey() { return map.pollFirstByteKey(); }
|
||||
@Override
|
||||
public double firstDoubleValue() { return map.lastDoubleValue(); }
|
||||
@Override
|
||||
public double lastDoubleValue() { return map.firstDoubleValue(); }
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry firstEntry() { return map.lastEntry(); }
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry lastEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry pollFirstEntry() { return map.pollLastEntry(); }
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry pollLastEntry() { return map.pollFirstEntry(); }
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2DoubleMap.Entry> byte2DoubleEntrySet() { return new AbstractObjectSet.ReversedObjectOrderedSet<>(map.byte2DoubleEntrySet()); }
|
||||
@Override
|
||||
public ByteOrderedSet keySet() { return new AbstractByteSet.ReversedByteOrderedSet(map.keySet()); }
|
||||
@Override
|
||||
public DoubleOrderedCollection values() { return map.values().reversed(); }
|
||||
@Override
|
||||
public Byte2DoubleOrderedMap reversed() { return map; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A Simple Type Specific Entry class to reduce boxing/unboxing
|
||||
*/
|
||||
|
||||
@ -9,6 +9,11 @@ import speiger.src.collections.bytes.functions.consumer.ByteFloatConsumer;
|
||||
import speiger.src.collections.bytes.functions.function.Byte2FloatFunction;
|
||||
import speiger.src.collections.bytes.functions.function.ByteFloatUnaryOperator;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2FloatMap;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2FloatOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.floats.collections.FloatOrderedCollection;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteSet;
|
||||
import speiger.src.collections.bytes.utils.maps.Byte2FloatMaps;
|
||||
@ -27,7 +32,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
*/
|
||||
public abstract class AbstractByte2FloatMap extends AbstractMap<Byte, Float> implements Byte2FloatMap
|
||||
{
|
||||
protected float defaultReturnValue = 0F;
|
||||
protected float defaultReturnValue = -1F;
|
||||
|
||||
@Override
|
||||
public float getDefaultReturnValue() {
|
||||
@ -91,7 +96,7 @@ public abstract class AbstractByte2FloatMap extends AbstractMap<Byte, Float> imp
|
||||
public void putAll(Byte[] keys, Float[] values, int offset, int size) {
|
||||
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||
SanityChecks.checkArrayCapacity(values.length, offset, size);
|
||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||
for(int i = 0;i<size;i++) put(keys[i].byteValue(), values[i].floatValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -414,6 +419,116 @@ public abstract class AbstractByte2FloatMap extends AbstractMap<Byte, Float> imp
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static class ReversedByte2FloatOrderedMap extends AbstractByte2FloatMap implements Byte2FloatOrderedMap {
|
||||
Byte2FloatOrderedMap map;
|
||||
|
||||
public ReversedByte2FloatOrderedMap(Byte2FloatOrderedMap map) {
|
||||
this.map = map;
|
||||
}
|
||||
@Override
|
||||
public AbstractByte2FloatMap setDefaultReturnValue(float v) {
|
||||
map.setDefaultReturnValue(v);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public float getDefaultReturnValue() { return map.getDefaultReturnValue(); }
|
||||
@Override
|
||||
public Byte2FloatOrderedMap copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public float put(byte key, float value) { return map.put(key, value); }
|
||||
@Override
|
||||
public float putIfAbsent(byte key, float value) { return map.putIfAbsent(key, value); }
|
||||
@Override
|
||||
public float addTo(byte key, float value) { return map.addTo(key, value); }
|
||||
@Override
|
||||
public float subFrom(byte key, float value) { return map.subFrom(key, value); }
|
||||
@Override
|
||||
public float remove(byte key) { return map.remove(key); }
|
||||
@Override
|
||||
public boolean remove(byte key, float value) { return map.remove(key, value); }
|
||||
@Override
|
||||
public float removeOrDefault(byte key, float defaultValue) { return map.removeOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public boolean containsKey(byte key) { return map.containsKey(key); }
|
||||
@Override
|
||||
public boolean containsValue(float value) { return map.containsValue(value); }
|
||||
@Override
|
||||
public boolean replace(byte key, float oldValue, float newValue) { return map.replace(key, oldValue, newValue); }
|
||||
@Override
|
||||
public float replace(byte key, float value) { return map.replace(key, value); }
|
||||
@Override
|
||||
public void replaceFloats(Byte2FloatMap m) { map.replaceFloats(m); }
|
||||
@Override
|
||||
public void replaceFloats(ByteFloatUnaryOperator mappingFunction) { map.replaceFloats(mappingFunction); }
|
||||
@Override
|
||||
public float computeFloat(byte key, ByteFloatUnaryOperator mappingFunction) { return map.computeFloat(key, mappingFunction); }
|
||||
@Override
|
||||
public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { return map.computeFloatIfAbsent(key, mappingFunction); }
|
||||
@Override
|
||||
public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { return map.supplyFloatIfAbsent(key, valueProvider); }
|
||||
@Override
|
||||
public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { return map.computeFloatIfPresent(key, mappingFunction); }
|
||||
@Override
|
||||
public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { return map.computeFloatNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider) { return map.supplyFloatIfAbsentNonDefault(key, valueProvider); }
|
||||
@Override
|
||||
public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public float mergeFloat(byte key, float value, FloatFloatUnaryOperator mappingFunction) { return map.mergeFloat(key, value, mappingFunction); }
|
||||
@Override
|
||||
public float getOrDefault(byte key, float defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public float get(byte key) { return map.get(key); }
|
||||
@Override
|
||||
public float putAndMoveToFirst(byte key, float value) { return map.putAndMoveToLast(key, value); }
|
||||
@Override
|
||||
public float putAndMoveToLast(byte key, float value) { return map.putAndMoveToFirst(key, value); }
|
||||
@Override
|
||||
public float putFirst(byte key, float value) { return map.putLast(key, value); }
|
||||
@Override
|
||||
public float putLast(byte key, float value) { return map.putFirst(key, value); }
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) { return map.moveToLast(key); }
|
||||
@Override
|
||||
public boolean moveToLast(byte key) { return map.moveToFirst(key); }
|
||||
@Override
|
||||
public float getAndMoveToFirst(byte key) { return map.getAndMoveToLast(key); }
|
||||
@Override
|
||||
public float getAndMoveToLast(byte key) { return map.getAndMoveToFirst(key); }
|
||||
@Override
|
||||
public byte firstByteKey() { return map.lastByteKey(); }
|
||||
@Override
|
||||
public byte pollFirstByteKey() { return map.pollLastByteKey(); }
|
||||
@Override
|
||||
public byte lastByteKey() { return map.firstByteKey(); }
|
||||
@Override
|
||||
public byte pollLastByteKey() { return map.pollFirstByteKey(); }
|
||||
@Override
|
||||
public float firstFloatValue() { return map.lastFloatValue(); }
|
||||
@Override
|
||||
public float lastFloatValue() { return map.firstFloatValue(); }
|
||||
@Override
|
||||
public Byte2FloatMap.Entry firstEntry() { return map.lastEntry(); }
|
||||
@Override
|
||||
public Byte2FloatMap.Entry lastEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public Byte2FloatMap.Entry pollFirstEntry() { return map.pollLastEntry(); }
|
||||
@Override
|
||||
public Byte2FloatMap.Entry pollLastEntry() { return map.pollFirstEntry(); }
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2FloatMap.Entry> byte2FloatEntrySet() { return new AbstractObjectSet.ReversedObjectOrderedSet<>(map.byte2FloatEntrySet()); }
|
||||
@Override
|
||||
public ByteOrderedSet keySet() { return new AbstractByteSet.ReversedByteOrderedSet(map.keySet()); }
|
||||
@Override
|
||||
public FloatOrderedCollection values() { return map.values().reversed(); }
|
||||
@Override
|
||||
public Byte2FloatOrderedMap reversed() { return map; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A Simple Type Specific Entry class to reduce boxing/unboxing
|
||||
*/
|
||||
|
||||
@ -9,6 +9,11 @@ import speiger.src.collections.bytes.functions.consumer.ByteIntConsumer;
|
||||
import speiger.src.collections.bytes.functions.function.Byte2IntFunction;
|
||||
import speiger.src.collections.bytes.functions.function.ByteIntUnaryOperator;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2IntMap;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2IntOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.ints.collections.IntOrderedCollection;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteSet;
|
||||
import speiger.src.collections.bytes.utils.maps.Byte2IntMaps;
|
||||
@ -27,7 +32,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
*/
|
||||
public abstract class AbstractByte2IntMap extends AbstractMap<Byte, Integer> implements Byte2IntMap
|
||||
{
|
||||
protected int defaultReturnValue = 0;
|
||||
protected int defaultReturnValue = -1;
|
||||
|
||||
@Override
|
||||
public int getDefaultReturnValue() {
|
||||
@ -91,7 +96,7 @@ public abstract class AbstractByte2IntMap extends AbstractMap<Byte, Integer> imp
|
||||
public void putAll(Byte[] keys, Integer[] values, int offset, int size) {
|
||||
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||
SanityChecks.checkArrayCapacity(values.length, offset, size);
|
||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||
for(int i = 0;i<size;i++) put(keys[i].byteValue(), values[i].intValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -414,6 +419,116 @@ public abstract class AbstractByte2IntMap extends AbstractMap<Byte, Integer> imp
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static class ReversedByte2IntOrderedMap extends AbstractByte2IntMap implements Byte2IntOrderedMap {
|
||||
Byte2IntOrderedMap map;
|
||||
|
||||
public ReversedByte2IntOrderedMap(Byte2IntOrderedMap map) {
|
||||
this.map = map;
|
||||
}
|
||||
@Override
|
||||
public AbstractByte2IntMap setDefaultReturnValue(int v) {
|
||||
map.setDefaultReturnValue(v);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public int getDefaultReturnValue() { return map.getDefaultReturnValue(); }
|
||||
@Override
|
||||
public Byte2IntOrderedMap copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public int put(byte key, int value) { return map.put(key, value); }
|
||||
@Override
|
||||
public int putIfAbsent(byte key, int value) { return map.putIfAbsent(key, value); }
|
||||
@Override
|
||||
public int addTo(byte key, int value) { return map.addTo(key, value); }
|
||||
@Override
|
||||
public int subFrom(byte key, int value) { return map.subFrom(key, value); }
|
||||
@Override
|
||||
public int remove(byte key) { return map.remove(key); }
|
||||
@Override
|
||||
public boolean remove(byte key, int value) { return map.remove(key, value); }
|
||||
@Override
|
||||
public int removeOrDefault(byte key, int defaultValue) { return map.removeOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public boolean containsKey(byte key) { return map.containsKey(key); }
|
||||
@Override
|
||||
public boolean containsValue(int value) { return map.containsValue(value); }
|
||||
@Override
|
||||
public boolean replace(byte key, int oldValue, int newValue) { return map.replace(key, oldValue, newValue); }
|
||||
@Override
|
||||
public int replace(byte key, int value) { return map.replace(key, value); }
|
||||
@Override
|
||||
public void replaceInts(Byte2IntMap m) { map.replaceInts(m); }
|
||||
@Override
|
||||
public void replaceInts(ByteIntUnaryOperator mappingFunction) { map.replaceInts(mappingFunction); }
|
||||
@Override
|
||||
public int computeInt(byte key, ByteIntUnaryOperator mappingFunction) { return map.computeInt(key, mappingFunction); }
|
||||
@Override
|
||||
public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { return map.computeIntIfAbsent(key, mappingFunction); }
|
||||
@Override
|
||||
public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { return map.supplyIntIfAbsent(key, valueProvider); }
|
||||
@Override
|
||||
public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { return map.computeIntIfPresent(key, mappingFunction); }
|
||||
@Override
|
||||
public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { return map.computeIntNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { return map.supplyIntIfAbsentNonDefault(key, valueProvider); }
|
||||
@Override
|
||||
public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { return map.computeIntIfPresentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public int mergeInt(byte key, int value, IntIntUnaryOperator mappingFunction) { return map.mergeInt(key, value, mappingFunction); }
|
||||
@Override
|
||||
public int getOrDefault(byte key, int defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public int get(byte key) { return map.get(key); }
|
||||
@Override
|
||||
public int putAndMoveToFirst(byte key, int value) { return map.putAndMoveToLast(key, value); }
|
||||
@Override
|
||||
public int putAndMoveToLast(byte key, int value) { return map.putAndMoveToFirst(key, value); }
|
||||
@Override
|
||||
public int putFirst(byte key, int value) { return map.putLast(key, value); }
|
||||
@Override
|
||||
public int putLast(byte key, int value) { return map.putFirst(key, value); }
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) { return map.moveToLast(key); }
|
||||
@Override
|
||||
public boolean moveToLast(byte key) { return map.moveToFirst(key); }
|
||||
@Override
|
||||
public int getAndMoveToFirst(byte key) { return map.getAndMoveToLast(key); }
|
||||
@Override
|
||||
public int getAndMoveToLast(byte key) { return map.getAndMoveToFirst(key); }
|
||||
@Override
|
||||
public byte firstByteKey() { return map.lastByteKey(); }
|
||||
@Override
|
||||
public byte pollFirstByteKey() { return map.pollLastByteKey(); }
|
||||
@Override
|
||||
public byte lastByteKey() { return map.firstByteKey(); }
|
||||
@Override
|
||||
public byte pollLastByteKey() { return map.pollFirstByteKey(); }
|
||||
@Override
|
||||
public int firstIntValue() { return map.lastIntValue(); }
|
||||
@Override
|
||||
public int lastIntValue() { return map.firstIntValue(); }
|
||||
@Override
|
||||
public Byte2IntMap.Entry firstEntry() { return map.lastEntry(); }
|
||||
@Override
|
||||
public Byte2IntMap.Entry lastEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public Byte2IntMap.Entry pollFirstEntry() { return map.pollLastEntry(); }
|
||||
@Override
|
||||
public Byte2IntMap.Entry pollLastEntry() { return map.pollFirstEntry(); }
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2IntMap.Entry> byte2IntEntrySet() { return new AbstractObjectSet.ReversedObjectOrderedSet<>(map.byte2IntEntrySet()); }
|
||||
@Override
|
||||
public ByteOrderedSet keySet() { return new AbstractByteSet.ReversedByteOrderedSet(map.keySet()); }
|
||||
@Override
|
||||
public IntOrderedCollection values() { return map.values().reversed(); }
|
||||
@Override
|
||||
public Byte2IntOrderedMap reversed() { return map; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A Simple Type Specific Entry class to reduce boxing/unboxing
|
||||
*/
|
||||
|
||||
@ -9,6 +9,11 @@ import speiger.src.collections.bytes.functions.consumer.ByteLongConsumer;
|
||||
import speiger.src.collections.bytes.functions.function.Byte2LongFunction;
|
||||
import speiger.src.collections.bytes.functions.function.ByteLongUnaryOperator;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2LongMap;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2LongOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.longs.collections.LongOrderedCollection;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteSet;
|
||||
import speiger.src.collections.bytes.utils.maps.Byte2LongMaps;
|
||||
@ -27,7 +32,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
*/
|
||||
public abstract class AbstractByte2LongMap extends AbstractMap<Byte, Long> implements Byte2LongMap
|
||||
{
|
||||
protected long defaultReturnValue = 0L;
|
||||
protected long defaultReturnValue = -1L;
|
||||
|
||||
@Override
|
||||
public long getDefaultReturnValue() {
|
||||
@ -91,7 +96,7 @@ public abstract class AbstractByte2LongMap extends AbstractMap<Byte, Long> imple
|
||||
public void putAll(Byte[] keys, Long[] values, int offset, int size) {
|
||||
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||
SanityChecks.checkArrayCapacity(values.length, offset, size);
|
||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||
for(int i = 0;i<size;i++) put(keys[i].byteValue(), values[i].longValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -414,6 +419,116 @@ public abstract class AbstractByte2LongMap extends AbstractMap<Byte, Long> imple
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static class ReversedByte2LongOrderedMap extends AbstractByte2LongMap implements Byte2LongOrderedMap {
|
||||
Byte2LongOrderedMap map;
|
||||
|
||||
public ReversedByte2LongOrderedMap(Byte2LongOrderedMap map) {
|
||||
this.map = map;
|
||||
}
|
||||
@Override
|
||||
public AbstractByte2LongMap setDefaultReturnValue(long v) {
|
||||
map.setDefaultReturnValue(v);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public long getDefaultReturnValue() { return map.getDefaultReturnValue(); }
|
||||
@Override
|
||||
public Byte2LongOrderedMap copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public long put(byte key, long value) { return map.put(key, value); }
|
||||
@Override
|
||||
public long putIfAbsent(byte key, long value) { return map.putIfAbsent(key, value); }
|
||||
@Override
|
||||
public long addTo(byte key, long value) { return map.addTo(key, value); }
|
||||
@Override
|
||||
public long subFrom(byte key, long value) { return map.subFrom(key, value); }
|
||||
@Override
|
||||
public long remove(byte key) { return map.remove(key); }
|
||||
@Override
|
||||
public boolean remove(byte key, long value) { return map.remove(key, value); }
|
||||
@Override
|
||||
public long removeOrDefault(byte key, long defaultValue) { return map.removeOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public boolean containsKey(byte key) { return map.containsKey(key); }
|
||||
@Override
|
||||
public boolean containsValue(long value) { return map.containsValue(value); }
|
||||
@Override
|
||||
public boolean replace(byte key, long oldValue, long newValue) { return map.replace(key, oldValue, newValue); }
|
||||
@Override
|
||||
public long replace(byte key, long value) { return map.replace(key, value); }
|
||||
@Override
|
||||
public void replaceLongs(Byte2LongMap m) { map.replaceLongs(m); }
|
||||
@Override
|
||||
public void replaceLongs(ByteLongUnaryOperator mappingFunction) { map.replaceLongs(mappingFunction); }
|
||||
@Override
|
||||
public long computeLong(byte key, ByteLongUnaryOperator mappingFunction) { return map.computeLong(key, mappingFunction); }
|
||||
@Override
|
||||
public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { return map.computeLongIfAbsent(key, mappingFunction); }
|
||||
@Override
|
||||
public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { return map.supplyLongIfAbsent(key, valueProvider); }
|
||||
@Override
|
||||
public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { return map.computeLongIfPresent(key, mappingFunction); }
|
||||
@Override
|
||||
public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { return map.computeLongNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { return map.supplyLongIfAbsentNonDefault(key, valueProvider); }
|
||||
@Override
|
||||
public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { return map.computeLongIfPresentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public long mergeLong(byte key, long value, LongLongUnaryOperator mappingFunction) { return map.mergeLong(key, value, mappingFunction); }
|
||||
@Override
|
||||
public long getOrDefault(byte key, long defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public long get(byte key) { return map.get(key); }
|
||||
@Override
|
||||
public long putAndMoveToFirst(byte key, long value) { return map.putAndMoveToLast(key, value); }
|
||||
@Override
|
||||
public long putAndMoveToLast(byte key, long value) { return map.putAndMoveToFirst(key, value); }
|
||||
@Override
|
||||
public long putFirst(byte key, long value) { return map.putLast(key, value); }
|
||||
@Override
|
||||
public long putLast(byte key, long value) { return map.putFirst(key, value); }
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) { return map.moveToLast(key); }
|
||||
@Override
|
||||
public boolean moveToLast(byte key) { return map.moveToFirst(key); }
|
||||
@Override
|
||||
public long getAndMoveToFirst(byte key) { return map.getAndMoveToLast(key); }
|
||||
@Override
|
||||
public long getAndMoveToLast(byte key) { return map.getAndMoveToFirst(key); }
|
||||
@Override
|
||||
public byte firstByteKey() { return map.lastByteKey(); }
|
||||
@Override
|
||||
public byte pollFirstByteKey() { return map.pollLastByteKey(); }
|
||||
@Override
|
||||
public byte lastByteKey() { return map.firstByteKey(); }
|
||||
@Override
|
||||
public byte pollLastByteKey() { return map.pollFirstByteKey(); }
|
||||
@Override
|
||||
public long firstLongValue() { return map.lastLongValue(); }
|
||||
@Override
|
||||
public long lastLongValue() { return map.firstLongValue(); }
|
||||
@Override
|
||||
public Byte2LongMap.Entry firstEntry() { return map.lastEntry(); }
|
||||
@Override
|
||||
public Byte2LongMap.Entry lastEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public Byte2LongMap.Entry pollFirstEntry() { return map.pollLastEntry(); }
|
||||
@Override
|
||||
public Byte2LongMap.Entry pollLastEntry() { return map.pollFirstEntry(); }
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2LongMap.Entry> byte2LongEntrySet() { return new AbstractObjectSet.ReversedObjectOrderedSet<>(map.byte2LongEntrySet()); }
|
||||
@Override
|
||||
public ByteOrderedSet keySet() { return new AbstractByteSet.ReversedByteOrderedSet(map.keySet()); }
|
||||
@Override
|
||||
public LongOrderedCollection values() { return map.values().reversed(); }
|
||||
@Override
|
||||
public Byte2LongOrderedMap reversed() { return map; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A Simple Type Specific Entry class to reduce boxing/unboxing
|
||||
*/
|
||||
|
||||
@ -9,6 +9,11 @@ import speiger.src.collections.bytes.functions.consumer.ByteObjectConsumer;
|
||||
import speiger.src.collections.bytes.functions.function.ByteFunction;
|
||||
import speiger.src.collections.bytes.functions.function.ByteObjectUnaryOperator;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2ObjectMap;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2ObjectOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.objects.collections.ObjectOrderedCollection;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteSet;
|
||||
import speiger.src.collections.bytes.utils.maps.Byte2ObjectMaps;
|
||||
@ -85,7 +90,7 @@ public abstract class AbstractByte2ObjectMap<V> extends AbstractMap<Byte, V> imp
|
||||
public void putAll(Byte[] keys, V[] values, int offset, int size) {
|
||||
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||
SanityChecks.checkArrayCapacity(values.length, offset, size);
|
||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||
for(int i = 0;i<size;i++) put(keys[i].byteValue(), values[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -367,6 +372,104 @@ public abstract class AbstractByte2ObjectMap<V> extends AbstractMap<Byte, V> imp
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static class ReversedByte2ObjectOrderedMap<V> extends AbstractByte2ObjectMap<V> implements Byte2ObjectOrderedMap<V> {
|
||||
Byte2ObjectOrderedMap<V> map;
|
||||
|
||||
public ReversedByte2ObjectOrderedMap(Byte2ObjectOrderedMap<V> map) {
|
||||
this.map = map;
|
||||
}
|
||||
@Override
|
||||
public AbstractByte2ObjectMap<V> setDefaultReturnValue(V v) {
|
||||
map.setDefaultReturnValue(v);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public V getDefaultReturnValue() { return map.getDefaultReturnValue(); }
|
||||
@Override
|
||||
public Byte2ObjectOrderedMap<V> copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public V put(byte key, V value) { return map.put(key, value); }
|
||||
@Override
|
||||
public V putIfAbsent(byte key, V value) { return map.putIfAbsent(key, value); }
|
||||
@Override
|
||||
public V remove(byte key) { return map.remove(key); }
|
||||
@Override
|
||||
public boolean remove(byte key, V value) { return map.remove(key, value); }
|
||||
@Override
|
||||
public V removeOrDefault(byte key, V defaultValue) { return map.removeOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public boolean containsKey(byte key) { return map.containsKey(key); }
|
||||
@Override
|
||||
public boolean containsValue(Object value) { return map.containsValue(value); }
|
||||
@Override
|
||||
public boolean replace(byte key, V oldValue, V newValue) { return map.replace(key, oldValue, newValue); }
|
||||
@Override
|
||||
public V replace(byte key, V value) { return map.replace(key, value); }
|
||||
@Override
|
||||
public void replaceObjects(Byte2ObjectMap<V> m) { map.replaceObjects(m); }
|
||||
@Override
|
||||
public void replaceObjects(ByteObjectUnaryOperator<V> mappingFunction) { map.replaceObjects(mappingFunction); }
|
||||
@Override
|
||||
public V compute(byte key, ByteObjectUnaryOperator<V> mappingFunction) { return map.compute(key, mappingFunction); }
|
||||
@Override
|
||||
public V computeIfAbsent(byte key, ByteFunction<V> mappingFunction) { return map.computeIfAbsent(key, mappingFunction); }
|
||||
@Override
|
||||
public V supplyIfAbsent(byte key, ObjectSupplier<V> valueProvider) { return map.supplyIfAbsent(key, valueProvider); }
|
||||
@Override
|
||||
public V computeIfPresent(byte key, ByteObjectUnaryOperator<V> mappingFunction) { return map.computeIfPresent(key, mappingFunction); }
|
||||
@Override
|
||||
public V merge(byte key, V value, ObjectObjectUnaryOperator<V, V> mappingFunction) { return map.merge(key, value, mappingFunction); }
|
||||
@Override
|
||||
public V getOrDefault(byte key, V defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public V get(byte key) { return map.get(key); }
|
||||
@Override
|
||||
public V putAndMoveToFirst(byte key, V value) { return map.putAndMoveToLast(key, value); }
|
||||
@Override
|
||||
public V putAndMoveToLast(byte key, V value) { return map.putAndMoveToFirst(key, value); }
|
||||
@Override
|
||||
public V putFirst(byte key, V value) { return map.putLast(key, value); }
|
||||
@Override
|
||||
public V putLast(byte key, V value) { return map.putFirst(key, value); }
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) { return map.moveToLast(key); }
|
||||
@Override
|
||||
public boolean moveToLast(byte key) { return map.moveToFirst(key); }
|
||||
@Override
|
||||
public V getAndMoveToFirst(byte key) { return map.getAndMoveToLast(key); }
|
||||
@Override
|
||||
public V getAndMoveToLast(byte key) { return map.getAndMoveToFirst(key); }
|
||||
@Override
|
||||
public byte firstByteKey() { return map.lastByteKey(); }
|
||||
@Override
|
||||
public byte pollFirstByteKey() { return map.pollLastByteKey(); }
|
||||
@Override
|
||||
public byte lastByteKey() { return map.firstByteKey(); }
|
||||
@Override
|
||||
public byte pollLastByteKey() { return map.pollFirstByteKey(); }
|
||||
@Override
|
||||
public V firstValue() { return map.lastValue(); }
|
||||
@Override
|
||||
public V lastValue() { return map.firstValue(); }
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> firstEntry() { return map.lastEntry(); }
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> lastEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> pollFirstEntry() { return map.pollLastEntry(); }
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> pollLastEntry() { return map.pollFirstEntry(); }
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2ObjectMap.Entry<V>> byte2ObjectEntrySet() { return new AbstractObjectSet.ReversedObjectOrderedSet<>(map.byte2ObjectEntrySet()); }
|
||||
@Override
|
||||
public ByteOrderedSet keySet() { return new AbstractByteSet.ReversedByteOrderedSet(map.keySet()); }
|
||||
@Override
|
||||
public ObjectOrderedCollection<V> values() { return map.values().reversed(); }
|
||||
@Override
|
||||
public Byte2ObjectOrderedMap<V> reversed() { return map; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A Simple Type Specific Entry class to reduce boxing/unboxing
|
||||
* @param <V> the keyType of elements maintained by this Collection
|
||||
|
||||
@ -9,6 +9,11 @@ import speiger.src.collections.bytes.functions.consumer.ByteShortConsumer;
|
||||
import speiger.src.collections.bytes.functions.function.Byte2ShortFunction;
|
||||
import speiger.src.collections.bytes.functions.function.ByteShortUnaryOperator;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2ShortMap;
|
||||
import speiger.src.collections.bytes.maps.interfaces.Byte2ShortOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.shorts.collections.ShortOrderedCollection;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteSet;
|
||||
import speiger.src.collections.bytes.utils.maps.Byte2ShortMaps;
|
||||
@ -27,7 +32,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
*/
|
||||
public abstract class AbstractByte2ShortMap extends AbstractMap<Byte, Short> implements Byte2ShortMap
|
||||
{
|
||||
protected short defaultReturnValue = (short)0;
|
||||
protected short defaultReturnValue = (short)-1;
|
||||
|
||||
@Override
|
||||
public short getDefaultReturnValue() {
|
||||
@ -91,7 +96,7 @@ public abstract class AbstractByte2ShortMap extends AbstractMap<Byte, Short> imp
|
||||
public void putAll(Byte[] keys, Short[] values, int offset, int size) {
|
||||
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||
SanityChecks.checkArrayCapacity(values.length, offset, size);
|
||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||
for(int i = 0;i<size;i++) put(keys[i].byteValue(), values[i].shortValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -414,6 +419,116 @@ public abstract class AbstractByte2ShortMap extends AbstractMap<Byte, Short> imp
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static class ReversedByte2ShortOrderedMap extends AbstractByte2ShortMap implements Byte2ShortOrderedMap {
|
||||
Byte2ShortOrderedMap map;
|
||||
|
||||
public ReversedByte2ShortOrderedMap(Byte2ShortOrderedMap map) {
|
||||
this.map = map;
|
||||
}
|
||||
@Override
|
||||
public AbstractByte2ShortMap setDefaultReturnValue(short v) {
|
||||
map.setDefaultReturnValue(v);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public short getDefaultReturnValue() { return map.getDefaultReturnValue(); }
|
||||
@Override
|
||||
public Byte2ShortOrderedMap copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public short put(byte key, short value) { return map.put(key, value); }
|
||||
@Override
|
||||
public short putIfAbsent(byte key, short value) { return map.putIfAbsent(key, value); }
|
||||
@Override
|
||||
public short addTo(byte key, short value) { return map.addTo(key, value); }
|
||||
@Override
|
||||
public short subFrom(byte key, short value) { return map.subFrom(key, value); }
|
||||
@Override
|
||||
public short remove(byte key) { return map.remove(key); }
|
||||
@Override
|
||||
public boolean remove(byte key, short value) { return map.remove(key, value); }
|
||||
@Override
|
||||
public short removeOrDefault(byte key, short defaultValue) { return map.removeOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public boolean containsKey(byte key) { return map.containsKey(key); }
|
||||
@Override
|
||||
public boolean containsValue(short value) { return map.containsValue(value); }
|
||||
@Override
|
||||
public boolean replace(byte key, short oldValue, short newValue) { return map.replace(key, oldValue, newValue); }
|
||||
@Override
|
||||
public short replace(byte key, short value) { return map.replace(key, value); }
|
||||
@Override
|
||||
public void replaceShorts(Byte2ShortMap m) { map.replaceShorts(m); }
|
||||
@Override
|
||||
public void replaceShorts(ByteShortUnaryOperator mappingFunction) { map.replaceShorts(mappingFunction); }
|
||||
@Override
|
||||
public short computeShort(byte key, ByteShortUnaryOperator mappingFunction) { return map.computeShort(key, mappingFunction); }
|
||||
@Override
|
||||
public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { return map.computeShortIfAbsent(key, mappingFunction); }
|
||||
@Override
|
||||
public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { return map.supplyShortIfAbsent(key, valueProvider); }
|
||||
@Override
|
||||
public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { return map.computeShortIfPresent(key, mappingFunction); }
|
||||
@Override
|
||||
public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { return map.computeShortNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider) { return map.supplyShortIfAbsentNonDefault(key, valueProvider); }
|
||||
@Override
|
||||
public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { return map.computeShortIfPresentNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public short mergeShort(byte key, short value, ShortShortUnaryOperator mappingFunction) { return map.mergeShort(key, value, mappingFunction); }
|
||||
@Override
|
||||
public short getOrDefault(byte key, short defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
public short get(byte key) { return map.get(key); }
|
||||
@Override
|
||||
public short putAndMoveToFirst(byte key, short value) { return map.putAndMoveToLast(key, value); }
|
||||
@Override
|
||||
public short putAndMoveToLast(byte key, short value) { return map.putAndMoveToFirst(key, value); }
|
||||
@Override
|
||||
public short putFirst(byte key, short value) { return map.putLast(key, value); }
|
||||
@Override
|
||||
public short putLast(byte key, short value) { return map.putFirst(key, value); }
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) { return map.moveToLast(key); }
|
||||
@Override
|
||||
public boolean moveToLast(byte key) { return map.moveToFirst(key); }
|
||||
@Override
|
||||
public short getAndMoveToFirst(byte key) { return map.getAndMoveToLast(key); }
|
||||
@Override
|
||||
public short getAndMoveToLast(byte key) { return map.getAndMoveToFirst(key); }
|
||||
@Override
|
||||
public byte firstByteKey() { return map.lastByteKey(); }
|
||||
@Override
|
||||
public byte pollFirstByteKey() { return map.pollLastByteKey(); }
|
||||
@Override
|
||||
public byte lastByteKey() { return map.firstByteKey(); }
|
||||
@Override
|
||||
public byte pollLastByteKey() { return map.pollFirstByteKey(); }
|
||||
@Override
|
||||
public short firstShortValue() { return map.lastShortValue(); }
|
||||
@Override
|
||||
public short lastShortValue() { return map.firstShortValue(); }
|
||||
@Override
|
||||
public Byte2ShortMap.Entry firstEntry() { return map.lastEntry(); }
|
||||
@Override
|
||||
public Byte2ShortMap.Entry lastEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public Byte2ShortMap.Entry pollFirstEntry() { return map.pollLastEntry(); }
|
||||
@Override
|
||||
public Byte2ShortMap.Entry pollLastEntry() { return map.pollFirstEntry(); }
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2ShortMap.Entry> byte2ShortEntrySet() { return new AbstractObjectSet.ReversedObjectOrderedSet<>(map.byte2ShortEntrySet()); }
|
||||
@Override
|
||||
public ByteOrderedSet keySet() { return new AbstractByteSet.ReversedByteOrderedSet(map.keySet()); }
|
||||
@Override
|
||||
public ShortOrderedCollection values() { return map.values().reversed(); }
|
||||
@Override
|
||||
public Byte2ShortOrderedMap reversed() { return map; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A Simple Type Specific Entry class to reduce boxing/unboxing
|
||||
*/
|
||||
|
||||
@ -24,7 +24,7 @@ import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.bytes.utils.ByteStrategy;
|
||||
import speiger.src.collections.booleans.collections.AbstractBooleanCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanOrderedCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
import speiger.src.collections.booleans.functions.function.BooleanBooleanUnaryOperator;
|
||||
import speiger.src.collections.booleans.functions.BooleanConsumer;
|
||||
@ -258,6 +258,54 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean putFirst(byte key, boolean value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean putLast(byte key, boolean value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || strategy.equals(firstByteKey(), key)) return false;
|
||||
@ -393,6 +441,52 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = false;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = false;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2BooleanMap.Entry> byte2BooleanEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -406,9 +500,9 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanCollection values() {
|
||||
public BooleanOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (BooleanOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -593,24 +687,24 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry first() {
|
||||
public Byte2BooleanMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstBooleanValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry last() {
|
||||
public Byte2BooleanMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastBooleanValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry pollFirst() {
|
||||
public Byte2BooleanMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstBooleanValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry pollLast() {
|
||||
public Byte2BooleanMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastBooleanValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -618,7 +712,12 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2BooleanMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2BooleanMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -628,7 +727,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2BooleanMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -864,7 +963,12 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -886,22 +990,22 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1030,30 +1134,41 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractBooleanCollection {
|
||||
private class Values extends AbstractBooleanCollection implements BooleanOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(boolean e) {
|
||||
return containsValue(e);
|
||||
public boolean contains(boolean e) { return containsValue(e); }
|
||||
@Override
|
||||
public boolean add(boolean o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public BooleanIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() { return Byte2BooleanLinkedOpenCustomHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() { Byte2BooleanLinkedOpenCustomHashMap.this.clear(); }
|
||||
@Override
|
||||
public BooleanOrderedCollection reversed() { return new AbstractBooleanCollection.ReverseBooleanOrderedCollection(this, this::reverseIterator); }
|
||||
private BooleanIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(boolean o) {
|
||||
throw new UnsupportedOperationException();
|
||||
public void addFirst(boolean e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(boolean e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean getFirstBoolean() { return firstBooleanValue(); }
|
||||
@Override
|
||||
public boolean removeFirstBoolean() {
|
||||
boolean result = firstBooleanValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public boolean getLastBoolean() { return lastBooleanValue(); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2BooleanLinkedOpenCustomHashMap.this.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2BooleanLinkedOpenCustomHashMap.this.clear();
|
||||
public boolean removeLastBoolean() {
|
||||
boolean result = lastBooleanValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1184,7 +1299,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2BooleanMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1211,7 +1326,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2BooleanMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1241,7 +1356,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1263,7 +1378,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements BooleanListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public boolean previousBoolean() {
|
||||
@ -1284,16 +1399,20 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, (byte)0)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -1321,11 +1440,11 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1385,20 +1504,30 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -23,7 +23,7 @@ import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.bytes.utils.ByteStrategy;
|
||||
import speiger.src.collections.bytes.collections.AbstractByteCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteOrderedCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteIterator;
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||
@ -251,6 +251,54 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte putFirst(byte key, byte value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte putLast(byte key, byte value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || strategy.equals(firstByteKey(), key)) return false;
|
||||
@ -386,6 +434,52 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = (byte)0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = (byte)0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2ByteMap.Entry> byte2ByteEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -399,9 +493,9 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteCollection values() {
|
||||
public ByteOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (ByteOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -586,24 +680,24 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry first() {
|
||||
public Byte2ByteMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstByteValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry last() {
|
||||
public Byte2ByteMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastByteValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry pollFirst() {
|
||||
public Byte2ByteMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstByteValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry pollLast() {
|
||||
public Byte2ByteMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastByteValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -611,7 +705,12 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ByteMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ByteMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -621,7 +720,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ByteMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -857,7 +956,12 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -879,22 +983,22 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1023,30 +1127,41 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractByteCollection {
|
||||
private class Values extends AbstractByteCollection implements ByteOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(byte e) {
|
||||
return containsValue(e);
|
||||
public boolean contains(byte e) { return containsValue(e); }
|
||||
@Override
|
||||
public boolean add(byte o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ByteIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() { return Byte2ByteLinkedOpenCustomHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() { Byte2ByteLinkedOpenCustomHashMap.this.clear(); }
|
||||
@Override
|
||||
public ByteOrderedCollection reversed() { return new AbstractByteCollection.ReverseByteOrderedCollection(this, this::reverseIterator); }
|
||||
private ByteIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(byte o) {
|
||||
throw new UnsupportedOperationException();
|
||||
public void addFirst(byte e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(byte e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public byte getFirstByte() { return firstByteValue(); }
|
||||
@Override
|
||||
public byte removeFirstByte() {
|
||||
byte result = firstByteValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public byte getLastByte() { return lastByteValue(); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2ByteLinkedOpenCustomHashMap.this.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2ByteLinkedOpenCustomHashMap.this.clear();
|
||||
public byte removeLastByte() {
|
||||
byte result = lastByteValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1177,7 +1292,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2ByteMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1204,7 +1319,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2ByteMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1234,7 +1349,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1256,7 +1371,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements ByteListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public byte previousByte() {
|
||||
@ -1277,16 +1392,20 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, (byte)0)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -1314,11 +1433,11 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1378,20 +1497,30 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -24,7 +24,7 @@ import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.bytes.utils.ByteStrategy;
|
||||
import speiger.src.collections.chars.collections.AbstractCharCollection;
|
||||
import speiger.src.collections.chars.collections.CharCollection;
|
||||
import speiger.src.collections.chars.collections.CharOrderedCollection;
|
||||
import speiger.src.collections.chars.collections.CharIterator;
|
||||
import speiger.src.collections.chars.functions.function.CharCharUnaryOperator;
|
||||
import speiger.src.collections.chars.functions.CharConsumer;
|
||||
@ -258,6 +258,54 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char putFirst(byte key, char value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char putLast(byte key, char value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || strategy.equals(firstByteKey(), key)) return false;
|
||||
@ -393,6 +441,52 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = (char)0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = (char)0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2CharMap.Entry> byte2CharEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -406,9 +500,9 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharCollection values() {
|
||||
public CharOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (CharOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -593,24 +687,24 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry first() {
|
||||
public Byte2CharMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstCharValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry last() {
|
||||
public Byte2CharMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastCharValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry pollFirst() {
|
||||
public Byte2CharMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstCharValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry pollLast() {
|
||||
public Byte2CharMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastCharValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -618,7 +712,12 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2CharMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2CharMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -628,7 +727,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2CharMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -864,7 +963,12 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -886,22 +990,22 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1030,30 +1134,41 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractCharCollection {
|
||||
private class Values extends AbstractCharCollection implements CharOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(char e) {
|
||||
return containsValue(e);
|
||||
public boolean contains(char e) { return containsValue(e); }
|
||||
@Override
|
||||
public boolean add(char o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public CharIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() { return Byte2CharLinkedOpenCustomHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() { Byte2CharLinkedOpenCustomHashMap.this.clear(); }
|
||||
@Override
|
||||
public CharOrderedCollection reversed() { return new AbstractCharCollection.ReverseCharOrderedCollection(this, this::reverseIterator); }
|
||||
private CharIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(char o) {
|
||||
throw new UnsupportedOperationException();
|
||||
public void addFirst(char e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(char e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public char getFirstChar() { return firstCharValue(); }
|
||||
@Override
|
||||
public char removeFirstChar() {
|
||||
char result = firstCharValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public char getLastChar() { return lastCharValue(); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2CharLinkedOpenCustomHashMap.this.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2CharLinkedOpenCustomHashMap.this.clear();
|
||||
public char removeLastChar() {
|
||||
char result = lastCharValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1184,7 +1299,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2CharMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1211,7 +1326,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2CharMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1241,7 +1356,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1263,7 +1378,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements CharListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public char previousChar() {
|
||||
@ -1284,16 +1399,20 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, (byte)0)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -1321,11 +1440,11 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1385,20 +1504,30 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -25,7 +25,7 @@ import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.bytes.utils.ByteStrategy;
|
||||
import speiger.src.collections.doubles.collections.AbstractDoubleCollection;
|
||||
import speiger.src.collections.doubles.collections.DoubleCollection;
|
||||
import speiger.src.collections.doubles.collections.DoubleOrderedCollection;
|
||||
import speiger.src.collections.doubles.collections.DoubleIterator;
|
||||
import speiger.src.collections.doubles.functions.function.DoubleDoubleUnaryOperator;
|
||||
import speiger.src.collections.doubles.functions.DoubleConsumer;
|
||||
@ -258,6 +258,54 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double putFirst(byte key, double value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double putLast(byte key, double value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || strategy.equals(firstByteKey(), key)) return false;
|
||||
@ -393,6 +441,52 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0D;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0D;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2DoubleMap.Entry> byte2DoubleEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -406,9 +500,9 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleCollection values() {
|
||||
public DoubleOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (DoubleOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -593,24 +687,24 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry first() {
|
||||
public Byte2DoubleMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstDoubleValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry last() {
|
||||
public Byte2DoubleMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastDoubleValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry pollFirst() {
|
||||
public Byte2DoubleMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstDoubleValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry pollLast() {
|
||||
public Byte2DoubleMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastDoubleValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -618,7 +712,12 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2DoubleMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2DoubleMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -628,7 +727,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2DoubleMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -864,7 +963,12 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -886,22 +990,22 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1030,30 +1134,41 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractDoubleCollection {
|
||||
private class Values extends AbstractDoubleCollection implements DoubleOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(double e) {
|
||||
return containsValue(e);
|
||||
public boolean contains(double e) { return containsValue(e); }
|
||||
@Override
|
||||
public boolean add(double o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public DoubleIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() { return Byte2DoubleLinkedOpenCustomHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() { Byte2DoubleLinkedOpenCustomHashMap.this.clear(); }
|
||||
@Override
|
||||
public DoubleOrderedCollection reversed() { return new AbstractDoubleCollection.ReverseDoubleOrderedCollection(this, this::reverseIterator); }
|
||||
private DoubleIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(double o) {
|
||||
throw new UnsupportedOperationException();
|
||||
public void addFirst(double e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(double e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public double getFirstDouble() { return firstDoubleValue(); }
|
||||
@Override
|
||||
public double removeFirstDouble() {
|
||||
double result = firstDoubleValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public double getLastDouble() { return lastDoubleValue(); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2DoubleLinkedOpenCustomHashMap.this.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2DoubleLinkedOpenCustomHashMap.this.clear();
|
||||
public double removeLastDouble() {
|
||||
double result = lastDoubleValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1184,7 +1299,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2DoubleMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1211,7 +1326,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2DoubleMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1241,7 +1356,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1263,7 +1378,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements DoubleListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public double previousDouble() {
|
||||
@ -1284,16 +1399,20 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, (byte)0)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -1321,11 +1440,11 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1385,20 +1504,30 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -24,7 +24,7 @@ import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.bytes.utils.ByteStrategy;
|
||||
import speiger.src.collections.floats.collections.AbstractFloatCollection;
|
||||
import speiger.src.collections.floats.collections.FloatCollection;
|
||||
import speiger.src.collections.floats.collections.FloatOrderedCollection;
|
||||
import speiger.src.collections.floats.collections.FloatIterator;
|
||||
import speiger.src.collections.floats.functions.function.FloatFloatUnaryOperator;
|
||||
import speiger.src.collections.floats.functions.FloatConsumer;
|
||||
@ -258,6 +258,54 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float putFirst(byte key, float value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float putLast(byte key, float value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || strategy.equals(firstByteKey(), key)) return false;
|
||||
@ -393,6 +441,52 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0F;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0F;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2FloatMap.Entry> byte2FloatEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -406,9 +500,9 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
}
|
||||
|
||||
@Override
|
||||
public FloatCollection values() {
|
||||
public FloatOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (FloatOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -593,24 +687,24 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry first() {
|
||||
public Byte2FloatMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstFloatValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry last() {
|
||||
public Byte2FloatMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastFloatValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry pollFirst() {
|
||||
public Byte2FloatMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstFloatValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry pollLast() {
|
||||
public Byte2FloatMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastFloatValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -618,7 +712,12 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2FloatMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2FloatMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -628,7 +727,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2FloatMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -864,7 +963,12 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -886,22 +990,22 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1030,30 +1134,41 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractFloatCollection {
|
||||
private class Values extends AbstractFloatCollection implements FloatOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(float e) {
|
||||
return containsValue(e);
|
||||
public boolean contains(float e) { return containsValue(e); }
|
||||
@Override
|
||||
public boolean add(float o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public FloatIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() { return Byte2FloatLinkedOpenCustomHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() { Byte2FloatLinkedOpenCustomHashMap.this.clear(); }
|
||||
@Override
|
||||
public FloatOrderedCollection reversed() { return new AbstractFloatCollection.ReverseFloatOrderedCollection(this, this::reverseIterator); }
|
||||
private FloatIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(float o) {
|
||||
throw new UnsupportedOperationException();
|
||||
public void addFirst(float e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(float e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public float getFirstFloat() { return firstFloatValue(); }
|
||||
@Override
|
||||
public float removeFirstFloat() {
|
||||
float result = firstFloatValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FloatIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public float getLastFloat() { return lastFloatValue(); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2FloatLinkedOpenCustomHashMap.this.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2FloatLinkedOpenCustomHashMap.this.clear();
|
||||
public float removeLastFloat() {
|
||||
float result = lastFloatValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1184,7 +1299,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2FloatMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1211,7 +1326,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2FloatMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1241,7 +1356,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1263,7 +1378,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements FloatListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public float previousFloat() {
|
||||
@ -1284,16 +1399,20 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, (byte)0)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -1321,11 +1440,11 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1385,20 +1504,30 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -25,7 +25,7 @@ import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.bytes.utils.ByteStrategy;
|
||||
import speiger.src.collections.ints.collections.AbstractIntCollection;
|
||||
import speiger.src.collections.ints.collections.IntCollection;
|
||||
import speiger.src.collections.ints.collections.IntOrderedCollection;
|
||||
import speiger.src.collections.ints.collections.IntIterator;
|
||||
import speiger.src.collections.ints.functions.function.IntIntUnaryOperator;
|
||||
import speiger.src.collections.ints.functions.IntConsumer;
|
||||
@ -258,6 +258,54 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int putFirst(byte key, int value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int putLast(byte key, int value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || strategy.equals(firstByteKey(), key)) return false;
|
||||
@ -393,6 +441,52 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2IntMap.Entry> byte2IntEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -406,9 +500,9 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntCollection values() {
|
||||
public IntOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (IntOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -593,24 +687,24 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry first() {
|
||||
public Byte2IntMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstIntValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry last() {
|
||||
public Byte2IntMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastIntValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry pollFirst() {
|
||||
public Byte2IntMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstIntValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry pollLast() {
|
||||
public Byte2IntMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastIntValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -618,7 +712,12 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2IntMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2IntMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -628,7 +727,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2IntMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -864,7 +963,12 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -886,22 +990,22 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1030,30 +1134,41 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractIntCollection {
|
||||
private class Values extends AbstractIntCollection implements IntOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(int e) {
|
||||
return containsValue(e);
|
||||
public boolean contains(int e) { return containsValue(e); }
|
||||
@Override
|
||||
public boolean add(int o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public IntIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() { return Byte2IntLinkedOpenCustomHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() { Byte2IntLinkedOpenCustomHashMap.this.clear(); }
|
||||
@Override
|
||||
public IntOrderedCollection reversed() { return new AbstractIntCollection.ReverseIntOrderedCollection(this, this::reverseIterator); }
|
||||
private IntIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(int o) {
|
||||
throw new UnsupportedOperationException();
|
||||
public void addFirst(int e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(int e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public int getFirstInt() { return firstIntValue(); }
|
||||
@Override
|
||||
public int removeFirstInt() {
|
||||
int result = firstIntValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public int getLastInt() { return lastIntValue(); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2IntLinkedOpenCustomHashMap.this.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2IntLinkedOpenCustomHashMap.this.clear();
|
||||
public int removeLastInt() {
|
||||
int result = lastIntValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1184,7 +1299,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2IntMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1211,7 +1326,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2IntMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1241,7 +1356,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1263,7 +1378,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements IntListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public int previousInt() {
|
||||
@ -1284,16 +1399,20 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, (byte)0)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -1321,11 +1440,11 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1385,20 +1504,30 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -25,7 +25,7 @@ import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.bytes.utils.ByteStrategy;
|
||||
import speiger.src.collections.longs.collections.AbstractLongCollection;
|
||||
import speiger.src.collections.longs.collections.LongCollection;
|
||||
import speiger.src.collections.longs.collections.LongOrderedCollection;
|
||||
import speiger.src.collections.longs.collections.LongIterator;
|
||||
import speiger.src.collections.longs.functions.function.LongLongUnaryOperator;
|
||||
import speiger.src.collections.longs.functions.LongConsumer;
|
||||
@ -258,6 +258,54 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long putFirst(byte key, long value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long putLast(byte key, long value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || strategy.equals(firstByteKey(), key)) return false;
|
||||
@ -393,6 +441,52 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0L;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0L;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2LongMap.Entry> byte2LongEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -406,9 +500,9 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongCollection values() {
|
||||
public LongOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (LongOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -593,24 +687,24 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry first() {
|
||||
public Byte2LongMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstLongValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry last() {
|
||||
public Byte2LongMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastLongValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry pollFirst() {
|
||||
public Byte2LongMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstLongValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry pollLast() {
|
||||
public Byte2LongMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastLongValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -618,7 +712,12 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2LongMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2LongMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -628,7 +727,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2LongMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -864,7 +963,12 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -886,22 +990,22 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1030,30 +1134,41 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractLongCollection {
|
||||
private class Values extends AbstractLongCollection implements LongOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(long e) {
|
||||
return containsValue(e);
|
||||
public boolean contains(long e) { return containsValue(e); }
|
||||
@Override
|
||||
public boolean add(long o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public LongIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() { return Byte2LongLinkedOpenCustomHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() { Byte2LongLinkedOpenCustomHashMap.this.clear(); }
|
||||
@Override
|
||||
public LongOrderedCollection reversed() { return new AbstractLongCollection.ReverseLongOrderedCollection(this, this::reverseIterator); }
|
||||
private LongIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(long o) {
|
||||
throw new UnsupportedOperationException();
|
||||
public void addFirst(long e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(long e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public long getFirstLong() { return firstLongValue(); }
|
||||
@Override
|
||||
public long removeFirstLong() {
|
||||
long result = firstLongValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public long getLastLong() { return lastLongValue(); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2LongLinkedOpenCustomHashMap.this.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2LongLinkedOpenCustomHashMap.this.clear();
|
||||
public long removeLastLong() {
|
||||
long result = lastLongValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1184,7 +1299,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2LongMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1211,7 +1326,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2LongMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1241,7 +1356,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1263,7 +1378,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements LongListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public long previousLong() {
|
||||
@ -1284,16 +1399,20 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, (byte)0)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -1321,11 +1440,11 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1385,20 +1504,30 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -23,7 +23,7 @@ import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.bytes.utils.ByteStrategy;
|
||||
import speiger.src.collections.objects.collections.AbstractObjectCollection;
|
||||
import speiger.src.collections.objects.collections.ObjectCollection;
|
||||
import speiger.src.collections.objects.collections.ObjectOrderedCollection;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
@ -253,6 +253,54 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V putFirst(byte key, V value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V putLast(byte key, V value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || strategy.equals(firstByteKey(), key)) return false;
|
||||
@ -388,6 +436,52 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry<>(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry<>(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry<V> result = new BasicEntry<>(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = null;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry<V> result = new BasicEntry<>(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = null;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2ObjectMap.Entry<V>> byte2ObjectEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -401,9 +495,9 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectCollection<V> values() {
|
||||
public ObjectOrderedCollection<V> values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (ObjectOrderedCollection<V>)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -588,24 +682,24 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> first() {
|
||||
public Byte2ObjectMap.Entry<V> getFirst() {
|
||||
return new BasicEntry<>(firstByteKey(), firstValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> last() {
|
||||
public Byte2ObjectMap.Entry<V> getLast() {
|
||||
return new BasicEntry<>(lastByteKey(), lastValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> pollFirst() {
|
||||
public Byte2ObjectMap.Entry<V> removeFirst() {
|
||||
BasicEntry<V> entry = new BasicEntry<>(firstByteKey(), firstValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> pollLast() {
|
||||
public Byte2ObjectMap.Entry<V> removeLast() {
|
||||
BasicEntry<V> entry = new BasicEntry<>(lastByteKey(), lastValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -613,7 +707,12 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ObjectMap.Entry<V>> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ObjectMap.Entry<V>> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -623,7 +722,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ObjectMap.Entry<V>> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -859,7 +958,12 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -881,22 +985,22 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1025,31 +1129,42 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractObjectCollection<V> {
|
||||
private class Values extends AbstractObjectCollection<V> implements ObjectOrderedCollection<V> {
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
@Override
|
||||
public boolean add(V o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(V o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ObjectIterator<V> iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public ObjectIterator<V> iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2ObjectLinkedOpenCustomHashMap.this.size();
|
||||
}
|
||||
|
||||
public int size() { return Byte2ObjectLinkedOpenCustomHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2ObjectLinkedOpenCustomHashMap.this.clear();
|
||||
public void clear() { Byte2ObjectLinkedOpenCustomHashMap.this.clear(); }
|
||||
@Override
|
||||
public ObjectOrderedCollection<V> reversed() { return new AbstractObjectCollection.ReverseObjectOrderedCollection<>(this, this::reverseIterator); }
|
||||
private ObjectIterator<V> reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(V e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(V e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public V getFirst() { return firstValue(); }
|
||||
@Override
|
||||
public V removeFirst() {
|
||||
V result = firstValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public V getLast() { return lastValue(); }
|
||||
@Override
|
||||
public V removeLast() {
|
||||
V result = lastValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1180,7 +1295,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2ObjectMap.Entry<V>> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1207,7 +1322,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2ObjectMap.Entry<V>> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1237,7 +1352,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1259,7 +1374,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements ObjectListIterator<V> {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public V previous() {
|
||||
@ -1280,16 +1395,20 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, (byte)0)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -1317,11 +1436,11 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1381,20 +1500,30 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -24,7 +24,7 @@ import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.bytes.utils.ByteStrategy;
|
||||
import speiger.src.collections.shorts.collections.AbstractShortCollection;
|
||||
import speiger.src.collections.shorts.collections.ShortCollection;
|
||||
import speiger.src.collections.shorts.collections.ShortOrderedCollection;
|
||||
import speiger.src.collections.shorts.collections.ShortIterator;
|
||||
import speiger.src.collections.shorts.functions.function.ShortShortUnaryOperator;
|
||||
import speiger.src.collections.shorts.functions.ShortConsumer;
|
||||
@ -258,6 +258,54 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short putFirst(byte key, short value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short putLast(byte key, short value) {
|
||||
if(strategy.equals(key, (byte)0)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], (byte)0)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || strategy.equals(firstByteKey(), key)) return false;
|
||||
@ -393,6 +441,52 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = (short)0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.getByteKey(), (byte)0)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = (short)0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2ShortMap.Entry> byte2ShortEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -406,9 +500,9 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShortCollection values() {
|
||||
public ShortOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (ShortOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -593,24 +687,24 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry first() {
|
||||
public Byte2ShortMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstShortValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry last() {
|
||||
public Byte2ShortMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastShortValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry pollFirst() {
|
||||
public Byte2ShortMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstShortValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry pollLast() {
|
||||
public Byte2ShortMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastShortValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -618,7 +712,12 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ShortMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ShortMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -628,7 +727,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ShortMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -864,7 +963,12 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -886,22 +990,22 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1030,30 +1134,41 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractShortCollection {
|
||||
private class Values extends AbstractShortCollection implements ShortOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(short e) {
|
||||
return containsValue(e);
|
||||
public boolean contains(short e) { return containsValue(e); }
|
||||
@Override
|
||||
public boolean add(short o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ShortIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() { return Byte2ShortLinkedOpenCustomHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() { Byte2ShortLinkedOpenCustomHashMap.this.clear(); }
|
||||
@Override
|
||||
public ShortOrderedCollection reversed() { return new AbstractShortCollection.ReverseShortOrderedCollection(this, this::reverseIterator); }
|
||||
private ShortIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(short o) {
|
||||
throw new UnsupportedOperationException();
|
||||
public void addFirst(short e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(short e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public short getFirstShort() { return firstShortValue(); }
|
||||
@Override
|
||||
public short removeFirstShort() {
|
||||
short result = firstShortValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShortIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public short getLastShort() { return lastShortValue(); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2ShortLinkedOpenCustomHashMap.this.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2ShortLinkedOpenCustomHashMap.this.clear();
|
||||
public short removeLastShort() {
|
||||
short result = lastShortValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1184,7 +1299,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2ShortMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1211,7 +1326,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2ShortMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1241,7 +1356,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1263,7 +1378,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements ShortListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public short previousShort() {
|
||||
@ -1284,16 +1399,20 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, (byte)0)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -1321,11 +1440,11 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1385,20 +1504,30 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -23,7 +23,7 @@ import speiger.src.collections.bytes.maps.interfaces.Byte2BooleanOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.booleans.collections.AbstractBooleanCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanOrderedCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
import speiger.src.collections.booleans.functions.function.BooleanBooleanUnaryOperator;
|
||||
import speiger.src.collections.booleans.functions.BooleanConsumer;
|
||||
@ -235,6 +235,54 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean putFirst(byte key, boolean value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean putLast(byte key, boolean value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || firstByteKey() == key) return false;
|
||||
@ -391,6 +439,52 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = false;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = false;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2BooleanMap.Entry> byte2BooleanEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -404,9 +498,9 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanCollection values() {
|
||||
public BooleanOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (BooleanOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -591,24 +685,24 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry first() {
|
||||
public Byte2BooleanMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstBooleanValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry last() {
|
||||
public Byte2BooleanMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastBooleanValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry pollFirst() {
|
||||
public Byte2BooleanMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstBooleanValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry pollLast() {
|
||||
public Byte2BooleanMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastBooleanValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -616,7 +710,12 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2BooleanMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2BooleanMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -626,7 +725,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2BooleanMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -859,7 +958,12 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -881,22 +985,22 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1025,32 +1129,43 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractBooleanCollection {
|
||||
private class Values extends AbstractBooleanCollection implements BooleanOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(boolean e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(boolean e) { return containsValue(e); }
|
||||
|
||||
@Override
|
||||
public boolean add(boolean o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(boolean o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public BooleanIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public BooleanIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2BooleanLinkedOpenHashMap.this.size();
|
||||
}
|
||||
|
||||
public int size() { return Byte2BooleanLinkedOpenHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2BooleanLinkedOpenHashMap.this.clear();
|
||||
public void clear() { Byte2BooleanLinkedOpenHashMap.this.clear(); }
|
||||
@Override
|
||||
public BooleanOrderedCollection reversed() { return new AbstractBooleanCollection.ReverseBooleanOrderedCollection(this, this::reverseIterator); }
|
||||
private BooleanIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(boolean e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(boolean e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean getFirstBoolean() { return firstBooleanValue(); }
|
||||
@Override
|
||||
public boolean removeFirstBoolean() {
|
||||
boolean result = firstBooleanValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean getLastBoolean() { return lastBooleanValue(); }
|
||||
@Override
|
||||
public boolean removeLastBoolean() {
|
||||
boolean result = lastBooleanValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(BooleanConsumer action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1180,7 +1295,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2BooleanMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1207,7 +1322,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2BooleanMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1237,7 +1352,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1259,7 +1374,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements BooleanListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public boolean previousBoolean() {
|
||||
@ -1279,13 +1394,16 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
@ -1316,11 +1434,11 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1380,20 +1498,30 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -22,7 +22,7 @@ import speiger.src.collections.bytes.maps.interfaces.Byte2ByteOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.bytes.collections.AbstractByteCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteOrderedCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteIterator;
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||
@ -228,6 +228,54 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte putFirst(byte key, byte value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte putLast(byte key, byte value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || firstByteKey() == key) return false;
|
||||
@ -384,6 +432,52 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = (byte)0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = (byte)0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2ByteMap.Entry> byte2ByteEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -397,9 +491,9 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteCollection values() {
|
||||
public ByteOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (ByteOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -584,24 +678,24 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry first() {
|
||||
public Byte2ByteMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstByteValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry last() {
|
||||
public Byte2ByteMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastByteValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry pollFirst() {
|
||||
public Byte2ByteMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstByteValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry pollLast() {
|
||||
public Byte2ByteMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastByteValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -609,7 +703,12 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ByteMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ByteMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -619,7 +718,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ByteMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -852,7 +951,12 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -874,22 +978,22 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1018,32 +1122,43 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractByteCollection {
|
||||
private class Values extends AbstractByteCollection implements ByteOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(byte e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(byte e) { return containsValue(e); }
|
||||
|
||||
@Override
|
||||
public boolean add(byte o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(byte o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ByteIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public ByteIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2ByteLinkedOpenHashMap.this.size();
|
||||
}
|
||||
|
||||
public int size() { return Byte2ByteLinkedOpenHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2ByteLinkedOpenHashMap.this.clear();
|
||||
public void clear() { Byte2ByteLinkedOpenHashMap.this.clear(); }
|
||||
@Override
|
||||
public ByteOrderedCollection reversed() { return new AbstractByteCollection.ReverseByteOrderedCollection(this, this::reverseIterator); }
|
||||
private ByteIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(byte e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(byte e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public byte getFirstByte() { return firstByteValue(); }
|
||||
@Override
|
||||
public byte removeFirstByte() {
|
||||
byte result = firstByteValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public byte getLastByte() { return lastByteValue(); }
|
||||
@Override
|
||||
public byte removeLastByte() {
|
||||
byte result = lastByteValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(ByteConsumer action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1173,7 +1288,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2ByteMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1200,7 +1315,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2ByteMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1230,7 +1345,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1252,7 +1367,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements ByteListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public byte previousByte() {
|
||||
@ -1272,13 +1387,16 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
@ -1309,11 +1427,11 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1373,20 +1491,30 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -23,7 +23,7 @@ import speiger.src.collections.bytes.maps.interfaces.Byte2CharOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.chars.collections.AbstractCharCollection;
|
||||
import speiger.src.collections.chars.collections.CharCollection;
|
||||
import speiger.src.collections.chars.collections.CharOrderedCollection;
|
||||
import speiger.src.collections.chars.collections.CharIterator;
|
||||
import speiger.src.collections.chars.functions.function.CharCharUnaryOperator;
|
||||
import speiger.src.collections.chars.functions.CharConsumer;
|
||||
@ -235,6 +235,54 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char putFirst(byte key, char value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char putLast(byte key, char value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || firstByteKey() == key) return false;
|
||||
@ -391,6 +439,52 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = (char)0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = (char)0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2CharMap.Entry> byte2CharEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -404,9 +498,9 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharCollection values() {
|
||||
public CharOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (CharOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -591,24 +685,24 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry first() {
|
||||
public Byte2CharMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstCharValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry last() {
|
||||
public Byte2CharMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastCharValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry pollFirst() {
|
||||
public Byte2CharMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstCharValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry pollLast() {
|
||||
public Byte2CharMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastCharValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -616,7 +710,12 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2CharMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2CharMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -626,7 +725,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2CharMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -859,7 +958,12 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -881,22 +985,22 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1025,32 +1129,43 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractCharCollection {
|
||||
private class Values extends AbstractCharCollection implements CharOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(char e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(char e) { return containsValue(e); }
|
||||
|
||||
@Override
|
||||
public boolean add(char o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(char o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public CharIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public CharIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2CharLinkedOpenHashMap.this.size();
|
||||
}
|
||||
|
||||
public int size() { return Byte2CharLinkedOpenHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2CharLinkedOpenHashMap.this.clear();
|
||||
public void clear() { Byte2CharLinkedOpenHashMap.this.clear(); }
|
||||
@Override
|
||||
public CharOrderedCollection reversed() { return new AbstractCharCollection.ReverseCharOrderedCollection(this, this::reverseIterator); }
|
||||
private CharIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(char e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(char e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public char getFirstChar() { return firstCharValue(); }
|
||||
@Override
|
||||
public char removeFirstChar() {
|
||||
char result = firstCharValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public char getLastChar() { return lastCharValue(); }
|
||||
@Override
|
||||
public char removeLastChar() {
|
||||
char result = lastCharValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(CharConsumer action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1180,7 +1295,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2CharMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1207,7 +1322,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2CharMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1237,7 +1352,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1259,7 +1374,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements CharListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public char previousChar() {
|
||||
@ -1279,13 +1394,16 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
@ -1316,11 +1434,11 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1380,20 +1498,30 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -24,7 +24,7 @@ import speiger.src.collections.bytes.maps.interfaces.Byte2DoubleOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.doubles.collections.AbstractDoubleCollection;
|
||||
import speiger.src.collections.doubles.collections.DoubleCollection;
|
||||
import speiger.src.collections.doubles.collections.DoubleOrderedCollection;
|
||||
import speiger.src.collections.doubles.collections.DoubleIterator;
|
||||
import speiger.src.collections.doubles.functions.function.DoubleDoubleUnaryOperator;
|
||||
import speiger.src.collections.doubles.functions.DoubleConsumer;
|
||||
@ -235,6 +235,54 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double putFirst(byte key, double value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double putLast(byte key, double value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || firstByteKey() == key) return false;
|
||||
@ -391,6 +439,52 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0D;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0D;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2DoubleMap.Entry> byte2DoubleEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -404,9 +498,9 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleCollection values() {
|
||||
public DoubleOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (DoubleOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -591,24 +685,24 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry first() {
|
||||
public Byte2DoubleMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstDoubleValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry last() {
|
||||
public Byte2DoubleMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastDoubleValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry pollFirst() {
|
||||
public Byte2DoubleMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstDoubleValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry pollLast() {
|
||||
public Byte2DoubleMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastDoubleValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -616,7 +710,12 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2DoubleMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2DoubleMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -626,7 +725,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2DoubleMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -859,7 +958,12 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -881,22 +985,22 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1025,32 +1129,43 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractDoubleCollection {
|
||||
private class Values extends AbstractDoubleCollection implements DoubleOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(double e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(double e) { return containsValue(e); }
|
||||
|
||||
@Override
|
||||
public boolean add(double o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(double o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public DoubleIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public DoubleIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2DoubleLinkedOpenHashMap.this.size();
|
||||
}
|
||||
|
||||
public int size() { return Byte2DoubleLinkedOpenHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2DoubleLinkedOpenHashMap.this.clear();
|
||||
public void clear() { Byte2DoubleLinkedOpenHashMap.this.clear(); }
|
||||
@Override
|
||||
public DoubleOrderedCollection reversed() { return new AbstractDoubleCollection.ReverseDoubleOrderedCollection(this, this::reverseIterator); }
|
||||
private DoubleIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(double e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(double e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public double getFirstDouble() { return firstDoubleValue(); }
|
||||
@Override
|
||||
public double removeFirstDouble() {
|
||||
double result = firstDoubleValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public double getLastDouble() { return lastDoubleValue(); }
|
||||
@Override
|
||||
public double removeLastDouble() {
|
||||
double result = lastDoubleValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(DoubleConsumer action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1180,7 +1295,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2DoubleMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1207,7 +1322,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2DoubleMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1237,7 +1352,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1259,7 +1374,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements DoubleListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public double previousDouble() {
|
||||
@ -1279,13 +1394,16 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
@ -1316,11 +1434,11 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1380,20 +1498,30 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -23,7 +23,7 @@ import speiger.src.collections.bytes.maps.interfaces.Byte2FloatOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.floats.collections.AbstractFloatCollection;
|
||||
import speiger.src.collections.floats.collections.FloatCollection;
|
||||
import speiger.src.collections.floats.collections.FloatOrderedCollection;
|
||||
import speiger.src.collections.floats.collections.FloatIterator;
|
||||
import speiger.src.collections.floats.functions.function.FloatFloatUnaryOperator;
|
||||
import speiger.src.collections.floats.functions.FloatConsumer;
|
||||
@ -235,6 +235,54 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float putFirst(byte key, float value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float putLast(byte key, float value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || firstByteKey() == key) return false;
|
||||
@ -391,6 +439,52 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0F;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0F;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2FloatMap.Entry> byte2FloatEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -404,9 +498,9 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public FloatCollection values() {
|
||||
public FloatOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (FloatOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -591,24 +685,24 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry first() {
|
||||
public Byte2FloatMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstFloatValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry last() {
|
||||
public Byte2FloatMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastFloatValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry pollFirst() {
|
||||
public Byte2FloatMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstFloatValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2FloatMap.Entry pollLast() {
|
||||
public Byte2FloatMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastFloatValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -616,7 +710,12 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2FloatMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2FloatMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -626,7 +725,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2FloatMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -859,7 +958,12 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -881,22 +985,22 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1025,32 +1129,43 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractFloatCollection {
|
||||
private class Values extends AbstractFloatCollection implements FloatOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(float e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(float e) { return containsValue(e); }
|
||||
|
||||
@Override
|
||||
public boolean add(float o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(float o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public FloatIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public FloatIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2FloatLinkedOpenHashMap.this.size();
|
||||
}
|
||||
|
||||
public int size() { return Byte2FloatLinkedOpenHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2FloatLinkedOpenHashMap.this.clear();
|
||||
public void clear() { Byte2FloatLinkedOpenHashMap.this.clear(); }
|
||||
@Override
|
||||
public FloatOrderedCollection reversed() { return new AbstractFloatCollection.ReverseFloatOrderedCollection(this, this::reverseIterator); }
|
||||
private FloatIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(float e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(float e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public float getFirstFloat() { return firstFloatValue(); }
|
||||
@Override
|
||||
public float removeFirstFloat() {
|
||||
float result = firstFloatValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public float getLastFloat() { return lastFloatValue(); }
|
||||
@Override
|
||||
public float removeLastFloat() {
|
||||
float result = lastFloatValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(FloatConsumer action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1180,7 +1295,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2FloatMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1207,7 +1322,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2FloatMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1237,7 +1352,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1259,7 +1374,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements FloatListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public float previousFloat() {
|
||||
@ -1279,13 +1394,16 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
@ -1316,11 +1434,11 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1380,20 +1498,30 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -24,7 +24,7 @@ import speiger.src.collections.bytes.maps.interfaces.Byte2IntOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.ints.collections.AbstractIntCollection;
|
||||
import speiger.src.collections.ints.collections.IntCollection;
|
||||
import speiger.src.collections.ints.collections.IntOrderedCollection;
|
||||
import speiger.src.collections.ints.collections.IntIterator;
|
||||
import speiger.src.collections.ints.functions.function.IntIntUnaryOperator;
|
||||
import speiger.src.collections.ints.functions.IntConsumer;
|
||||
@ -235,6 +235,54 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int putFirst(byte key, int value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int putLast(byte key, int value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || firstByteKey() == key) return false;
|
||||
@ -391,6 +439,52 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2IntMap.Entry> byte2IntEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -404,9 +498,9 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntCollection values() {
|
||||
public IntOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (IntOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -591,24 +685,24 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry first() {
|
||||
public Byte2IntMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstIntValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry last() {
|
||||
public Byte2IntMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastIntValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry pollFirst() {
|
||||
public Byte2IntMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstIntValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2IntMap.Entry pollLast() {
|
||||
public Byte2IntMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastIntValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -616,7 +710,12 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2IntMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2IntMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -626,7 +725,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2IntMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -859,7 +958,12 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -881,22 +985,22 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1025,32 +1129,43 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractIntCollection {
|
||||
private class Values extends AbstractIntCollection implements IntOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(int e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(int e) { return containsValue(e); }
|
||||
|
||||
@Override
|
||||
public boolean add(int o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(int o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public IntIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public IntIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2IntLinkedOpenHashMap.this.size();
|
||||
}
|
||||
|
||||
public int size() { return Byte2IntLinkedOpenHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2IntLinkedOpenHashMap.this.clear();
|
||||
public void clear() { Byte2IntLinkedOpenHashMap.this.clear(); }
|
||||
@Override
|
||||
public IntOrderedCollection reversed() { return new AbstractIntCollection.ReverseIntOrderedCollection(this, this::reverseIterator); }
|
||||
private IntIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(int e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(int e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public int getFirstInt() { return firstIntValue(); }
|
||||
@Override
|
||||
public int removeFirstInt() {
|
||||
int result = firstIntValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public int getLastInt() { return lastIntValue(); }
|
||||
@Override
|
||||
public int removeLastInt() {
|
||||
int result = lastIntValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(IntConsumer action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1180,7 +1295,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2IntMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1207,7 +1322,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2IntMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1237,7 +1352,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1259,7 +1374,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements IntListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public int previousInt() {
|
||||
@ -1279,13 +1394,16 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
@ -1316,11 +1434,11 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1380,20 +1498,30 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -24,7 +24,7 @@ import speiger.src.collections.bytes.maps.interfaces.Byte2LongOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.longs.collections.AbstractLongCollection;
|
||||
import speiger.src.collections.longs.collections.LongCollection;
|
||||
import speiger.src.collections.longs.collections.LongOrderedCollection;
|
||||
import speiger.src.collections.longs.collections.LongIterator;
|
||||
import speiger.src.collections.longs.functions.function.LongLongUnaryOperator;
|
||||
import speiger.src.collections.longs.functions.LongConsumer;
|
||||
@ -235,6 +235,54 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long putFirst(byte key, long value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long putLast(byte key, long value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || firstByteKey() == key) return false;
|
||||
@ -391,6 +439,52 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0L;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = 0L;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2LongMap.Entry> byte2LongEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -404,9 +498,9 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongCollection values() {
|
||||
public LongOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (LongOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -591,24 +685,24 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry first() {
|
||||
public Byte2LongMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstLongValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry last() {
|
||||
public Byte2LongMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastLongValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry pollFirst() {
|
||||
public Byte2LongMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstLongValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2LongMap.Entry pollLast() {
|
||||
public Byte2LongMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastLongValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -616,7 +710,12 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2LongMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2LongMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -626,7 +725,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2LongMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -859,7 +958,12 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -881,22 +985,22 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1025,32 +1129,43 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractLongCollection {
|
||||
private class Values extends AbstractLongCollection implements LongOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(long e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(long e) { return containsValue(e); }
|
||||
|
||||
@Override
|
||||
public boolean add(long o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(long o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public LongIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public LongIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2LongLinkedOpenHashMap.this.size();
|
||||
}
|
||||
|
||||
public int size() { return Byte2LongLinkedOpenHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2LongLinkedOpenHashMap.this.clear();
|
||||
public void clear() { Byte2LongLinkedOpenHashMap.this.clear(); }
|
||||
@Override
|
||||
public LongOrderedCollection reversed() { return new AbstractLongCollection.ReverseLongOrderedCollection(this, this::reverseIterator); }
|
||||
private LongIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(long e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(long e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public long getFirstLong() { return firstLongValue(); }
|
||||
@Override
|
||||
public long removeFirstLong() {
|
||||
long result = firstLongValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public long getLastLong() { return lastLongValue(); }
|
||||
@Override
|
||||
public long removeLastLong() {
|
||||
long result = lastLongValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(LongConsumer action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1180,7 +1295,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2LongMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1207,7 +1322,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2LongMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1237,7 +1352,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1259,7 +1374,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements LongListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public long previousLong() {
|
||||
@ -1279,13 +1394,16 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
@ -1316,11 +1434,11 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1380,20 +1498,30 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -22,7 +22,7 @@ import speiger.src.collections.bytes.maps.interfaces.Byte2ObjectOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.objects.collections.AbstractObjectCollection;
|
||||
import speiger.src.collections.objects.collections.ObjectCollection;
|
||||
import speiger.src.collections.objects.collections.ObjectOrderedCollection;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
@ -230,6 +230,54 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V putFirst(byte key, V value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V putLast(byte key, V value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || firstByteKey() == key) return false;
|
||||
@ -375,6 +423,52 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry<>(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry<>(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry<V> result = new BasicEntry<>(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = null;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry<V> result = new BasicEntry<>(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = null;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2ObjectMap.Entry<V>> byte2ObjectEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -388,9 +482,9 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectCollection<V> values() {
|
||||
public ObjectOrderedCollection<V> values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (ObjectOrderedCollection<V>)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -575,24 +669,24 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> first() {
|
||||
public Byte2ObjectMap.Entry<V> getFirst() {
|
||||
return new BasicEntry<>(firstByteKey(), firstValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> last() {
|
||||
public Byte2ObjectMap.Entry<V> getLast() {
|
||||
return new BasicEntry<>(lastByteKey(), lastValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> pollFirst() {
|
||||
public Byte2ObjectMap.Entry<V> removeFirst() {
|
||||
BasicEntry<V> entry = new BasicEntry<>(firstByteKey(), firstValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ObjectMap.Entry<V> pollLast() {
|
||||
public Byte2ObjectMap.Entry<V> removeLast() {
|
||||
BasicEntry<V> entry = new BasicEntry<>(lastByteKey(), lastValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -600,7 +694,12 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ObjectMap.Entry<V>> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ObjectMap.Entry<V>> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -610,7 +709,7 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ObjectMap.Entry<V>> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -843,7 +942,12 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -865,22 +969,22 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1009,33 +1113,44 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractObjectCollection<V> {
|
||||
private class Values extends AbstractObjectCollection<V> implements ObjectOrderedCollection<V> {
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
|
||||
@Override
|
||||
public boolean add(V o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(V o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ObjectIterator<V> iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public ObjectIterator<V> iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2ObjectLinkedOpenHashMap.this.size();
|
||||
}
|
||||
|
||||
public int size() { return Byte2ObjectLinkedOpenHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2ObjectLinkedOpenHashMap.this.clear();
|
||||
public void clear() { Byte2ObjectLinkedOpenHashMap.this.clear(); }
|
||||
@Override
|
||||
public ObjectOrderedCollection<V> reversed() { return new AbstractObjectCollection.ReverseObjectOrderedCollection<>(this, this::reverseIterator); }
|
||||
private ObjectIterator<V> reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(V e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(V e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public V getFirst() { return firstValue(); }
|
||||
@Override
|
||||
public V removeFirst() {
|
||||
V result = firstValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public V getLast() { return lastValue(); }
|
||||
@Override
|
||||
public V removeLast() {
|
||||
V result = lastValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super V> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1165,7 +1280,7 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2ObjectMap.Entry<V>> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1192,7 +1307,7 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2ObjectMap.Entry<V>> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1222,7 +1337,7 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1244,7 +1359,7 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements ObjectListIterator<V> {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public V previous() {
|
||||
@ -1264,13 +1379,16 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
@ -1301,11 +1419,11 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1365,20 +1483,30 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -23,7 +23,7 @@ import speiger.src.collections.bytes.maps.interfaces.Byte2ShortOrderedMap;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.sets.ByteOrderedSet;
|
||||
import speiger.src.collections.shorts.collections.AbstractShortCollection;
|
||||
import speiger.src.collections.shorts.collections.ShortCollection;
|
||||
import speiger.src.collections.shorts.collections.ShortOrderedCollection;
|
||||
import speiger.src.collections.shorts.collections.ShortIterator;
|
||||
import speiger.src.collections.shorts.functions.function.ShortShortUnaryOperator;
|
||||
import speiger.src.collections.shorts.functions.ShortConsumer;
|
||||
@ -235,6 +235,54 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short putFirst(byte key, short value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short putLast(byte key, short value) {
|
||||
if(key == (byte)0) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(Byte.hashCode(key)) & mask;
|
||||
while(key == (byte)0) {
|
||||
if(keys[pos] == key) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) {
|
||||
if(isEmpty() || firstByteKey() == key) return false;
|
||||
@ -391,6 +439,52 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = (short)0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry result = new BasicEntry(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(result.getByteKey() == (byte)0) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = (byte)0;
|
||||
values[nullIndex] = (short)0;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2ShortMap.Entry> byte2ShortEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -404,9 +498,9 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShortCollection values() {
|
||||
public ShortOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (ShortOrderedCollection)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -591,24 +685,24 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry first() {
|
||||
public Byte2ShortMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstShortValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry last() {
|
||||
public Byte2ShortMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastShortValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry pollFirst() {
|
||||
public Byte2ShortMap.Entry removeFirst() {
|
||||
BasicEntry entry = new BasicEntry(firstByteKey(), firstShortValue());
|
||||
pollFirstByteKey();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ShortMap.Entry pollLast() {
|
||||
public Byte2ShortMap.Entry removeLast() {
|
||||
BasicEntry entry = new BasicEntry(lastByteKey(), lastShortValue());
|
||||
pollLastByteKey();
|
||||
return entry;
|
||||
@ -616,7 +710,12 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ShortMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ShortMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -626,7 +725,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ShortMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -859,7 +958,12 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -881,22 +985,22 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() {
|
||||
public byte removeFirstByte() {
|
||||
return pollFirstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() {
|
||||
public byte removeLastByte() {
|
||||
return pollLastByteKey();
|
||||
}
|
||||
|
||||
@ -1025,32 +1129,43 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractShortCollection {
|
||||
private class Values extends AbstractShortCollection implements ShortOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(short e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(short e) { return containsValue(e); }
|
||||
|
||||
@Override
|
||||
public boolean add(short o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(short o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ShortIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public ShortIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return Byte2ShortLinkedOpenHashMap.this.size();
|
||||
}
|
||||
|
||||
public int size() { return Byte2ShortLinkedOpenHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
Byte2ShortLinkedOpenHashMap.this.clear();
|
||||
public void clear() { Byte2ShortLinkedOpenHashMap.this.clear(); }
|
||||
@Override
|
||||
public ShortOrderedCollection reversed() { return new AbstractShortCollection.ReverseShortOrderedCollection(this, this::reverseIterator); }
|
||||
private ShortIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(short e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(short e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public short getFirstShort() { return firstShortValue(); }
|
||||
@Override
|
||||
public short removeFirstShort() {
|
||||
short result = firstShortValue();
|
||||
pollFirstByteKey();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public short getLastShort() { return lastShortValue(); }
|
||||
@Override
|
||||
public short removeLastShort() {
|
||||
short result = lastShortValue();
|
||||
pollLastByteKey();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(ShortConsumer action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1180,7 +1295,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2ShortMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1207,7 +1322,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2ShortMap.Entry> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1237,7 +1352,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1259,7 +1374,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements ShortListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public short previousShort() {
|
||||
@ -1279,13 +1394,16 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
@ -1316,11 +1434,11 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1380,20 +1498,30 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -30,7 +30,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
|
||||
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.booleans.collections.AbstractBooleanCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanOrderedCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
import speiger.src.collections.booleans.functions.BooleanSupplier;
|
||||
import speiger.src.collections.booleans.functions.function.BooleanBooleanUnaryOperator;
|
||||
@ -73,7 +73,7 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
/** KeySet cache */
|
||||
protected transient ByteOrderedSet keySet;
|
||||
/** Values cache */
|
||||
protected transient BooleanCollection valuesC;
|
||||
protected transient BooleanOrderedCollection valuesC;
|
||||
|
||||
/** Amount of Elements stored in the HashMap */
|
||||
protected int size;
|
||||
@ -258,6 +258,10 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
@Override
|
||||
public boolean putAndMoveToLast(byte key, boolean value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean putFirst(byte key, boolean value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean putLast(byte key, boolean value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(byte key) { throw new UnsupportedOperationException(); }
|
||||
@ -362,6 +366,23 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry pollFirstEntry() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry pollLastEntry() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2BooleanMap.Entry> byte2BooleanEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -375,7 +396,7 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanCollection values() {
|
||||
public BooleanOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
}
|
||||
@ -524,24 +545,29 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
public boolean moveToLast(Byte2BooleanMap.Entry o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry first() {
|
||||
public Byte2BooleanMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstBooleanValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry last() {
|
||||
public Byte2BooleanMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastBooleanValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry pollFirst() { throw new UnsupportedOperationException(); }
|
||||
public Byte2BooleanMap.Entry removeFirst() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public Byte2BooleanMap.Entry pollLast() { throw new UnsupportedOperationException(); }
|
||||
public Byte2BooleanMap.Entry removeLast() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2BooleanMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2BooleanMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -551,7 +577,7 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2BooleanMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -766,7 +792,12 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -786,20 +817,20 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() { throw new UnsupportedOperationException(); }
|
||||
public byte removeFirstByte() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() { throw new UnsupportedOperationException(); }
|
||||
public byte removeLastByte() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(ByteConsumer action) {
|
||||
@ -926,30 +957,35 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractBooleanCollection {
|
||||
private class Values extends AbstractBooleanCollection implements BooleanOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(boolean e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(boolean e) { return containsValue(e); }
|
||||
|
||||
@Override
|
||||
public boolean add(boolean o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(boolean o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public BooleanIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public BooleanIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return ImmutableByte2BooleanOpenHashMap.this.size();
|
||||
}
|
||||
|
||||
public int size() { return ImmutableByte2BooleanOpenHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public BooleanOrderedCollection reversed() { return new AbstractBooleanCollection.ReverseBooleanOrderedCollection(this, this::reverseIterator); }
|
||||
private BooleanIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(boolean e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(boolean e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean getFirstBoolean() { return firstBooleanValue(); }
|
||||
@Override
|
||||
public boolean removeFirstBoolean() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean getLastBoolean() { return lastBooleanValue(); }
|
||||
@Override
|
||||
public boolean removeLastBoolean() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void forEach(BooleanConsumer action) {
|
||||
int index = firstIndex;
|
||||
@ -1078,7 +1114,7 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2BooleanMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1104,7 +1140,7 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2BooleanMap.Entry> {
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1131,7 +1167,7 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1153,7 +1189,7 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements BooleanListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public boolean previousBoolean() {
|
||||
@ -1174,13 +1210,16 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
@ -1211,11 +1250,11 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1232,20 +1271,30 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -26,7 +26,7 @@ import speiger.src.collections.bytes.utils.ByteArrays;
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.bytes.collections.AbstractByteCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteOrderedCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteIterator;
|
||||
import speiger.src.collections.bytes.functions.ByteSupplier;
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
@ -65,7 +65,7 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
/** KeySet cache */
|
||||
protected transient ByteOrderedSet keySet;
|
||||
/** Values cache */
|
||||
protected transient ByteCollection valuesC;
|
||||
protected transient ByteOrderedCollection valuesC;
|
||||
|
||||
/** Amount of Elements stored in the HashMap */
|
||||
protected int size;
|
||||
@ -254,6 +254,10 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
@Override
|
||||
public byte putAndMoveToLast(byte key, byte value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public byte putFirst(byte key, byte value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public byte putLast(byte key, byte value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(byte key) { throw new UnsupportedOperationException(); }
|
||||
@ -358,6 +362,23 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry pollFirstEntry() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public Byte2ByteMap.Entry pollLastEntry() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2ByteMap.Entry> byte2ByteEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -371,7 +392,7 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteCollection values() {
|
||||
public ByteOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
}
|
||||
@ -520,24 +541,29 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
public boolean moveToLast(Byte2ByteMap.Entry o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry first() {
|
||||
public Byte2ByteMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstByteValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry last() {
|
||||
public Byte2ByteMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastByteValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry pollFirst() { throw new UnsupportedOperationException(); }
|
||||
public Byte2ByteMap.Entry removeFirst() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public Byte2ByteMap.Entry pollLast() { throw new UnsupportedOperationException(); }
|
||||
public Byte2ByteMap.Entry removeLast() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ByteMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ByteMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -547,7 +573,7 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2ByteMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -762,7 +788,12 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -782,20 +813,20 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() { throw new UnsupportedOperationException(); }
|
||||
public byte removeFirstByte() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() { throw new UnsupportedOperationException(); }
|
||||
public byte removeLastByte() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(ByteConsumer action) {
|
||||
@ -922,30 +953,35 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractByteCollection {
|
||||
private class Values extends AbstractByteCollection implements ByteOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(byte e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(byte e) { return containsValue(e); }
|
||||
|
||||
@Override
|
||||
public boolean add(byte o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(byte o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ByteIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public ByteIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return ImmutableByte2ByteOpenHashMap.this.size();
|
||||
}
|
||||
|
||||
public int size() { return ImmutableByte2ByteOpenHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public ByteOrderedCollection reversed() { return new AbstractByteCollection.ReverseByteOrderedCollection(this, this::reverseIterator); }
|
||||
private ByteIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(byte e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(byte e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public byte getFirstByte() { return firstByteValue(); }
|
||||
@Override
|
||||
public byte removeFirstByte() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public byte getLastByte() { return lastByteValue(); }
|
||||
@Override
|
||||
public byte removeLastByte() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void forEach(ByteConsumer action) {
|
||||
int index = firstIndex;
|
||||
@ -1074,7 +1110,7 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2ByteMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1100,7 +1136,7 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2ByteMap.Entry> {
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1127,7 +1163,7 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1149,7 +1185,7 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements ByteListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public byte previousByte() {
|
||||
@ -1170,13 +1206,16 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
@ -1207,11 +1246,11 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1228,20 +1267,30 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -31,7 +31,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectCharConsumer;
|
||||
import speiger.src.collections.chars.functions.function.CharPredicate;
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.chars.collections.AbstractCharCollection;
|
||||
import speiger.src.collections.chars.collections.CharCollection;
|
||||
import speiger.src.collections.chars.collections.CharOrderedCollection;
|
||||
import speiger.src.collections.chars.collections.CharIterator;
|
||||
import speiger.src.collections.chars.functions.CharSupplier;
|
||||
import speiger.src.collections.chars.functions.function.CharCharUnaryOperator;
|
||||
@ -74,7 +74,7 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
/** KeySet cache */
|
||||
protected transient ByteOrderedSet keySet;
|
||||
/** Values cache */
|
||||
protected transient CharCollection valuesC;
|
||||
protected transient CharOrderedCollection valuesC;
|
||||
|
||||
/** Amount of Elements stored in the HashMap */
|
||||
protected int size;
|
||||
@ -263,6 +263,10 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
@Override
|
||||
public char putAndMoveToLast(byte key, char value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public char putFirst(byte key, char value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public char putLast(byte key, char value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(byte key) { throw new UnsupportedOperationException(); }
|
||||
@ -367,6 +371,23 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry pollFirstEntry() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public Byte2CharMap.Entry pollLastEntry() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2CharMap.Entry> byte2CharEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -380,7 +401,7 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharCollection values() {
|
||||
public CharOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
}
|
||||
@ -529,24 +550,29 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
public boolean moveToLast(Byte2CharMap.Entry o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry first() {
|
||||
public Byte2CharMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstCharValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry last() {
|
||||
public Byte2CharMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastCharValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry pollFirst() { throw new UnsupportedOperationException(); }
|
||||
public Byte2CharMap.Entry removeFirst() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public Byte2CharMap.Entry pollLast() { throw new UnsupportedOperationException(); }
|
||||
public Byte2CharMap.Entry removeLast() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2CharMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2CharMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -556,7 +582,7 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2CharMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -771,7 +797,12 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -791,20 +822,20 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() { throw new UnsupportedOperationException(); }
|
||||
public byte removeFirstByte() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() { throw new UnsupportedOperationException(); }
|
||||
public byte removeLastByte() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(ByteConsumer action) {
|
||||
@ -931,30 +962,35 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractCharCollection {
|
||||
private class Values extends AbstractCharCollection implements CharOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(char e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(char e) { return containsValue(e); }
|
||||
|
||||
@Override
|
||||
public boolean add(char o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(char o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public CharIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public CharIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return ImmutableByte2CharOpenHashMap.this.size();
|
||||
}
|
||||
|
||||
public int size() { return ImmutableByte2CharOpenHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public CharOrderedCollection reversed() { return new AbstractCharCollection.ReverseCharOrderedCollection(this, this::reverseIterator); }
|
||||
private CharIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(char e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(char e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public char getFirstChar() { return firstCharValue(); }
|
||||
@Override
|
||||
public char removeFirstChar() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public char getLastChar() { return lastCharValue(); }
|
||||
@Override
|
||||
public char removeLastChar() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void forEach(CharConsumer action) {
|
||||
int index = firstIndex;
|
||||
@ -1083,7 +1119,7 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2CharMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1109,7 +1145,7 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2CharMap.Entry> {
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1136,7 +1172,7 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1158,7 +1194,7 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements CharListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public char previousChar() {
|
||||
@ -1179,13 +1215,16 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
@ -1216,11 +1255,11 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1237,20 +1276,30 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -31,7 +31,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectDoubleConsumer;
|
||||
|
||||
import speiger.src.collections.bytes.sets.AbstractByteSet;
|
||||
import speiger.src.collections.doubles.collections.AbstractDoubleCollection;
|
||||
import speiger.src.collections.doubles.collections.DoubleCollection;
|
||||
import speiger.src.collections.doubles.collections.DoubleOrderedCollection;
|
||||
import speiger.src.collections.doubles.collections.DoubleIterator;
|
||||
import speiger.src.collections.doubles.functions.DoubleSupplier;
|
||||
import speiger.src.collections.doubles.functions.function.DoubleDoubleUnaryOperator;
|
||||
@ -74,7 +74,7 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
/** KeySet cache */
|
||||
protected transient ByteOrderedSet keySet;
|
||||
/** Values cache */
|
||||
protected transient DoubleCollection valuesC;
|
||||
protected transient DoubleOrderedCollection valuesC;
|
||||
|
||||
/** Amount of Elements stored in the HashMap */
|
||||
protected int size;
|
||||
@ -263,6 +263,10 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
@Override
|
||||
public double putAndMoveToLast(byte key, double value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public double putFirst(byte key, double value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public double putLast(byte key, double value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(byte key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(byte key) { throw new UnsupportedOperationException(); }
|
||||
@ -367,6 +371,23 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntry(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry pollFirstEntry() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry pollLastEntry() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<Byte2DoubleMap.Entry> byte2DoubleEntrySet() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -380,7 +401,7 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleCollection values() {
|
||||
public DoubleOrderedCollection values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
}
|
||||
@ -529,24 +550,29 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
public boolean moveToLast(Byte2DoubleMap.Entry o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry first() {
|
||||
public Byte2DoubleMap.Entry getFirst() {
|
||||
return new BasicEntry(firstByteKey(), firstDoubleValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry last() {
|
||||
public Byte2DoubleMap.Entry getLast() {
|
||||
return new BasicEntry(lastByteKey(), lastDoubleValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry pollFirst() { throw new UnsupportedOperationException(); }
|
||||
public Byte2DoubleMap.Entry removeFirst() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public Byte2DoubleMap.Entry pollLast() { throw new UnsupportedOperationException(); }
|
||||
public Byte2DoubleMap.Entry removeLast() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2DoubleMap.Entry> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2DoubleMap.Entry> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -556,7 +582,7 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<Byte2DoubleMap.Entry> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -771,7 +797,12 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
|
||||
@Override
|
||||
public ByteListIterator iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -791,20 +822,20 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public byte firstByte() {
|
||||
public byte getFirstByte() {
|
||||
return firstByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollFirstByte() { throw new UnsupportedOperationException(); }
|
||||
public byte removeFirstByte() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public byte lastByte() {
|
||||
public byte getLastByte() {
|
||||
return lastByteKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte pollLastByte() { throw new UnsupportedOperationException(); }
|
||||
public byte removeLastByte() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(ByteConsumer action) {
|
||||
@ -931,30 +962,35 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractDoubleCollection {
|
||||
private class Values extends AbstractDoubleCollection implements DoubleOrderedCollection {
|
||||
@Override
|
||||
public boolean contains(double e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(double e) { return containsValue(e); }
|
||||
|
||||
@Override
|
||||
public boolean add(double o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(double o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public DoubleIterator iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public DoubleIterator iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return ImmutableByte2DoubleOpenHashMap.this.size();
|
||||
}
|
||||
|
||||
public int size() { return ImmutableByte2DoubleOpenHashMap.this.size(); }
|
||||
@Override
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public DoubleOrderedCollection reversed() { return new AbstractDoubleCollection.ReverseDoubleOrderedCollection(this, this::reverseIterator); }
|
||||
private DoubleIterator reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(double e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(double e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public double getFirstDouble() { return firstDoubleValue(); }
|
||||
@Override
|
||||
public double removeFirstDouble() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public double getLastDouble() { return lastDoubleValue(); }
|
||||
@Override
|
||||
public double removeLastDouble() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void forEach(DoubleConsumer action) {
|
||||
int index = firstIndex;
|
||||
@ -1083,7 +1119,7 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<Byte2DoubleMap.Entry> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1109,7 +1145,7 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<Byte2DoubleMap.Entry> {
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1136,7 +1172,7 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
|
||||
private class KeyIterator extends MapIterator implements ByteListIterator {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(byte from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1158,7 +1194,7 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements DoubleListIterator {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public double previousDouble() {
|
||||
@ -1179,13 +1215,16 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(byte from) {
|
||||
@ -1216,11 +1255,11 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1237,20 +1276,30 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user