Search in sources :

Example 1 with NameKey

use of suite.fs.impl.FileSystemKeyUtil.NameKey in project suite by stupidsing.

the class FileSystemKeySet method remove.

public void remove(Bytes name) {
    KeyDataMutator<Bytes> mutator = store.mutateData();
    List<NameKey> keys = keyUtil.toNameKeys(name);
    for (int i = keys.size() - 1; 0 <= i; i--) {
        NameKey key = keys.get(i);
        if (key.size == 0) {
            Bytes hash = keyUtil.hash(keyUtil.toName(keys.subList(0, i + 1)));
            NameKey minKey = boundingKey(hash, 0);
            NameKey maxKey = boundingKey(hash, 1);
            if (mutator.keys(keyUtil.toBytes(minKey), keyUtil.toBytes(maxKey)) == null)
                mutator.removeTerminal(keyUtil.toBytes(key));
        } else
            mutator.removeTerminal(keyUtil.toBytes(key));
    }
}
Also used : Bytes(suite.primitive.Bytes) NameKey(suite.fs.impl.FileSystemKeyUtil.NameKey)

Example 2 with NameKey

use of suite.fs.impl.FileSystemKeyUtil.NameKey in project suite by stupidsing.

the class FileSystemKeySet method list.

private Streamlet<Bytes> list(List<NameKey> prefix, List<NameKey> keys0, List<NameKey> keys1) {
    Bytes hash = keyUtil.hash(keyUtil.toName(prefix));
    NameKey minKey = keys0 != null && !keys0.isEmpty() ? List_.first(keys0) : boundingKey(hash, 0);
    NameKey maxKey = keys1 != null && !keys1.isEmpty() ? List_.first(keys1) : boundingKey(hash, 1);
    Streamlet<Bytes> st = store.mutateData().keys(keyUtil.toBytes(minKey), increment(keyUtil.toBytes(maxKey)));
    return st.concatMap(bytes -> {
        NameKey key = keyUtil.toNameKey(bytes);
        List<NameKey> prefix1 = List_.concat(prefix, List.of(key));
        if (key.size == 0) {
            List<NameKey> tailKeys0 = key == minKey ? !keys0.isEmpty() ? List_.right(keys0, 1) : emptyKeys : null;
            List<NameKey> tailKeys1 = key == maxKey ? !keys1.isEmpty() ? List_.right(keys1, 1) : emptyKeys : null;
            return list(prefix1, tailKeys0, tailKeys1);
        } else
            return Read.each(keyUtil.toName(prefix1));
    });
}
Also used : Bytes(suite.primitive.Bytes) NameKey(suite.fs.impl.FileSystemKeyUtil.NameKey)

Aggregations

NameKey (suite.fs.impl.FileSystemKeyUtil.NameKey)2 Bytes (suite.primitive.Bytes)2