Example usage for java.util.concurrent ConcurrentSkipListMap subMap

List of usage examples for java.util.concurrent ConcurrentSkipListMap subMap

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentSkipListMap subMap.

Prototype

public ConcurrentNavigableMap<K, V> subMap(K fromKey, K toKey) 

Source Link

Usage

From source file:com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService.java

@Override
public Multimap<Cell, Long> getAllTimestamps(String tableName, Set<Cell> cells, long ts) {
    Multimap<Cell, Long> multimap = HashMultimap.create();
    ConcurrentSkipListMap<Key, byte[]> table = getTableMap(tableName).entries;
    for (Cell key : cells) {
        for (Key entry : table.subMap(new Key(key, Long.MIN_VALUE), new Key(key, ts)).keySet()) {
            multimap.put(key, entry.ts);
        }//from  w w  w  . jav a  2  s . c  om
    }
    return multimap;
}

From source file:com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService.java

@Override
public Map<Cell, Value> getRows(String tableName, Iterable<byte[]> rows, ColumnSelection columnSelection,
        long timestamp) {
    Map<Cell, Value> result = Maps.newHashMap();
    ConcurrentSkipListMap<Key, byte[]> table = getTableMap(tableName).entries;

    for (byte[] row : rows) {
        Cell rowBegin = Cells.createSmallestCellForRow(row);
        Cell rowEnd = Cells.createLargestCellForRow(row);
        PeekingIterator<Entry<Key, byte[]>> entries = Iterators.peekingIterator(table
                .subMap(new Key(rowBegin, Long.MIN_VALUE), new Key(rowEnd, timestamp)).entrySet().iterator());
        while (entries.hasNext()) {
            Entry<Key, byte[]> entry = entries.peek();
            Key key = entry.getKey();
            Iterator<Entry<Key, byte[]>> cellIter = takeCell(entries, key);
            if (columnSelection.contains(key.col)) {
                Entry<Key, byte[]> lastEntry = null;
                while (cellIter.hasNext()) {
                    Entry<Key, byte[]> curEntry = cellIter.next();
                    if (curEntry.getKey().ts >= timestamp) {
                        break;
                    }/*  w w w. j  av  a2s  .  c o  m*/
                    lastEntry = curEntry;
                }
                if (lastEntry != null) {
                    long ts = lastEntry.getKey().ts;
                    byte[] value = lastEntry.getValue();
                    result.put(Cell.create(row, key.col), Value.create(value, ts));
                }
            }
            Iterators.size(cellIter);
        }
    }

    return result;
}