Search in sources :

Example 1 with DiffSets

use of org.neo4j.kernel.impl.util.diffsets.DiffSets in project neo4j by neo4j.

the class TxState method getIndexUpdatesForRangeSeekByString.

private ReadableDiffSets<Long> getIndexUpdatesForRangeSeekByString(NewIndexDescriptor descriptor, String lower, boolean includeLower, String upper, boolean includeUpper) {
    TreeMap<OrderedPropertyValues, DiffSets<Long>> sortedUpdates = getSortedIndexUpdates(descriptor.schema());
    if (sortedUpdates == null) {
        return null;
    }
    OrderedPropertyValues selectedLower;
    boolean selectedIncludeLower;
    OrderedPropertyValues selectedUpper;
    boolean selectedIncludeUpper;
    //TODO: Get working with composite indexes
    if (lower == null) {
        selectedLower = OrderedPropertyValues.ofUndefined(STRING.lowLimit.castValue(String.class));
        selectedIncludeLower = STRING.lowLimit.isInclusive;
    } else {
        selectedLower = OrderedPropertyValues.ofUndefined(lower);
        selectedIncludeLower = includeLower;
    }
    if (upper == null) {
        selectedUpper = OrderedPropertyValues.ofUndefined(STRING.highLimit.castValue(Boolean.class).booleanValue());
        selectedIncludeUpper = STRING.highLimit.isInclusive;
    } else {
        selectedUpper = OrderedPropertyValues.ofUndefined(upper);
        selectedIncludeUpper = includeUpper;
    }
    DiffSets<Long> diffs = new DiffSets<>();
    Collection<DiffSets<Long>> inRange = sortedUpdates.subMap(selectedLower, selectedIncludeLower, selectedUpper, selectedIncludeUpper).values();
    for (DiffSets<Long> diffForSpecificValue : inRange) {
        diffs.addAll(diffForSpecificValue.getAdded().iterator());
        diffs.removeAll(diffForSpecificValue.getRemoved().iterator());
    }
    return diffs;
}
Also used : DiffSets(org.neo4j.kernel.impl.util.diffsets.DiffSets) RelationshipDiffSets(org.neo4j.kernel.impl.util.diffsets.RelationshipDiffSets) ReadableDiffSets(org.neo4j.storageengine.api.txstate.ReadableDiffSets) ReadableRelationshipDiffSets(org.neo4j.storageengine.api.txstate.ReadableRelationshipDiffSets) OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues)

Example 2 with DiffSets

use of org.neo4j.kernel.impl.util.diffsets.DiffSets in project neo4j by neo4j.

the class TxState method getIndexUpdatesForRangeSeekByPrefix.

private ReadableDiffSets<Long> getIndexUpdatesForRangeSeekByPrefix(NewIndexDescriptor descriptor, String prefix) {
    TreeMap<OrderedPropertyValues, DiffSets<Long>> sortedUpdates = getSortedIndexUpdates(descriptor.schema());
    if (sortedUpdates == null) {
        return null;
    }
    //TODO: get working with composite indexes
    OrderedPropertyValues floor = OrderedPropertyValues.ofUndefined(prefix);
    DiffSets<Long> diffs = new DiffSets<>();
    for (Map.Entry<OrderedPropertyValues, DiffSets<Long>> entry : sortedUpdates.tailMap(floor).entrySet()) {
        OrderedPropertyValues key = entry.getKey();
        if (key.getSinglePropertyValue().toString().startsWith(prefix)) {
            DiffSets<Long> diffSets = entry.getValue();
            diffs.addAll(diffSets.getAdded().iterator());
            diffs.removeAll(diffSets.getRemoved().iterator());
        } else {
            break;
        }
    }
    return diffs;
}
Also used : DiffSets(org.neo4j.kernel.impl.util.diffsets.DiffSets) RelationshipDiffSets(org.neo4j.kernel.impl.util.diffsets.RelationshipDiffSets) ReadableDiffSets(org.neo4j.storageengine.api.txstate.ReadableDiffSets) ReadableRelationshipDiffSets(org.neo4j.storageengine.api.txstate.ReadableRelationshipDiffSets) OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 3 with DiffSets

use of org.neo4j.kernel.impl.util.diffsets.DiffSets in project neo4j by neo4j.

the class TxState method getIndexUpdatesForRangeSeekByNumber.

private ReadableDiffSets<Long> getIndexUpdatesForRangeSeekByNumber(NewIndexDescriptor descriptor, Number lower, boolean includeLower, Number upper, boolean includeUpper) {
    TreeMap<OrderedPropertyValues, DiffSets<Long>> sortedUpdates = getSortedIndexUpdates(descriptor.schema());
    if (sortedUpdates == null) {
        return null;
    }
    OrderedPropertyValues selectedLower;
    boolean selectedIncludeLower;
    OrderedPropertyValues selectedUpper;
    boolean selectedIncludeUpper;
    //TODO: Get working with composite indexes
    if (lower == null) {
        selectedLower = OrderedPropertyValues.ofUndefined(NUMBER.lowLimit.castValue(Number.class));
        selectedIncludeLower = NUMBER.lowLimit.isInclusive;
    } else {
        selectedLower = OrderedPropertyValues.ofUndefined(lower);
        selectedIncludeLower = includeLower;
    }
    if (upper == null) {
        selectedUpper = OrderedPropertyValues.ofUndefined(NUMBER.highLimit.castValue(Number.class));
        selectedIncludeUpper = NUMBER.highLimit.isInclusive;
    } else {
        selectedUpper = OrderedPropertyValues.ofUndefined(upper);
        selectedIncludeUpper = includeUpper;
    }
    DiffSets<Long> diffs = new DiffSets<>();
    Collection<DiffSets<Long>> inRange = sortedUpdates.subMap(selectedLower, selectedIncludeLower, selectedUpper, selectedIncludeUpper).values();
    for (DiffSets<Long> diffForSpecificValue : inRange) {
        diffs.addAll(diffForSpecificValue.getAdded().iterator());
        diffs.removeAll(diffForSpecificValue.getRemoved().iterator());
    }
    return diffs;
}
Also used : DiffSets(org.neo4j.kernel.impl.util.diffsets.DiffSets) RelationshipDiffSets(org.neo4j.kernel.impl.util.diffsets.RelationshipDiffSets) ReadableDiffSets(org.neo4j.storageengine.api.txstate.ReadableDiffSets) ReadableRelationshipDiffSets(org.neo4j.storageengine.api.txstate.ReadableRelationshipDiffSets) OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues)

Example 4 with DiffSets

use of org.neo4j.kernel.impl.util.diffsets.DiffSets in project neo4j by neo4j.

the class LongDiffSetsTest method shouldContainSourceForEmptyDiffSets.

// TODO empty diffset EMPTY
// TODO null/isEmpty elements
@Test
public void shouldContainSourceForEmptyDiffSets() throws Exception {
    // given
    DiffSets<Long> diffSets = new DiffSets<>();
    Iterator<Long> expected = diffSets.apply(iteratorSource(1L, 2L));
    // when
    PrimitiveLongIterator actual = diffSets.augment(iterator(1L, 2L));
    // then
    assertThat(expected, hasSamePrimitiveItems(actual));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) DiffSets(org.neo4j.kernel.impl.util.diffsets.DiffSets) Test(org.junit.Test)

Example 5 with DiffSets

use of org.neo4j.kernel.impl.util.diffsets.DiffSets in project neo4j by neo4j.

the class LongDiffSetsTest method shouldContainFilteredSourceForDiffSetsWithAddedElements.

@Test
public void shouldContainFilteredSourceForDiffSetsWithAddedElements() throws Exception {
    // given
    DiffSets<Long> diffSets = new DiffSets<>();
    diffSets.add(17L);
    diffSets.add(18L);
    Iterator<Long> expected = diffSets.apply(iteratorSource(1L, 17L, 3L));
    // when
    PrimitiveLongIterator actual = diffSets.augment(iterator(1L, 17L, 3L));
    // then
    assertThat(expected, hasSamePrimitiveItems(actual));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) DiffSets(org.neo4j.kernel.impl.util.diffsets.DiffSets) Test(org.junit.Test)

Aggregations

DiffSets (org.neo4j.kernel.impl.util.diffsets.DiffSets)7 Test (org.junit.Test)4 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)4 OrderedPropertyValues (org.neo4j.kernel.api.schema_new.OrderedPropertyValues)3 RelationshipDiffSets (org.neo4j.kernel.impl.util.diffsets.RelationshipDiffSets)3 ReadableDiffSets (org.neo4j.storageengine.api.txstate.ReadableDiffSets)3 ReadableRelationshipDiffSets (org.neo4j.storageengine.api.txstate.ReadableRelationshipDiffSets)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1