| 64 | size_t DBmemory::get_approximate_items_count() const { return storage.size(); } |
| 65 | |
| 66 | DBmemory::Cursor::Cursor(DBmemory *db, const std::string &prefix, const std::string &middle, bool forward) |
| 67 | : db(db), prefix(prefix), forward(forward) { |
| 68 | std::string start = prefix + middle; |
| 69 | std::string finish = start; |
| 70 | if (finish.size() < db->max_key_size) |
| 71 | finish += std::string(db->max_key_size - finish.size(), char(0xff)); // char('~') |
| 72 | if (forward) |
| 73 | it = db->storage.lower_bound(start); |
| 74 | else { |
| 75 | it = db->storage.upper_bound(finish); |
| 76 | if (it == db->storage.begin()) |
| 77 | it = db->storage.end(); |
| 78 | else |
| 79 | --it; |
| 80 | } |
| 81 | check_prefix(); |
| 82 | } |
| 83 | |
| 84 | void DBmemory::Cursor::check_prefix() { |
| 85 | if (it == db->storage.end()) |