use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.
the class PrimitiveLongSetTest method shouldContainReallyBigLongValue.
@Test
public void shouldContainReallyBigLongValue() throws Exception {
// GIVEN
PrimitiveLongSet set = newSet(10);
set.add(7416509207113022571L);
// WHEN/THEN
boolean existedBefore = set.contains(7620037383187366331L);
boolean added = set.add(7620037383187366331L);
boolean existsAfter = set.contains(7620037383187366331L);
assertFalse("7620037383187366331 should not exist before adding here", existedBefore);
assertTrue("7620037383187366331 should be reported as added here", added);
assertTrue("7620037383187366331 should exist", existsAfter);
}
use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.
the class HopScotchHashingAlgorithmTest method figureOutGrowthThreshold.
private int figureOutGrowthThreshold() {
final AtomicBoolean grew = new AtomicBoolean();
Monitor monitor = new Monitor.Adapter() {
@Override
public boolean tableGrew(int fromCapacity, int toCapacity, int currentSize) {
grew.set(true);
return true;
}
};
try (PrimitiveLongSet set = new PrimitiveLongHashSet(new LongKeyTable<>(DEFAULT_H, VALUE_MARKER), VALUE_MARKER, monitor)) {
int i = 0;
for (i = 0; !grew.get(); i++) {
set.add(i * 3);
}
return i;
}
}
use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.
the class HopScotchHashingAlgorithmTest method shouldSupportIteratingThroughResize.
@Test
public void shouldSupportIteratingThroughResize() throws Exception {
// GIVEN
int threshold = figureOutGrowthThreshold();
TableGrowthAwareMonitor monitor = new TableGrowthAwareMonitor();
PrimitiveLongSet set = new PrimitiveLongHashSet(new LongKeyTable<>(DEFAULT_H, VALUE_MARKER), VALUE_MARKER, monitor);
Set<Long> added = new HashSet<>();
for (int i = 0; i < threshold - 1; i++) {
long value = i * 3;
set.add(value);
added.add(value);
}
// WHEN
PrimitiveLongIterator iterator = set.iterator();
Set<Long> iterated = new HashSet<>();
for (int i = 0; i < threshold / 2; i++) {
iterated.add(iterator.next());
}
assertFalse(monitor.checkAndReset());
// will push it over the edge, to grow the table
set.add((threshold - 1) * 3);
assertTrue(monitor.checkAndReset());
while (iterator.hasNext()) {
iterated.add(iterator.next());
}
// THEN
assertEquals(added, iterated);
}
use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.
the class LuceneLegacyIndex method query.
protected LegacyIndexHits query(Query query, String keyForDirectLookup, Object valueForDirectLookup, QueryContext additionalParametersOrNull) {
List<EntityId> simpleTransactionStateIds = new ArrayList<>();
Collection<EntityId> removedIdsFromTransactionState = Collections.emptySet();
IndexSearcher fulltextTransactionStateSearcher = null;
if (transaction != null) {
if (keyForDirectLookup != null) {
simpleTransactionStateIds.addAll(transaction.getAddedIds(this, keyForDirectLookup, valueForDirectLookup));
} else {
fulltextTransactionStateSearcher = transaction.getAdditionsAsSearcher(this, additionalParametersOrNull);
}
removedIdsFromTransactionState = keyForDirectLookup != null ? transaction.getRemovedIds(this, keyForDirectLookup, valueForDirectLookup) : transaction.getRemovedIds(this, query);
}
LegacyIndexHits idIterator = null;
IndexReference searcher = null;
dataSource.getReadLock();
try {
searcher = dataSource.getIndexSearcher(identifier);
} finally {
dataSource.releaseReadLock();
}
if (searcher != null) {
try {
// Gather all added ids from fulltextTransactionStateSearcher and simpleTransactionStateIds.
PrimitiveLongSet idsModifiedInTransactionState = gatherIdsModifiedInTransactionState(simpleTransactionStateIds, fulltextTransactionStateSearcher, query);
// Do the combined search from store and fulltext tx state
DocToIdIterator hits = new DocToIdIterator(search(searcher, fulltextTransactionStateSearcher, query, additionalParametersOrNull, removedIdsFromTransactionState), removedIdsFromTransactionState, searcher, idsModifiedInTransactionState);
idIterator = simpleTransactionStateIds.isEmpty() ? hits : new CombinedIndexHits(Arrays.<LegacyIndexHits>asList(hits, new ConstantScoreIterator(simpleTransactionStateIds, Float.NaN)));
} catch (IOException e) {
throw new RuntimeException("Unable to query " + this + " with " + query, e);
}
}
// We've only got transaction state
idIterator = idIterator == null ? new ConstantScoreIterator(simpleTransactionStateIds, 0) : idIterator;
return idIterator;
}
use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.
the class LuceneLegacyIndex method gatherIdsModifiedInTransactionState.
private PrimitiveLongSet gatherIdsModifiedInTransactionState(List<EntityId> simpleTransactionStateIds, IndexSearcher fulltextTransactionStateSearcher, Query query) throws IOException {
// If there's no state them don't bother gathering it
if (simpleTransactionStateIds.isEmpty() && fulltextTransactionStateSearcher == null) {
return PrimitiveLongCollections.emptySet();
}
// There's potentially some state
DocValuesCollector docValuesCollector = null;
int fulltextSize = 0;
if (fulltextTransactionStateSearcher != null) {
docValuesCollector = new DocValuesCollector();
fulltextTransactionStateSearcher.search(query, docValuesCollector);
fulltextSize = docValuesCollector.getTotalHits();
// Nah, no state
if (simpleTransactionStateIds.isEmpty() && fulltextSize == 0) {
return PrimitiveLongCollections.emptySet();
}
}
PrimitiveLongSet set = longSet(simpleTransactionStateIds.size() + fulltextSize);
// Add from simple tx state
for (EntityId id : simpleTransactionStateIds) {
set.add(id.id());
}
if (docValuesCollector != null) {
// Add from fulltext tx state
PrimitiveLongIterator valuesIterator = docValuesCollector.getValuesIterator(LuceneLegacyIndex.KEY_DOC_ID);
while (valuesIterator.hasNext()) {
set.add(valuesIterator.next());
}
}
return set;
}
Aggregations