| 23 | #include "fdbclient/NativeAPI.actor.h" |
| 24 | |
| 25 | KeyRef keyBetween(const KeyRangeRef& keys) { |
| 26 | int pos = 0; // will be the position of the first difference between keys.begin and keys.end |
| 27 | int minSize = std::min(keys.begin.size(), keys.end.size()); |
| 28 | for (; pos < minSize && pos < CLIENT_KNOBS->SPLIT_KEY_SIZE_LIMIT; pos++) { |
| 29 | if (keys.begin[pos] != keys.end[pos]) { |
| 30 | return keys.end.substr(0, pos + 1); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | // If one more character keeps us in the limit, and the latter key is simply |
| 35 | // longer, then we only need one more byte of the end string. |
| 36 | if (pos < CLIENT_KNOBS->SPLIT_KEY_SIZE_LIMIT && keys.begin.size() < keys.end.size()) { |
| 37 | return keys.end.substr(0, pos + 1); |
| 38 | } |
| 39 | |
| 40 | return keys.end; |
| 41 | } |
| 42 | |
| 43 | void KeySelectorRef::setKey(KeyRef const& key) { |
| 44 | // There are no keys in the database with size greater than the max key size, so if this key selector has a key |