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();
}
}
Aggregations