-
Notifications
You must be signed in to change notification settings - Fork 517
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L43-L44
|
||
"table"); | ||
|
||
private volatile Entry[] table; | ||
|
@@ -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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L54-L55
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L57
|
||
|
||
/** | ||
* must be 2^n - 1 | ||
|
@@ -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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L67
|
||
((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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L73
|
||
array, | ||
((long) index << ENTRY_ARRAY_SHIFT) + ENTRY_ARRAY_BASE, | ||
expected, | ||
|
@@ -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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L81
|
||
newValue); | ||
} | ||
Check warning on line 83 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L83
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L86-L91
|
||
return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1; | ||
} | ||
|
||
|
@@ -96,47 +96,47 @@ | |
private volatile int size; // updated via atomic field updater | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L99-L100
|
||
|
||
public IntMapByDynamicHash(int initialCapacity) { | ||
Check warning on line 102 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L102
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L104
|
||
} | ||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L107
|
||
} | ||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L109
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L111
|
||
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. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L117
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L121-L122
|
||
|
||
@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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L126-L128
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L130-L131
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L133
|
||
} | ||
this.addToSize(-1); | ||
Check warning on line 135 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L135
|
||
} | ||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L138-L139
|
||
} | ||
|
||
private int slowPut(int key, int value, Entry[] currentTable) { | ||
|
@@ -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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L148-L150
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L153
|
||
} 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L155-L156
|
||
|
||
// 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L160
|
||
if (candidate == key) { | ||
found = true; | ||
break; | ||
Check warning on line 163 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L162-L163
|
||
} | ||
e = e.getNext(); | ||
} | ||
Check warning on line 166 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L165-L166
|
||
|
||
if (found) { | ||
int oldVal = e.getValue(); | ||
Check warning on line 169 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L169
|
||
// 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L171-L172
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L174
|
||
} | ||
} else { | ||
Check warning on line 176 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L176
|
||
// 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L178
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L180-L181
|
||
} | ||
} | ||
} | ||
Check warning on line 184 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L184
|
||
} | ||
} | ||
|
||
@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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L190-L192
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L194
|
||
} | ||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L199
|
||
} | ||
} | ||
return NULL_VALUE; | ||
Check warning on line 202 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L202
|
||
} | ||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L207-L209
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L211
|
||
} else { | ||
Entry e = o; | ||
Check warning on line 213 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L213
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L215
|
||
if (candidate == key) { | ||
return e.getValue(); | ||
Check warning on line 217 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L217
|
||
} | ||
e = e.getNext(); | ||
} | ||
return NULL_VALUE; | ||
Check warning on line 221 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L219-L221
|
||
} | ||
} | ||
Check warning on line 223 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L223
|
||
} | ||
|
||
@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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L228-L230
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L235
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L237
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L239
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L241-L242
|
||
} | ||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L246-L248
|
||
} | ||
|
||
private Entry slowRemove(int key, Entry[] currentTable) { | ||
|
@@ -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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L257-L259
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L261
|
||
} 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L263-L264
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L267
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L269
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L271-L272
|
||
} | ||
// 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L277-L279
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L283
|
||
} | ||
} | ||
Check warning on line 285 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L285
|
||
} | ||
} | ||
|
||
|
@@ -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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L297
|
||
} | ||
|
||
@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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L303
|
||
} | ||
|
||
@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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L308
|
||
ResizeContainer resizeContainer; | ||
do { | ||
resizeContainer = null; | ||
Check warning on line 311 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L311
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L313
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L315
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L319
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L321
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L323-L324
|
||
} | ||
this.addToSize(-removedEntries); | ||
Check warning on line 326 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L326
|
||
} | ||
} | ||
} | ||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L332-L333
|
||
} | ||
currentArray = resizeContainer.nextArray; | ||
Check warning on line 335 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L335
|
||
} | ||
} while (resizeContainer != null); | ||
} | ||
Check warning on line 338 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L338
|
||
|
||
@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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L342
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L345
|
||
} | ||
} | ||
return localSize; | ||
Check warning on line 348 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L348
|
||
} | ||
|
||
@Override | ||
public boolean concurrent() { | ||
return true; | ||
Check warning on line 353 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L353
|
||
} | ||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L357
|
||
} | ||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L361
|
||
} | ||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L365
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L367-L369
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L371
|
||
} else { | ||
Entry e = o; | ||
Check warning on line 373 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L373
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L375
|
||
if (candidate == key) { | ||
return e; | ||
Check warning on line 377 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L377
|
||
} | ||
e = e.getNext(); | ||
} | ||
return null; | ||
Check warning on line 381 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L379-L381
|
||
} | ||
} | ||
Check warning on line 383 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L383
|
||
} | ||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L389
|
||
} | ||
} | ||
this.incrementLocalSize(value); | ||
} | ||
Check warning on line 393 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L392-L393
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L396-L398
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L400-L401
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L403
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L406
|
||
} | ||
} | ||
Check warning on line 408 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L408
|
||
} | ||
return false; | ||
Check warning on line 410 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L410
|
||
} | ||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L415
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L417
|
||
} | ||
} | ||
} | ||
Check warning on line 420 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L419-L420
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L425
|
||
} | ||
Entry replacement = null; | ||
Entry e = original; | ||
Check warning on line 428 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L427-L428
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L431
|
||
} | ||
e = e.getNext(); | ||
Check warning on line 433 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L433
|
||
} | ||
return replacement; | ||
Check warning on line 435 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L435
|
||
} | ||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L439
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L441-L442
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L444
|
||
} | ||
} | ||
} | ||
Check warning on line 447 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L447
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L450-L451
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L453-L454
|
||
if ((helpCount & 7) == 0) { | ||
Thread.yield(); | ||
Check warning on line 456 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L456
|
||
} | ||
} | ||
return newArray; | ||
Check warning on line 459 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L459
|
||
} | ||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L463-L464
|
||
|
||
// 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L469-L471
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L473
|
||
} | ||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L476
|
||
} | ||
ResizeContainer resizeContainer = null; | ||
Check warning on line 478 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L478
|
||
// 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L481
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L484
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L486
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L488
|
||
} | ||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L490-L492
|
||
} | ||
} | ||
Check warning on line 494 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L494
|
||
} | ||
if (ownResize) { | ||
this.transfer(oldTable, resizeContainer); | ||
Check warning on line 497 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L497
|
||
|
||
Entry[] src = this.table; | ||
Check warning on line 499 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L499
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L506
|
||
} | ||
} | ||
} else { | ||
this.helpWithResize(oldTable); | ||
Check warning on line 510 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L509-L510
|
||
} | ||
} | ||
Check warning on line 512 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L512
|
||
|
||
/** | ||
* 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L518
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L521
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L524
|
||
} | ||
} else if (o == RESIZED || o == RESIZING) { | ||
/* | ||
|
@@ -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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L532
|
||
/* | ||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L538
|
||
} | ||
} else { | ||
Entry e = o; | ||
Check warning on line 541 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L541
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L544-L545
|
||
} | ||
IntMapByDynamicHash.setTableAt(src, j, RESIZED); | ||
j++; | ||
Check warning on line 548 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L547-L548
|
||
} | ||
} | ||
} | ||
resizeContainer.decrementResizerAndNotify(); | ||
resizeContainer.waitForAllResizers(); | ||
} | ||
Check warning on line 554 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L551-L554
|
||
|
||
/** | ||
* 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L560-L561
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L563
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L565-L567
|
||
} | ||
return newTable; | ||
Check warning on line 569 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L569
|
||
} | ||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L573
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L575-L576
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L579
|
||
} | ||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L582
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L585
|
||
} | ||
} 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L588-L589
|
||
} else { | ||
Entry e = o; | ||
Check warning on line 591 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L591
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L594-L595
|
||
} | ||
IntMapByDynamicHash.setTableAt(src, j, RESIZED); | ||
j--; | ||
Check warning on line 598 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L597-L598
|
||
} | ||
} | ||
} | ||
Check warning on line 601 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L601
|
||
} | ||
} | ||
} | ||
Check warning on line 604 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L603-L604
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L607
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L609-L611
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L613
|
||
length - | ||
1)).nextArray; | ||
Check warning on line 615 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L615
|
||
} 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L620
|
||
} 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L622
|
||
} | ||
} 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L625-L626
|
||
} | ||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L629
|
||
} | ||
} | ||
} | ||
Check warning on line 632 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L632
|
||
} | ||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L636-L639
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L644-L647
|
||
|
||
public void incrementResizer() { | ||
this.resizers.incrementAndGet(); | ||
} | ||
Check warning on line 651 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L650-L651
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L654
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L656-L658
|
||
} | ||
} | ||
Check warning on line 660 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L660
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L663
|
||
} | ||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L667
|
||
} | ||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L674
|
||
} | ||
} | ||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L679
|
||
} | ||
Thread.yield(); | ||
Check warning on line 681 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L681
|
||
} | ||
} | ||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L685
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L688-L689
|
||
//ginore | ||
} | ||
Check warning on line 691 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L691
|
||
} | ||
} | ||
Check warning on line 693 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L693
|
||
} | ||
} | ||
Check warning on line 695 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L695
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L702-L703
|
||
} | ||
|
||
private static class Entry { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
@@ -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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L720-L724
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L726-L731
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L733-L738
|
||
|
||
public int getKey() { | ||
return key; | ||
Check warning on line 741 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L741
|
||
} | ||
|
||
public int getValue() { | ||
return value; | ||
Check warning on line 745 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L745
|
||
} | ||
|
||
public Entry getNext() { | ||
return next; | ||
Check warning on line 749 in hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L749
|
||
} | ||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L754
|
||
} | ||
} | ||
|
||
/* ---------------- 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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L759
|
||
private static final long ENTRY_ARRAY_BASE; | ||
private static final int ENTRY_ARRAY_SHIFT; | ||
private static final long INT_ARRAY_BASE; | ||
|
@@ -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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L768-L770
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L772
|
||
} | ||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L774
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L776-L778
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L780
|
||
} | ||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L782
|
||
|
||
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 Codecov / codecov/patchhugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMapByDynamicHash.java#L784-L789
|
||
} |
There was a problem hiding this comment.
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