Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defaultTasks("mvgCorrector", "test", "publish", "mvgTagger")
plugins {
`java-library`
`maven-publish`
id("org.modelingvalue.gradle.mvgplugin") version "2.3.15"
id("org.modelingvalue.gradle.mvgplugin") version "2.3.21"
}

dependencies {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
# suppress inspection "UnusedProperty" for whole file
group = org.modelingvalue
artifact = immutable-collections
version = 5.0.0
version_java = 17
version = 6.0.0
version_java = 21
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
15 changes: 7 additions & 8 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 12 additions & 22 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,3 @@ rootProject.name = "immutable-collections"

include("generator")

pluginManagement {
repositories {
maven { url = uri("https://modelingvaluegroup.github.io/gradlePlugins/") }
gradlePluginPortal()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.stream.Stream;

import org.modelingvalue.collections.Entry;
import org.modelingvalue.collections.util.Age;
import org.modelingvalue.collections.util.IdentityRank;
import org.modelingvalue.collections.util.Internable;
import org.modelingvalue.collections.util.StringUtil;

Expand Down Expand Up @@ -73,7 +73,7 @@ public boolean equals(Object obj) {
return true;
} else if (value == null || !value.equals(other.value)) {
return false;
} else if (Age.age(value) > Age.age(other.value)) {
} else if (IdentityRank.rank(value) < IdentityRank.rank(other.value)) {
other.value = value;
return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,13 @@ public boolean equals(Object obj) {
if (!this.outgoing.equals(other.outgoing))
return false;

if (Age.age(this.outgoing) > Age.age(other.outgoing)) {
if (IdentityRank.rank(this.outgoing) < IdentityRank.rank(other.outgoing)) {
other.outgoing = this.outgoing;
} else {
this.outgoing = other.outgoing;
}

if (Age.age(this.incoming) > Age.age(other.incoming)) {
if (IdentityRank.rank(this.incoming) < IdentityRank.rank(other.incoming)) {
other.incoming = this.incoming;
} else {
this.incoming = other.incoming;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.modelingvalue.collections.ContainingCollection;
import org.modelingvalue.collections.Set;
import org.modelingvalue.collections.StreamCollection;
import org.modelingvalue.collections.util.Age;
import org.modelingvalue.collections.util.IdentityRank;
import org.modelingvalue.collections.util.Concurrent;
import org.modelingvalue.collections.util.ContextThread;
import org.modelingvalue.collections.util.Reusable;
Expand Down Expand Up @@ -189,7 +189,7 @@ protected boolean equalsWithStop(Object obj, boolean[] stop) {
} else if (values[ia] == other.values[ib]) {
continue outer;
} else if (Objects.equals(values[ia], other.values[ib])) {
if (Age.age(values[ia]) > Age.age(other.values[ib])) {
if (IdentityRank.rank(values[ia]) < IdentityRank.rank(other.values[ib])) {
other.values[ib] = values[ia];
} else {
values[ia] = other.values[ib];
Expand All @@ -210,7 +210,7 @@ protected boolean equalsWithStop(Object obj, boolean[] stop) {
} else if (!TreeCollectionImpl.equalsWithStop(values[i], other.values[i], stop)) {
stop[0] = true;
return false;
} else if (Age.age(values[i]) > Age.age(other.values[i])) {
} else if (IdentityRank.rank(values[i]) < IdentityRank.rank(other.values[i])) {
other.values[i] = values[i];
return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean equals(Object obj) {
return true;
} else if (!equalsWithStop(value, other.value, new boolean[1])) {
return false;
} else if (Age.age(value) > Age.age(other.value)) {
} else if (IdentityRank.rank(value) < IdentityRank.rank(other.value)) {
other.value = value;
return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ public List<T> getAndSet(UnaryOperator<List<T>> oper) {
return pre;
}

@Override
public MutableList<T> subList(int fromIndex, int toIndex) {
return of(get().sublist(toIndex, toIndex));
}

}

private static class ConcurrentImpl<T> extends MutableList<T> {
Expand All @@ -284,10 +289,12 @@ public List<T> get() {
public boolean set(UnaryOperator<List<T>> oper) {
List<T> prev = ref.get(), next = null;
for (boolean haveNext = false;;) {
if (!haveNext)
if (!haveNext) {
next = oper.apply(prev);
if (ref.weakCompareAndSetVolatile(prev, next))
}
if (ref.weakCompareAndSetVolatile(prev, next)) {
return prev != next;
}
haveNext = (prev == (prev = ref.get()));
}
}
Expand All @@ -297,6 +304,11 @@ public List<T> getAndSet(UnaryOperator<List<T>> oper) {
return ref.getAndUpdate(oper);
}

@Override
public MutableList<T> subList(int fromIndex, int toIndex) {
return concurrent(get().sublist(toIndex, toIndex));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.function.Consumer;

import org.modelingvalue.collections.struct.Struct;
import org.modelingvalue.collections.util.Age;
import org.modelingvalue.collections.util.IdentityRank;
import org.modelingvalue.collections.util.Internable;
import org.modelingvalue.collections.util.StringUtil;

Expand Down Expand Up @@ -63,7 +63,7 @@ public boolean equals(Object obj) {
return true;
} else if (!Arrays.equals(data, other.data)) {
return false;
} else if (Age.age(data) > Age.age(other.data)) {
} else if (IdentityRank.rank(data) < IdentityRank.rank(other.data)) {
other.data = data;
return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public boolean equals(Object obj) {
} else if (!Arrays.equals(array, other.array)) {
return false;
} else {
if (Age.age(array) > Age.age(other.array)) {
if (IdentityRank.rank(array) < IdentityRank.rank(other.array)) {
other.array = array;
} else {
array = other.array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,13 @@

package org.modelingvalue.collections.util;

import sun.misc.Unsafe;
public final class IdentityRank {

import java.lang.reflect.Field;

public final class Age {

private static Unsafe UNSAFE = null;

static {
try {
Field declaredField = Unsafe.class.getDeclaredField("theUnsafe");
declaredField.setAccessible(true);
UNSAFE = (Unsafe) declaredField.get(null);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}

public static int age(Object object) {
return (UNSAFE.getByte(object, 0L) & 0x78) >> 3;
public static int rank(Object object) {
return System.identityHashCode(object);
}

private Age() {
private IdentityRank() {
}

}
Loading