| 1 |
package com.carrotsearch.hppc.benchmarks.implementations; |
| 2 |
|
| 3 |
import net.openhft.koloboke.collect.hash.HashConfig; |
| 4 |
import net.openhft.koloboke.collect.set.hash.HashIntSet; |
| 5 |
import net.openhft.koloboke.collect.set.hash.HashIntSets; |
| 6 |
|
| 7 |
import com.carrotsearch.hppc.benchmarks.IntSetOps; |
| 8 |
|
| 9 |
public class KolobokeIntSetOps implements IntSetOps { |
| 10 |
private final HashIntSet delegate; |
| 11 |
|
| 12 |
public KolobokeIntSetOps(int expectedElements, double loadFactor) { |
| 13 |
this.delegate = HashIntSets.getDefaultFactory() |
| 14 |
.withHashConfig(HashConfig.fromLoads(loadFactor / 2, loadFactor, loadFactor)).newMutableSet(); |
| 15 |
this.delegate.ensureCapacity(expectedElements); |
| 16 |
} |
| 17 |
|
| 18 |
@Override |
| 19 |
public void add(int key) { |
| 20 |
delegate.add(key); |
| 21 |
} |
| 22 |
|
| 23 |
@Override |
| 24 |
public void bulkAdd(int[] keys) { |
| 25 |
for (int key : keys) { |
| 26 |
delegate.add(key); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
@Override |
| 31 |
public int bulkContains(int[] keys) { |
| 32 |
int v = 0; |
| 33 |
for (int key : keys) { |
| 34 |
if (delegate.contains(key)) { |
| 35 |
v++; |
| 36 |
} |
| 37 |
} |
| 38 |
return v; |
| 39 |
} |
| 40 |
|
| 41 |
@Override |
| 42 |
public int[] iterationOrderArray() { |
| 43 |
return delegate.toIntArray(); |
| 44 |
} |
| 45 |
} |