我需要一个像prefixSubMap of MapDB这样的函数。Xodus有这样的功能吗?我找不到接口。
https://jankotek.gitbooks.io/mapdb/content/btreemap/composite-keys.html
prefixSubMap
发布于 2018-02-12 09:21:41
没有这样的函数,但是您可以使用环境API来完成这项工作。如果您有Transaction txn、Store store和ByteIterable keyPrefix,那么枚举键以keyPrefix开头的键/值对如下所示:
int prefixLen = keyPrefix.getLength();
try (Cursor cursor = store.openCursor(txn)) {
if (cursor.getSearchKeyRange(keyPrefix) != null) {
do {
ByteIterable key = cursor.getKey();
// check if the key starts with keyPrefix
int keyLen = key.getLength();
if (keyLen < prefixLen ||
ByteIterableUtil.compare(keyPrefix, key.subIterable(0, prefixLen)) != 0) {
break;
}
// wanted key/value pair is here
ByteIterable value = cursor.getValue();
...
} while(cursor.getNext());
}
}发布于 2018-02-09 18:57:31
我发现了store.openCursor()和cursor.getSearchKey()。
https://stackoverflow.com/questions/48708984
复制相似问题