Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(WIP): add IntMapByDynamicHash #2294

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
private static final int NULL_VALUE = Integer.MIN_VALUE;

private static final AtomicReferenceFieldUpdater<IntMapByDynamicHash, Entry[]>
TABLE_UPDATER =
AtomicReferenceFieldUpdater.newUpdater(IntMapByDynamicHash.class, Entry[].class,

Check warning on line 44 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L43-L44

Added lines #L43 - L44 were not covered by tests
"table");

private volatile Entry[] table;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect a primitive type array here

Expand All @@ -51,10 +51,10 @@
*/
private int[] partitionedSize;

private static final Entry RESIZING = new Entry(NULL_VALUE, NULL_VALUE, 1);
private static final Entry RESIZED = new Entry(NULL_VALUE, NULL_VALUE, 2);

Check warning on line 55 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L54-L55

Added lines #L54 - L55 were not covered by tests

private static final Entry RESIZE_SENTINEL = new Entry(NULL_VALUE, NULL_VALUE, 3);

Check warning on line 57 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L57

Added line #L57 was not covered by tests

/**
* must be 2^n - 1
Expand All @@ -64,13 +64,13 @@

/* ---------------- Table element access -------------- */
private static Object tableAt(Object[] array, int index) {
return UNSAFE.getObjectVolatile(array,

Check warning on line 67 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L67

Added line #L67 was not covered by tests
((long) index << ENTRY_ARRAY_SHIFT) +
ENTRY_ARRAY_BASE);
}

private static boolean casTableAt(Object[] array, int index, Object expected, Object newValue) {
return UNSAFE.compareAndSwapObject(

Check warning on line 73 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L73

Added line #L73 was not covered by tests
array,
((long) index << ENTRY_ARRAY_SHIFT) + ENTRY_ARRAY_BASE,
expected,
Expand All @@ -78,17 +78,17 @@
}

private static void setTableAt(Object[] array, int index, Object newValue) {
UNSAFE.putObjectVolatile(array, ((long) index << ENTRY_ARRAY_SHIFT) + ENTRY_ARRAY_BASE,

Check warning on line 81 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L81

Added line #L81 was not covered by tests
newValue);
}

Check warning on line 83 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L83

Added line #L83 was not covered by tests

private static int tableSizeFor(int c) {
int n = c - 1;
n |= n >>> 1;
n |= n >>> 2;
n |= n >>> 4;
n |= n >>> 8;
n |= n >>> 16;

Check warning on line 91 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L86-L91

Added lines #L86 - L91 were not covered by tests
return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
}

Expand All @@ -96,47 +96,47 @@
private volatile int size; // updated via atomic field updater
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improve the style


public IntMapByDynamicHash() {
this(DEFAULT_INITIAL_CAPACITY);
}

Check warning on line 100 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L99-L100

Added lines #L99 - L100 were not covered by tests

public IntMapByDynamicHash(int initialCapacity) {

Check warning on line 102 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L102

Added line #L102 was not covered by tests
if (initialCapacity < 0) {
throw new IllegalArgumentException("Illegal Initial Capacity: " + initialCapacity);

Check warning on line 104 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L104

Added line #L104 was not covered by tests
}
if (initialCapacity > MAXIMUM_CAPACITY) {
initialCapacity = MAXIMUM_CAPACITY;

Check warning on line 107 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L107

Added line #L107 was not covered by tests
}
long size = (long) (1.0 + (long) initialCapacity / LOAD_FACTOR);

Check warning on line 109 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L109

Added line #L109 was not covered by tests
int cap = (size >= (long) MAXIMUM_CAPACITY) ?
MAXIMUM_CAPACITY : tableSizeFor((int) size);

Check warning on line 111 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L111

Added line #L111 was not covered by tests
if (cap >= PARTITIONED_SIZE_THRESHOLD) {
/*
we want 7 extra slots and 64 bytes for each
slot. int is 4 bytes, so 64 bytes is 16 ints.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improve the style

this.partitionedSize =

Check warning on line 117 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L117

Added line #L117 was not covered by tests
new int[SIZE_BUCKETS * 16];
}
// The end index is for resizeContainer
this.table = new Entry[cap + 1];
}

Check warning on line 122 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L121-L122

Added lines #L121 - L122 were not covered by tests

@Override
public boolean put(int key, int value) {
int hash = this.hash(key);
Entry[] currentArray = this.table;
Entry o = (Entry) IntMapByDynamicHash.tableAt(currentArray, hash);

Check warning on line 128 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L126-L128

Added lines #L126 - L128 were not covered by tests
if (o == null) {
Entry newEntry = new Entry(key, value);
this.addToSize(1);

Check warning on line 131 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L130-L131

Added lines #L130 - L131 were not covered by tests
if (IntMapByDynamicHash.casTableAt(currentArray, hash, null, newEntry)) {
return true;

Check warning on line 133 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L133

Added line #L133 was not covered by tests
}
this.addToSize(-1);

Check warning on line 135 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L135

Added line #L135 was not covered by tests
}

this.slowPut(key, value, currentArray);
return true;

Check warning on line 139 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L138-L139

Added lines #L138 - L139 were not covered by tests
}

private int slowPut(int key, int value, Entry[] currentTable) {
Expand All @@ -145,107 +145,107 @@
Entry o;

while (true) {
length = currentTable.length;
index = this.hash(key, length);
o = (Entry) IntMapByDynamicHash.tableAt(currentTable, index);

Check warning on line 150 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L148-L150

Added lines #L148 - L150 were not covered by tests

if (o == RESIZED || o == RESIZING) {
currentTable = this.helpWithResizeWhileCurrentIndex(currentTable, index);

Check warning on line 153 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L153

Added line #L153 was not covered by tests
} else {
Entry e = o;
boolean found = false;

Check warning on line 156 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L155-L156

Added lines #L155 - L156 were not covered by tests

// Search for the key in the chain
while (e != null) {
int candidate = e.getKey();

Check warning on line 160 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L160

Added line #L160 was not covered by tests
if (candidate == key) {
found = true;
break;

Check warning on line 163 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L162-L163

Added lines #L162 - L163 were not covered by tests
}
e = e.getNext();
}

Check warning on line 166 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L165-L166

Added lines #L165 - L166 were not covered by tests

if (found) {
int oldVal = e.getValue();

Check warning on line 169 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L169

Added line #L169 was not covered by tests
// Key found, replace the entry
Entry newEntry =
new Entry(key, value, this.createReplacementChainForRemoval(o, e));

Check warning on line 172 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L171-L172

Added lines #L171 - L172 were not covered by tests
if (IntMapByDynamicHash.casTableAt(currentTable, index, o, newEntry)) {
return oldVal;

Check warning on line 174 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L174

Added line #L174 was not covered by tests
}
} else {

Check warning on line 176 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L176

Added line #L176 was not covered by tests
// Key not found, add a new entry
Entry newEntry = new Entry(key, value, o);

Check warning on line 178 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L178

Added line #L178 was not covered by tests
if (IntMapByDynamicHash.casTableAt(currentTable, index, o, newEntry)) {
this.incrementSizeAndPossiblyResize(currentTable, length, o);
return NULL_VALUE;

Check warning on line 181 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L180-L181

Added lines #L180 - L181 were not covered by tests
}
}
}

Check warning on line 184 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L184

Added line #L184 was not covered by tests
}
}

@Override
public int get(int key) {
int hash = this.hash(key);
Entry[] currentArray = this.table;
Entry o = (Entry) IntMapByDynamicHash.tableAt(currentArray, hash);

Check warning on line 192 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L190-L192

Added lines #L190 - L192 were not covered by tests
if (o == RESIZED || o == RESIZING) {
return this.slowGet(key, currentArray);

Check warning on line 194 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L194

Added line #L194 was not covered by tests
}
for (Entry e = o; e != null; e = e.getNext()) {
int k;
if ((k = e.getKey()) == key || key == k) {
return e.value;

Check warning on line 199 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L199

Added line #L199 was not covered by tests
}
}
return NULL_VALUE;

Check warning on line 202 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L202

Added line #L202 was not covered by tests
}

private int slowGet(int key, Entry[] currentArray) {
while (true) {
int length = currentArray.length;
int hash = this.hash(key, length);
Entry o = (Entry) IntMapByDynamicHash.tableAt(currentArray, hash);

Check warning on line 209 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L207-L209

Added lines #L207 - L209 were not covered by tests
if (o == RESIZED || o == RESIZING) {
currentArray = this.helpWithResizeWhileCurrentIndex(currentArray, hash);

Check warning on line 211 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L211

Added line #L211 was not covered by tests
} else {
Entry e = o;

Check warning on line 213 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L213

Added line #L213 was not covered by tests
while (e != null) {
int candidate = e.getKey();

Check warning on line 215 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L215

Added line #L215 was not covered by tests
if (candidate == key) {
return e.getValue();

Check warning on line 217 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L217

Added line #L217 was not covered by tests
}
e = e.getNext();
}
return NULL_VALUE;

Check warning on line 221 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L219-L221

Added lines #L219 - L221 were not covered by tests
}
}

Check warning on line 223 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L223

Added line #L223 was not covered by tests
}

@Override
public boolean remove(int key) {
int hash = this.hash(key);
Entry[] currentTable = this.table;
Entry o = (Entry) IntMapByDynamicHash.tableAt(currentTable, hash);

Check warning on line 230 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L228-L230

Added lines #L228 - L230 were not covered by tests
if (o == RESIZED || o == RESIZING) {
return this.slowRemove(key, currentTable) != null;
}

Entry e = o;

Check warning on line 235 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L235

Added line #L235 was not covered by tests
while (e != null) {
int candidate = e.getKey();

Check warning on line 237 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L237

Added line #L237 was not covered by tests
if (candidate == key) {
Entry replacement = this.createReplacementChainForRemoval(o, e);

Check warning on line 239 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L239

Added line #L239 was not covered by tests
if (IntMapByDynamicHash.casTableAt(currentTable, hash, o, replacement)) {
this.addToSize(-1);
return true;

Check warning on line 242 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L241-L242

Added lines #L241 - L242 were not covered by tests
}
return this.slowRemove(key, currentTable) != null;
}
e = e.getNext();
}
return false;

Check warning on line 248 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L246-L248

Added lines #L246 - L248 were not covered by tests
}

private Entry slowRemove(int key, Entry[] currentTable) {
Expand All @@ -254,35 +254,35 @@
Entry o;

while (true) {
length = currentTable.length;
index = this.hash(key, length);
o = (Entry) IntMapByDynamicHash.tableAt(currentTable, index);

Check warning on line 259 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L257-L259

Added lines #L257 - L259 were not covered by tests
if (o == RESIZED || o == RESIZING) {
currentTable = this.helpWithResizeWhileCurrentIndex(currentTable, index);

Check warning on line 261 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L261

Added line #L261 was not covered by tests
} else {
Entry e = o;
Entry prev = null;

Check warning on line 264 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L263-L264

Added lines #L263 - L264 were not covered by tests

while (e != null) {
int candidate = e.getKey();

Check warning on line 267 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L267

Added line #L267 was not covered by tests
if (candidate == key) {
Entry replacement = this.createReplacementChainForRemoval(o, e);

Check warning on line 269 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L269

Added line #L269 was not covered by tests
if (IntMapByDynamicHash.casTableAt(currentTable, index, o, replacement)) {
this.addToSize(-1);
return e;

Check warning on line 272 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L271-L272

Added lines #L271 - L272 were not covered by tests
}
// Key found, but CAS failed, restart the loop
break;
}
prev = e;
e = e.getNext();
}

Check warning on line 279 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L277-L279

Added lines #L277 - L279 were not covered by tests

if (prev != null) {
// Key not found
return null;

Check warning on line 283 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L283

Added line #L283 was not covered by tests
}
}

Check warning on line 285 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L285

Added line #L285 was not covered by tests
}
}

Expand All @@ -294,234 +294,234 @@
@Override
public IntIterator keys() {
// TODO impl
return null;

Check warning on line 297 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L297

Added line #L297 was not covered by tests
}

@Override
public IntIterator values() {
// TODO impl
return null;

Check warning on line 303 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L303

Added line #L303 was not covered by tests
}

@Override
public void clear() {
Entry[] currentArray = this.table;

Check warning on line 308 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L308

Added line #L308 was not covered by tests
ResizeContainer resizeContainer;
do {
resizeContainer = null;

Check warning on line 311 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L311

Added line #L311 was not covered by tests
for (int i = 0; i < currentArray.length - 1; i++) {
Entry o = (Entry) IntMapByDynamicHash.tableAt(currentArray, i);

Check warning on line 313 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L313

Added line #L313 was not covered by tests
if (o == RESIZED || o == RESIZING) {
resizeContainer = (ResizeContainer) IntMapByDynamicHash.tableAt(currentArray,

Check warning on line 315 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L315

Added line #L315 was not covered by tests
currentArray.length -
1);
} else if (o != null) {
Entry e = o;

Check warning on line 319 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L319

Added line #L319 was not covered by tests
if (IntMapByDynamicHash.casTableAt(currentArray, i, o, null)) {
int removedEntries = 0;

Check warning on line 321 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L321

Added line #L321 was not covered by tests
while (e != null) {
removedEntries++;
e = e.getNext();

Check warning on line 324 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L323-L324

Added lines #L323 - L324 were not covered by tests
}
this.addToSize(-removedEntries);

Check warning on line 326 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L326

Added line #L326 was not covered by tests
}
}
}
if (resizeContainer != null) {
if (resizeContainer.isNotDone()) {
this.helpWithResize(currentArray);
resizeContainer.waitForAllResizers();

Check warning on line 333 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L332-L333

Added lines #L332 - L333 were not covered by tests
}
currentArray = resizeContainer.nextArray;

Check warning on line 335 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L335

Added line #L335 was not covered by tests
}
} while (resizeContainer != null);
}

Check warning on line 338 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L338

Added line #L338 was not covered by tests

@Override
public int size() {
int localSize = this.size;

Check warning on line 342 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L342

Added line #L342 was not covered by tests
if (this.partitionedSize != null) {
for (int i = 0; i < SIZE_BUCKETS; i++) {
localSize += this.partitionedSize[i << 4];

Check warning on line 345 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L345

Added line #L345 was not covered by tests
}
}
return localSize;

Check warning on line 348 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L348

Added line #L348 was not covered by tests
}

@Override
public boolean concurrent() {
return true;

Check warning on line 353 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L353

Added line #L353 was not covered by tests
}

private int hash(int key) {
return key & (table.length - 2);

Check warning on line 357 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L357

Added line #L357 was not covered by tests
}

private int hash(int key, int length) {
return key & (length - 2);

Check warning on line 361 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L361

Added line #L361 was not covered by tests
}

private Entry getEntry(int key) {
Entry[] currentArray = this.table;

Check warning on line 365 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L365

Added line #L365 was not covered by tests
while (true) {
int length = currentArray.length;
int index = this.hash(key, length);
Entry o = (Entry) IntMapByDynamicHash.tableAt(currentArray, index);

Check warning on line 369 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L367-L369

Added lines #L367 - L369 were not covered by tests
if (o == RESIZED || o == RESIZING) {
currentArray = this.helpWithResizeWhileCurrentIndex(currentArray, index);

Check warning on line 371 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L371

Added line #L371 was not covered by tests
} else {
Entry e = o;

Check warning on line 373 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L373

Added line #L373 was not covered by tests
while (e != null) {
int candidate = e.getKey();

Check warning on line 375 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L375

Added line #L375 was not covered by tests
if (candidate == key) {
return e;

Check warning on line 377 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L377

Added line #L377 was not covered by tests
}
e = e.getNext();
}
return null;

Check warning on line 381 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L379-L381

Added lines #L379 - L381 were not covered by tests
}
}

Check warning on line 383 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L383

Added line #L383 was not covered by tests
}

private void addToSize(int value) {
if (this.partitionedSize != null) {
if (this.incrementPartitionedSize(value)) {
return;

Check warning on line 389 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L389

Added line #L389 was not covered by tests
}
}
this.incrementLocalSize(value);
}

Check warning on line 393 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L392-L393

Added lines #L392 - L393 were not covered by tests

private boolean incrementPartitionedSize(int value) {
int h = (int) Thread.currentThread().getId();
h ^= (h >>> 18) ^ (h >>> 12);
h = (h ^ (h >>> 10)) & SIZE_BUCKETS;

Check warning on line 398 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L396-L398

Added lines #L396 - L398 were not covered by tests
if (h != 0) {
h = (h - 1) << 4;
long address = ((long) h << INT_ARRAY_SHIFT) + INT_ARRAY_BASE;

Check warning on line 401 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L400-L401

Added lines #L400 - L401 were not covered by tests
while (true) {
int localSize = UNSAFE.getIntVolatile(this.partitionedSize, address);

Check warning on line 403 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L403

Added line #L403 was not covered by tests
if (UNSAFE.compareAndSwapInt(this.partitionedSize, address, localSize,
localSize + value)) {
return true;

Check warning on line 406 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L406

Added line #L406 was not covered by tests
}
}

Check warning on line 408 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L408

Added line #L408 was not covered by tests
}
return false;

Check warning on line 410 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L410

Added line #L410 was not covered by tests
}

private void incrementLocalSize(int value) {
while (true) {
int localSize = this.size;

Check warning on line 415 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L415

Added line #L415 was not covered by tests
if (UNSAFE.compareAndSwapInt(this, SIZE_OFFSET, localSize, localSize + value)) {
break;

Check warning on line 417 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L417

Added line #L417 was not covered by tests
}
}
}

Check warning on line 420 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L419-L420

Added lines #L419 - L420 were not covered by tests

private Entry createReplacementChainForRemoval(Entry original,
Entry toRemove) {
if (original == toRemove) {
return original.getNext();

Check warning on line 425 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L425

Added line #L425 was not covered by tests
}
Entry replacement = null;
Entry e = original;

Check warning on line 428 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L427-L428

Added lines #L427 - L428 were not covered by tests
while (e != null) {
if (e != toRemove) {
replacement = new Entry(e.getKey(), e.getValue(), replacement);

Check warning on line 431 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L431

Added line #L431 was not covered by tests
}
e = e.getNext();

Check warning on line 433 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L433

Added line #L433 was not covered by tests
}
return replacement;

Check warning on line 435 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L435

Added line #L435 was not covered by tests
}

private void incrementSizeAndPossiblyResize(Entry[] currentArray, int length, Entry prev) {
this.addToSize(1);

Check warning on line 439 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L439

Added line #L439 was not covered by tests
if (prev != null) {
int localSize = this.size();
int threshold = (int) (length * LOAD_FACTOR); // threshold = length * 0.75

Check warning on line 442 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L441-L442

Added lines #L441 - L442 were not covered by tests
if (localSize + 1 > threshold) {
this.resize(currentArray);

Check warning on line 444 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L444

Added line #L444 was not covered by tests
}
}
}

Check warning on line 447 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L447

Added line #L447 was not covered by tests

private Entry[] helpWithResizeWhileCurrentIndex(Entry[] currentArray, int index) {
Entry[] newArray = this.helpWithResize(currentArray);
int helpCount = 0;

Check warning on line 451 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L450-L451

Added lines #L450 - L451 were not covered by tests
while (IntMapByDynamicHash.tableAt(currentArray, index) != RESIZED) {
helpCount++;
newArray = this.helpWithResize(currentArray);

Check warning on line 454 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L453-L454

Added lines #L453 - L454 were not covered by tests
if ((helpCount & 7) == 0) {
Thread.yield();

Check warning on line 456 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L456

Added line #L456 was not covered by tests
}
}
return newArray;

Check warning on line 459 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L459

Added line #L459 was not covered by tests
}

private void resize(Entry[] oldTable) {
this.resize(oldTable, (oldTable.length - 1 << 1) + 1);
}

Check warning on line 464 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L463-L464

Added lines #L463 - L464 were not covered by tests

// newSize must be a power of 2 + 1
@SuppressWarnings("JLM_JSR166_UTILCONCURRENT_MONITORENTER")
private void resize(Entry[] oldTable, int newSize) {
int oldCapacity = oldTable.length;
int end = oldCapacity - 1;
Entry last = (Entry) IntMapByDynamicHash.tableAt(oldTable, end);

Check warning on line 471 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L469-L471

Added lines #L469 - L471 were not covered by tests
if (this.size() < end && last == RESIZE_SENTINEL) {
return;

Check warning on line 473 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L473

Added line #L473 was not covered by tests
}
if (oldCapacity >= MAXIMUM_CAPACITY) {
throw new RuntimeException("max capacity of map exceeded");

Check warning on line 476 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L476

Added line #L476 was not covered by tests
}
ResizeContainer resizeContainer = null;

Check warning on line 478 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L478

Added line #L478 was not covered by tests
// This ownResize records whether current thread need to perform the expansion operation of
// the map by itself
boolean ownResize = false;

Check warning on line 481 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L481

Added line #L481 was not covered by tests
if (last == null || last == RESIZE_SENTINEL) {
// allocating a new array is too expensive to make this an atomic operation
synchronized (oldTable) {

Check warning on line 484 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L484

Added line #L484 was not covered by tests
if (IntMapByDynamicHash.tableAt(oldTable, end) == null) {
IntMapByDynamicHash.setTableAt(oldTable, end, RESIZE_SENTINEL);

Check warning on line 486 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L486

Added line #L486 was not covered by tests
if (this.partitionedSize == null && newSize >= PARTITIONED_SIZE_THRESHOLD) {
this.partitionedSize = new int[SIZE_BUCKETS * 16];

Check warning on line 488 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L488

Added line #L488 was not covered by tests
}
resizeContainer = new ResizeContainer(new Entry[newSize], oldTable.length - 1);
IntMapByDynamicHash.setTableAt(oldTable, end, resizeContainer);
ownResize = true;

Check warning on line 492 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L490-L492

Added lines #L490 - L492 were not covered by tests
}
}

Check warning on line 494 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L494

Added line #L494 was not covered by tests
}
if (ownResize) {
this.transfer(oldTable, resizeContainer);

Check warning on line 497 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L497

Added line #L497 was not covered by tests

Entry[] src = this.table;

Check warning on line 499 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L499

Added line #L499 was not covered by tests
while (!TABLE_UPDATER.compareAndSet(this, oldTable, resizeContainer.nextArray)) {
/*
we're in a double resize situation; we'll have to go help until it's our turn
to set the table
*/
if (src != oldTable) {
this.helpWithResize(src);

Check warning on line 506 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L506

Added line #L506 was not covered by tests
}
}
} else {
this.helpWithResize(oldTable);

Check warning on line 510 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L509-L510

Added lines #L509 - L510 were not covered by tests
}
}

Check warning on line 512 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L512

Added line #L512 was not covered by tests

/**
* Transfer all entries from src to dest tables
*/
private void transfer(Entry[] src, ResizeContainer resizeContainer) {
Entry[] dest = resizeContainer.nextArray;

Check warning on line 518 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L518

Added line #L518 was not covered by tests

for (int j = 0; j < src.length - 1; ) {
Entry o = (Entry) IntMapByDynamicHash.tableAt(src, j);

Check warning on line 521 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L521

Added line #L521 was not covered by tests
if (o == null) {
if (IntMapByDynamicHash.casTableAt(src, j, null, RESIZED)) {
j++;

Check warning on line 524 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L524

Added line #L524 was not covered by tests
}
} else if (o == RESIZED || o == RESIZING) {
/*
Expand All @@ -529,178 +529,178 @@
this location to the new array. This means that the elements in the current
position have already been processed and do not need to be migrated again.
*/
j = (j & ~(ResizeContainer.QUEUE_INCREMENT - 1)) + ResizeContainer.QUEUE_INCREMENT;

Check warning on line 532 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L532

Added line #L532 was not covered by tests
/*
When there is only one thread for expansion, there is no concurrency issue
and there is no need to wait.
*/
if (resizeContainer.resizers.get() == 1) {
break;

Check warning on line 538 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L538

Added line #L538 was not covered by tests
}
} else {
Entry e = o;

Check warning on line 541 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L541

Added line #L541 was not covered by tests
if (IntMapByDynamicHash.casTableAt(src, j, o, RESIZING)) {
while (e != null) {
this.unconditionalCopy(dest, e);
e = e.getNext();

Check warning on line 545 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L544-L545

Added lines #L544 - L545 were not covered by tests
}
IntMapByDynamicHash.setTableAt(src, j, RESIZED);
j++;

Check warning on line 548 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L547-L548

Added lines #L547 - L548 were not covered by tests
}
}
}
resizeContainer.decrementResizerAndNotify();
resizeContainer.waitForAllResizers();
}

Check warning on line 554 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L551-L554

Added lines #L551 - L554 were not covered by tests

/**
* Enable the current thread to participate in the expansion
*/
private Entry[] helpWithResize(Entry[] currentArray) {
ResizeContainer resizeContainer =
(ResizeContainer) IntMapByDynamicHash.tableAt(currentArray,

Check warning on line 561 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L560-L561

Added lines #L560 - L561 were not covered by tests
currentArray.length - 1);
Entry[] newTable = resizeContainer.nextArray;

Check warning on line 563 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L563

Added line #L563 was not covered by tests
if (resizeContainer.getQueuePosition() > ResizeContainer.QUEUE_INCREMENT) {
resizeContainer.incrementResizer();
this.reverseTransfer(currentArray, resizeContainer);
resizeContainer.decrementResizerAndNotify();

Check warning on line 567 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L565-L567

Added lines #L565 - L567 were not covered by tests
}
return newTable;

Check warning on line 569 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L569

Added line #L569 was not covered by tests
}

private void reverseTransfer(Entry[] src, ResizeContainer resizeContainer) {
Entry[] dest = resizeContainer.nextArray;

Check warning on line 573 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L573

Added line #L573 was not covered by tests
while (resizeContainer.getQueuePosition() > 0) {
int start = resizeContainer.subtractAndGetQueuePosition();
int end = start + ResizeContainer.QUEUE_INCREMENT;

Check warning on line 576 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L575-L576

Added lines #L575 - L576 were not covered by tests
if (end > 0) {
if (start < 0) {
start = 0;

Check warning on line 579 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L579

Added line #L579 was not covered by tests
}
for (int j = end - 1; j >= start; ) {
Entry o = (Entry) IntMapByDynamicHash.tableAt(src, j);

Check warning on line 582 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L582

Added line #L582 was not covered by tests
if (o == null) {
if (IntMapByDynamicHash.casTableAt(src, j, null, RESIZED)) {
j--;

Check warning on line 585 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L585

Added line #L585 was not covered by tests
}
} else if (o == RESIZED || o == RESIZING) {
resizeContainer.zeroOutQueuePosition();
return;

Check warning on line 589 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L588-L589

Added lines #L588 - L589 were not covered by tests
} else {
Entry e = o;

Check warning on line 591 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L591

Added line #L591 was not covered by tests
if (IntMapByDynamicHash.casTableAt(src, j, o, RESIZING)) {
while (e != null) {
this.unconditionalCopy(dest, e);
e = e.getNext();

Check warning on line 595 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L594-L595

Added lines #L594 - L595 were not covered by tests
}
IntMapByDynamicHash.setTableAt(src, j, RESIZED);
j--;

Check warning on line 598 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L597-L598

Added lines #L597 - L598 were not covered by tests
}
}
}

Check warning on line 601 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L601

Added line #L601 was not covered by tests
}
}
}

Check warning on line 604 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L603-L604

Added lines #L603 - L604 were not covered by tests

private void unconditionalCopy(Entry[] dest, Entry toCopyEntry) {
Entry[] currentArray = dest;

Check warning on line 607 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L607

Added line #L607 was not covered by tests
while (true) {
int length = currentArray.length;
int index = this.hash(toCopyEntry.getKey(), length);
Entry o = (Entry) IntMapByDynamicHash.tableAt(currentArray, index);

Check warning on line 611 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L609-L611

Added lines #L609 - L611 were not covered by tests
if (o == RESIZED || o == RESIZING) {
currentArray = ((ResizeContainer) IntMapByDynamicHash.tableAt(currentArray,

Check warning on line 613 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L613

Added line #L613 was not covered by tests
length -
1)).nextArray;

Check warning on line 615 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L615

Added line #L615 was not covered by tests
} else {
Entry newEntry;
if (o == null) {
if (toCopyEntry.getNext() == null) {
newEntry = toCopyEntry; // no need to duplicate

Check warning on line 620 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L620

Added line #L620 was not covered by tests
} else {
newEntry = new Entry(toCopyEntry.getKey(), toCopyEntry.getValue());

Check warning on line 622 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L622

Added line #L622 was not covered by tests
}
} else {
newEntry =
new Entry(toCopyEntry.getKey(), toCopyEntry.getValue(), o);

Check warning on line 626 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L625-L626

Added lines #L625 - L626 were not covered by tests
}
if (IntMapByDynamicHash.casTableAt(currentArray, index, o, newEntry)) {
return;

Check warning on line 629 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L629

Added line #L629 was not covered by tests
}
}
}

Check warning on line 632 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L632

Added line #L632 was not covered by tests
}

private static final class ResizeContainer extends Entry {
private static final int QUEUE_INCREMENT =
Math.min(1 << 10,
Integer.highestOneBit(Runtime.getRuntime().availableProcessors()) << 4);
private final AtomicInteger resizers = new AtomicInteger(1);

Check warning on line 639 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L636-L639

Added lines #L636 - L639 were not covered by tests
private final Entry[] nextArray;
private final AtomicInteger queuePosition;

private ResizeContainer(Entry[] nextArray, int oldSize) {
super(NULL_VALUE, NULL_VALUE, 4);
this.nextArray = nextArray;
this.queuePosition = new AtomicInteger(oldSize);
}

Check warning on line 647 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L644-L647

Added lines #L644 - L647 were not covered by tests

public void incrementResizer() {
this.resizers.incrementAndGet();
}

Check warning on line 651 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L650-L651

Added lines #L650 - L651 were not covered by tests

public void decrementResizerAndNotify() {
int remaining = this.resizers.decrementAndGet();

Check warning on line 654 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L654

Added line #L654 was not covered by tests
if (remaining == 0) {
synchronized (this) {
this.notifyAll();
}

Check warning on line 658 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L656-L658

Added lines #L656 - L658 were not covered by tests
}
}

Check warning on line 660 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L660

Added line #L660 was not covered by tests

public int getQueuePosition() {
return this.queuePosition.get();

Check warning on line 663 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L663

Added line #L663 was not covered by tests
}

public int subtractAndGetQueuePosition() {
return this.queuePosition.addAndGet(-QUEUE_INCREMENT);

Check warning on line 667 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L667

Added line #L667 was not covered by tests
}

public void waitForAllResizers() {
if (this.resizers.get() > 0) {
for (int i = 0; i < 16; i++) {
if (this.resizers.get() == 0) {
break;

Check warning on line 674 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L674

Added line #L674 was not covered by tests
}
}
for (int i = 0; i < 16; i++) {
if (this.resizers.get() == 0) {
break;

Check warning on line 679 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L679

Added line #L679 was not covered by tests
}
Thread.yield();

Check warning on line 681 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L681

Added line #L681 was not covered by tests
}
}
if (this.resizers.get() > 0) {
synchronized (this) {

Check warning on line 685 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L685

Added line #L685 was not covered by tests
while (this.resizers.get() > 0) {
try {
this.wait();
} catch (InterruptedException e) {

Check warning on line 689 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L688-L689

Added lines #L688 - L689 were not covered by tests
//ginore
}

Check warning on line 691 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L691

Added line #L691 was not covered by tests
}
}

Check warning on line 693 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L693

Added line #L693 was not covered by tests
}
}

Check warning on line 695 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L695

Added line #L695 was not covered by tests

public boolean isNotDone() {
return this.resizers.get() > 0;
}

public void zeroOutQueuePosition() {
this.queuePosition.set(0);
}

Check warning on line 703 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L702-L703

Added lines #L702 - L703 were not covered by tests
}

private static class Entry {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we expect a primitive type instead of a class, it's too many objects because each Entry will be generated an object

Expand All @@ -717,50 +717,46 @@
*/
final int state;

public Entry(int key, int value, int state) {
this.key = key;
this.value = value;
this.state = state;
}

Check warning on line 724 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L720-L724

Added lines #L720 - L724 were not covered by tests

public Entry(int key, int value) {
this.key = key;
this.value = value;
this.next = null;
this.state = 0;
}

Check warning on line 731 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L726-L731

Added lines #L726 - L731 were not covered by tests

public Entry(int key, int value, Entry next) {
this.key = key;
this.value = value;
this.next = next;
this.state = 0;
}

Check warning on line 738 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L733-L738

Added lines #L733 - L738 were not covered by tests

public int getKey() {
return key;

Check warning on line 741 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L741

Added line #L741 was not covered by tests
}

public int getValue() {
return value;

Check warning on line 745 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L745

Added line #L745 was not covered by tests
}

public Entry getNext() {
return next;

Check warning on line 749 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L749

Added line #L749 was not covered by tests
}

public void setNext(Entry next) {
this.next = next;
}

@Override
public String toString() {
return this.key + "=" + this.value;

Check warning on line 754 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L754

Added line #L754 was not covered by tests
}
}

/* ---------------- Unsafe mechanics -------------- */
private static final Unsafe UNSAFE = IntSet.UNSAFE;

Check warning on line 759 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L759

Added line #L759 was not covered by tests
private static final long ENTRY_ARRAY_BASE;
private static final int ENTRY_ARRAY_SHIFT;
private static final long INT_ARRAY_BASE;
Expand All @@ -769,26 +765,26 @@

static {
try {
Class<?> tableClass = Entry[].class;
ENTRY_ARRAY_BASE = UNSAFE.arrayBaseOffset(tableClass);
int objectArrayScale = UNSAFE.arrayIndexScale(tableClass);

Check warning on line 770 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L768-L770

Added lines #L768 - L770 were not covered by tests
if ((objectArrayScale & (objectArrayScale - 1)) != 0) {
throw new AssertionError("data type scale not a power of two");

Check warning on line 772 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L772

Added line #L772 was not covered by tests
}
ENTRY_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(objectArrayScale);

Check warning on line 774 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L774

Added line #L774 was not covered by tests

Class<?> intArrayClass = int[].class;
INT_ARRAY_BASE = UNSAFE.arrayBaseOffset(intArrayClass);
int intArrayScale = UNSAFE.arrayIndexScale(intArrayClass);

Check warning on line 778 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L776-L778

Added lines #L776 - L778 were not covered by tests
if ((intArrayScale & (intArrayScale - 1)) != 0) {
throw new AssertionError("data type scale not a power of two");

Check warning on line 780 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L780

Added line #L780 was not covered by tests
}
INT_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(intArrayScale);

Check warning on line 782 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L782

Added line #L782 was not covered by tests

Class<?> mapClass = IntMapByDynamicHash.class;
SIZE_OFFSET = UNSAFE.objectFieldOffset(mapClass.getDeclaredField("size"));
} catch (NoSuchFieldException | SecurityException e) {
throw new AssertionError(e);
}
}

Check warning on line 789 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L784-L789

Added lines #L784 - L789 were not covered by tests
}
Loading
Loading