Search in sources :

Example 1 with CoalescableTreeMap

use of com.cinchapi.common.collect.CoalescableTreeMap in project concourse by cinchapi.

the class IndexRecord method coalesce.

/**
 * Return all the key/value mappings of keys that matched {@code key} at
 * {@code timestamp} in a case insensitive manner.
 *
 * @param key
 * @param timestamp
 * @return the matching entries
 */
private Map<Value, Set<Identifier>> coalesce(Value key, long timestamp) {
    read.lock();
    try {
        Map<Value, Set<Identifier>> data = Maps.newLinkedHashMap();
        Map<Value, List<CompactRevision<Identifier>>> coalesced = ((CoalescableTreeMap<Value, List<CompactRevision<Identifier>>>) history).coalesce(key, CASE_INSENSITIVE_COALESCER);
        for (Entry<Value, List<CompactRevision<Identifier>>> entry : coalesced.entrySet()) {
            Value stored = entry.getKey();
            List<CompactRevision<Identifier>> revisions = entry.getValue();
            Set<Identifier> values = Sets.newLinkedHashSet();
            Iterator<CompactRevision<Identifier>> it = revisions.iterator();
            while (it.hasNext()) {
                CompactRevision<Identifier> revision = it.next();
                if (revision.getVersion() <= timestamp) {
                    if (revision.getType() == Action.ADD) {
                        values.add(revision.getValue());
                    } else {
                        values.remove(revision.getValue());
                    }
                } else {
                    break;
                }
            }
            data.put(stored, values);
        }
        return data;
    } finally {
        read.unlock();
    }
}
Also used : CoalescableTreeMap(com.cinchapi.common.collect.CoalescableTreeMap) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) LazyTransformSet(com.cinchapi.common.collect.lazy.LazyTransformSet) Identifier(com.cinchapi.concourse.server.model.Identifier) Value(com.cinchapi.concourse.server.model.Value) List(java.util.List)

Aggregations

CoalescableTreeMap (com.cinchapi.common.collect.CoalescableTreeMap)1 LazyTransformSet (com.cinchapi.common.collect.lazy.LazyTransformSet)1 Identifier (com.cinchapi.concourse.server.model.Identifier)1 Value (com.cinchapi.concourse.server.model.Value)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 List (java.util.List)1 NavigableSet (java.util.NavigableSet)1 Set (java.util.Set)1