-
Notifications
You must be signed in to change notification settings - Fork 478
Expand file tree
/
Copy pathLongCompactOffHeapLinearHashTable.java
More file actions
83 lines (70 loc) · 2.67 KB
/
Copy pathLongCompactOffHeapLinearHashTable.java
File metadata and controls
83 lines (70 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Copyright 2013-2026 chronicle.software; SPDX-License-Identifier: Apache-2.0
*/
package net.openhft.chronicle.hash.impl;
import net.openhft.chronicle.core.OS;
import static net.openhft.chronicle.assertions.AssertUtil.SKIP_ASSERTIONS;
import static net.openhft.chronicle.map.internal.InternalAssertUtil.assertAddress;
import static net.openhft.chronicle.map.internal.InternalAssertUtil.assertPosition;
@SuppressWarnings({"rawtypes", "unchecked"})
public final class LongCompactOffHeapLinearHashTable extends CompactOffHeapLinearHashTable {
private static final long SCALE = 8L;
/**
* Must not store {@code h} in a field, to avoid memory leaks.
*
* @see net.openhft.chronicle.hash.impl.stage.hash.Chaining#initMap
*/
LongCompactOffHeapLinearHashTable(VanillaChronicleHash h) {
super(h);
}
@Override
long indexToPos(long index) {
return index * SCALE;
}
@Override
public long step(long pos) {
return (pos + SCALE) & capacityMask2;
}
@Override
public long stepBack(long pos) {
return (pos - SCALE) & capacityMask2;
}
@Override
public long readEntry(final long address,
final long pos) {
assert SKIP_ASSERTIONS || assertAddress(address);
assert SKIP_ASSERTIONS || assertPosition(pos);
return OS.memory().readLong(address + pos);
}
@Override
public long readEntryVolatile(final long address,
final long pos) {
assert SKIP_ASSERTIONS || assertAddress(address);
assert SKIP_ASSERTIONS || assertPosition(pos);
return OS.memory().readVolatileLong(address + pos);
}
@Override
public void writeEntryVolatile(final long address,
final long pos,
final long key,
final long value) {
assert SKIP_ASSERTIONS || assertAddress(address);
assert SKIP_ASSERTIONS || assertPosition(pos);
OS.memory().writeVolatileLong(address + pos, entry(key, value));
}
@Override
public void writeEntry(final long address,
final long pos,
final long newEntry) {
assert SKIP_ASSERTIONS || assertAddress(address);
assert SKIP_ASSERTIONS || assertPosition(pos);
OS.memory().writeLong(address + pos, newEntry);
}
@Override
public void clearEntry(final long address,
final long pos) {
assert SKIP_ASSERTIONS || assertAddress(address);
assert SKIP_ASSERTIONS || assertPosition(pos);
OS.memory().writeLong(address + pos, 0L);
}
}