Java Code Examples for org.apache.cassandra.utils.btree.BTreeSearchIterator

Following code examples demonstrate how to use org.apache.cassandra.utils.btree.BTreeSearchIteratorfrom cassandra. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.apache.cassandra.utils.btree.BTreeSearchIteratorand various code implementation of this class.

    }

    public SearchIterator<Clustering, Row> searchIterator(final ColumnFilter columns, final boolean reversed)
    {
        final Holder current = holder();
        return new SearchIterator<Clustering, Row>()
        {
            private final SearchIterator<Clustering, Row> rawIter = new BTreeSearchIterator<>(current.tree, metadata().comparator, desc(reversed));
            private final DeletionTime partitionDeletion = current.deletionInfo.getPartitionDeletion();

            public Row next(Clustering clustering)
            {
                if (clustering == Clustering.STATIC_CLUSTERING)
                    return staticRow(current, columns, true);

                Row row = rawIter.next(clustering);
                RangeTombstone rt = current.deletionInfo.rangeCovering(clustering);

                DeletionTime activeDeletion = partitionDeletion;
                if (rt != null && rt.deletionTime().supersedes(activeDeletion))
                    activeDeletion = rt.deletionTime();

                if (row == null)
                    return activeDeletion.isLive() ? null : BTreeRow.emptyDeletedRow(clustering, Row.Deletion.regular(activeDeletion));

                return row.filter(columns, activeDeletion, true, metadata());
            }
        };
    } 


    @Benchmark
    public void searchNotFound()
    {
        BTreeSearchIterator<String, String> iter = getIterator();
        String val = iter.next(nonExistData.get(targetIdx));
        assert(val == null);
    } 

    @Benchmark
    public void searchFound()
    {
        BTreeSearchIterator<String, String> iter = getIterator();
        String val = iter.next(data.get(targetIdx));
        assert(val != null);
    } 

    }

    private BTreeSearchIterator<String,String> getIterator()
    {
        switch (iteratorType)
        {
            case "LEAF":
                return new LeafBTreeSearchIterator<>(btree, CMP, dir);
            case "TREE":
                return new FullBTreeSearchIterator<>(btree, CMP, dir);
            default:
                throw new IllegalArgumentException("unknown btree iterator type: " + iteratorType);
        }
    } 

    }

    public SearchIterator<CellName, Cell> searchIterator()
    {
        return new BTreeSearchIterator<>(ref.tree, asymmetricComparator());
    } 

Advertisement
Related Classes
Advertisement