Discussion:
can I retrieve the actual matching key with Get()
Scott Kolodzieski
10 years ago
Permalink
My comparator is quite specialized, as there is relevant daya stored in the
key, that is not part of the KEY proper.

When I do a get an pass a key, I would like to get both the KEY and VALUE
in the db, not just the value. It seems that there is an assumption that
when you pass a key, it does not need to be returned, but when two keys can
match that are bot byte-for-byte compatible, this leaves one with just the
value, and not the KEY of the looked up data.

Thanks.
--
You received this message because you are subscribed to the Google Groups "leveldb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leveldb+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Sanjay Ghemawat' via leveldb
10 years ago
Permalink
Post by Scott Kolodzieski
My comparator is quite specialized, as there is relevant daya stored in the
key, that is not part of the KEY proper.
When I do a get an pass a key, I would like to get both the KEY and VALUE in
the db, not just the value. It seems that there is an assumption that when
you pass a key, it does not need to be returned, but when two keys can match
that are bot byte-for-byte compatible, this leaves one with just the value,
and not the KEY of the looked up data.
Instead of using Get, you can use an iterator:
auto iter = db->NewIterator(...);
iter->Seek(key);
if (iter->Valid() && your_comparator->Compare(key, iter->key()) == 0) {
Use iter->key() and iter->value()
}
delete iter;

PS. you probably already saw this, but if you have a special comparator which
ignores some key bytes and are also using filter policies, you need to implement
your own FilterPolicy instead of using NewBloomFilterPolicy:

// Note: if you are using a custom comparator that ignores some parts
// of the keys being compared, you must not use NewBloomFilterPolicy()
// and must provide your own FilterPolicy that also ignores the
// corresponding parts of the keys. For example, if the comparator
// ignores trailing spaces, it would be incorrect to use a
// FilterPolicy (like NewBloomFilterPolicy) that does not ignore
// trailing spaces in keys.
extern const FilterPolicy* NewBloomFilterPolicy(int bits_per_key);
--
You received this message because you are subscribed to the Google Groups "leveldb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leveldb+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...