Kevacoin source tree
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.1 KiB

// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include <algorithm>
#include <stdint.h>
#include "leveldb/comparator.h"
#include "leveldb/slice.h"
#include "port/port.h"
#include "util/logging.h"
namespace leveldb {
Comparator::~Comparator() { }
namespace {
class BytewiseComparatorImpl : public Comparator {
public:
BytewiseComparatorImpl() { }
virtual const char* Name() const {
return "leveldb.BytewiseComparator";
}
virtual int Compare(const Slice& a, const Slice& b) const {
return a.compare(b);
}
virtual void FindShortestSeparator(
std::string* start,
const Slice& limit) const {
// Find length of common prefix
size_t min_length = std::min(start->size(), limit.size());
size_t diff_index = 0;
while ((diff_index < min_length) &&
((*start)[diff_index] == limit[diff_index])) {
diff_index++;
}
if (diff_index >= min_length) {
// Do not shorten if one string is a prefix of the other
} else {
uint8_t diff_byte = static_cast<uint8_t>((*start)[diff_index]);
if (diff_byte < static_cast<uint8_t>(0xff) &&
diff_byte + 1 < static_cast<uint8_t>(limit[diff_index])) {
(*start)[diff_index]++;
start->resize(diff_index + 1);
assert(Compare(*start, limit) < 0);
}
}
}
virtual void FindShortSuccessor(std::string* key) const {
// Find first character that can be incremented
size_t n = key->size();
for (size_t i = 0; i < n; i++) {
const uint8_t byte = (*key)[i];
if (byte != static_cast<uint8_t>(0xff)) {
(*key)[i] = byte + 1;
key->resize(i+1);
return;
}
}
// *key is a run of 0xffs. Leave it alone.
}
};
} // namespace
Squashed 'src/leveldb/' changes from ae6c262..a02ddf9 a02ddf9 Added GNU/kFreeBSD kernel name (TARGET_OS) 8487468 CondVar::SignalAll was broken, leading to deadlocks on Windows builds. http://code.google.com/p/leveldb/issues/detail?id=149 f6d84d1 Allow files to be opened for reading multiple times cb8e3f7 Checking whether closing succeeds d5317e8 Print actual Win32 error that occurred on file creation failure. 907f308 Port leveldb to MinGW32 9def2bf Mingw support for Windows LevelDB port 0a7b074 Pre-Vista leveldb::port::InitOnce implementation 31a2b09 Native Windows LevelDB port 058a035 Remove Snappy support 5bd76dc Release leveldb 1.12 7b094f1 Release leveldb 1.11 28dad91 Release leveldb 1.10 514c943 Make DB::Open fail if sst files are missing. d84c825 Fix corruption bug found and analyzed by dhruba@gmail.com ea2e919 added utility to dump leveldb files REVERT: ae6c262 Merge branch 'leveldb' into ripple-fork REVERT: 28fa222 Looks like a bit more delay is needed to smooth the latency. REVERT: a18f3e6 Tidy up JobQueue, add ripple_core module REVERT: ab82e57 Release leveldb 1.12 REVERT: 02c6259 Release leveldb 1.11 REVERT: 5bbb544 Rate limit compactions with a 25ms pause after each complete file. REVERT: 8c29c47 LevelDB issue 178 fix: cannot resize a level 0 compaction set REVERT: 18b245c Added GNU/kFreeBSD kernel name (TARGET_OS) REVERT: 8be9d12 CondVar::SignalAll was broken, leading to deadlocks on Windows builds. http://code.google.com/p/leveldb/issues/detail?id=149 REVERT: c9fc070 Upgrade LevelDB to 1.10.0, mostly for better write stall logging. REVERT: 8215b15 Tweak to variable name to support unity build REVERT: aca1ffc Allow files to be opened for reading multiple times REVERT: 693a70c Checking whether closing succeeds REVERT: 0144d04 Print actual Win32 error that occurred on file creation failure. REVERT: 43ed517 Fix corruption bug found and analyzed by dhruba@gmail.com REVERT: 413c74c added utility to dump leveldb files REVERT: 96eda85 Port leveldb to MinGW32 REVERT: 0967260 Mingw support for Windows LevelDB port REVERT: ee3f9bd Pre-Vista leveldb::port::InitOnce implementation REVERT: f5d0a41 Native Windows LevelDB port REVERT: 28b35f1 Remove Snappy support git-subtree-dir: src/leveldb git-subtree-split: a02ddf9b14d145e88185ee209ab8b01d8826663a
12 years ago
static port::OnceType once = LEVELDB_ONCE_INIT;
static const Comparator* bytewise;
static void InitModule() {
bytewise = new BytewiseComparatorImpl;
}
const Comparator* BytewiseComparator() {
Squashed 'src/leveldb/' changes from ae6c262..a02ddf9 a02ddf9 Added GNU/kFreeBSD kernel name (TARGET_OS) 8487468 CondVar::SignalAll was broken, leading to deadlocks on Windows builds. http://code.google.com/p/leveldb/issues/detail?id=149 f6d84d1 Allow files to be opened for reading multiple times cb8e3f7 Checking whether closing succeeds d5317e8 Print actual Win32 error that occurred on file creation failure. 907f308 Port leveldb to MinGW32 9def2bf Mingw support for Windows LevelDB port 0a7b074 Pre-Vista leveldb::port::InitOnce implementation 31a2b09 Native Windows LevelDB port 058a035 Remove Snappy support 5bd76dc Release leveldb 1.12 7b094f1 Release leveldb 1.11 28dad91 Release leveldb 1.10 514c943 Make DB::Open fail if sst files are missing. d84c825 Fix corruption bug found and analyzed by dhruba@gmail.com ea2e919 added utility to dump leveldb files REVERT: ae6c262 Merge branch 'leveldb' into ripple-fork REVERT: 28fa222 Looks like a bit more delay is needed to smooth the latency. REVERT: a18f3e6 Tidy up JobQueue, add ripple_core module REVERT: ab82e57 Release leveldb 1.12 REVERT: 02c6259 Release leveldb 1.11 REVERT: 5bbb544 Rate limit compactions with a 25ms pause after each complete file. REVERT: 8c29c47 LevelDB issue 178 fix: cannot resize a level 0 compaction set REVERT: 18b245c Added GNU/kFreeBSD kernel name (TARGET_OS) REVERT: 8be9d12 CondVar::SignalAll was broken, leading to deadlocks on Windows builds. http://code.google.com/p/leveldb/issues/detail?id=149 REVERT: c9fc070 Upgrade LevelDB to 1.10.0, mostly for better write stall logging. REVERT: 8215b15 Tweak to variable name to support unity build REVERT: aca1ffc Allow files to be opened for reading multiple times REVERT: 693a70c Checking whether closing succeeds REVERT: 0144d04 Print actual Win32 error that occurred on file creation failure. REVERT: 43ed517 Fix corruption bug found and analyzed by dhruba@gmail.com REVERT: 413c74c added utility to dump leveldb files REVERT: 96eda85 Port leveldb to MinGW32 REVERT: 0967260 Mingw support for Windows LevelDB port REVERT: ee3f9bd Pre-Vista leveldb::port::InitOnce implementation REVERT: f5d0a41 Native Windows LevelDB port REVERT: 28b35f1 Remove Snappy support git-subtree-dir: src/leveldb git-subtree-split: a02ddf9b14d145e88185ee209ab8b01d8826663a
12 years ago
port::InitOnce(&once, InitModule);
return bytewise;
}
} // namespace leveldb