本文整理汇总了C++中leveldb::Slice类的典型用法代码示例。如果您正苦于以下问题:C++ Slice类的具体用法?C++ Slice怎么用?C++ Slice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Slice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
int Binlog::load(const leveldb::Slice &s){
if(s.size() < HEADER_LEN){
return -1;
}
buf.assign(s.data(), s.size());
return 0;
}
示例2: sizeof
Binlog::Binlog(uint64_t seq, char type, char cmd, const leveldb::Slice &key, int64_t ttl){
buf.append((char *)(&seq), sizeof(uint64_t));
buf.push_back(type);
buf.push_back(cmd);
buf.append(key.data(), key.size());
buf.append(reinterpret_cast<char*>(&ttl), sizeof(ttl));
}
示例3: PCompare
int PaxosComparator :: PCompare(const leveldb::Slice & a, const leveldb::Slice & b)
{
if (a.size() != sizeof(uint64_t))
{
NLErr("assert a.size %zu b.size %zu", a.size(), b.size());
assert(a.size() == sizeof(uint64_t));
}
if (b.size() != sizeof(uint64_t))
{
NLErr("assert a.size %zu b.size %zu", a.size(), b.size());
assert(b.size() == sizeof(uint64_t));
}
uint64_t lla = 0;
uint64_t llb = 0;
memcpy(&lla, a.data(), sizeof(uint64_t));
memcpy(&llb, b.data(), sizeof(uint64_t));
if (lla == llb)
{
return 0;
}
return lla < llb ? -1 : 1;
}
示例4: Put
virtual void Put(const leveldb::Slice& key, const leveldb::Slice& value) {
if (key.ToString() == needle) {
foundEntry = true;
*deleted = false;
*foundValue = value.ToString();
}
}
示例5: decode_seq_key
static inline uint64_t decode_seq_key(const leveldb::Slice &key){
uint64_t seq = 0;
if(key.size() == (sizeof(uint64_t) + 1) && key.data()[0] == DataType::SYNCLOG){
seq = *((uint64_t *)(key.data() + 1));
seq = big_endian(seq);
}
return seq;
}
示例6: sizeof
Binlog::Binlog(uint64_t seq, char type, char cmd, const leveldb::Slice &key, const leveldb::Slice &val){
buf.append((char *)(&seq), sizeof(uint64_t));
buf.push_back(type);
buf.push_back(cmd);
buf.append(key.data(), key.size());
val_buf.append(val.data(), val.size());
}
示例7: load_checksum
void load_checksum(leveldb::Slice key)
{
const uint8_t* begin = slice_begin(key.data());
const uint8_t* end = begin + key.size();
BITCOIN_ASSERT(key.size() == 1 + short_hash_size + 8);
auto deserial = make_deserializer(begin + 1 + short_hash_size, end);
checksum_ = deserial.read_8_bytes();
BITCOIN_ASSERT(deserial.iterator() == end);
}
示例8: Compare
int Compare(const leveldb::Slice& a, const leveldb::Slice& b) const
{
int ret;
PyObject* bytes_a;
PyObject* bytes_b;
PyObject* compare_result;
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
/* Create two Python byte strings */
bytes_a = PyBytes_FromStringAndSize(a.data(), a.size());
bytes_b = PyBytes_FromStringAndSize(b.data(), b.size());
if ((bytes_a == NULL) || (bytes_b == NULL)) {
PyErr_Print();
std::cerr << "FATAL ERROR: Plyvel comparator could not allocate byte strings" << std::endl;
std::cerr << "Aborting to avoid database corruption..." << std::endl;
abort();
}
/* Invoke comparator callable */
compare_result = PyObject_CallFunctionObjArgs(comparator, bytes_a, bytes_b, 0);
if (compare_result == NULL) {
PyErr_Print();
std::cerr << "FATAL ERROR: Exception raised from custom Plyvel comparator" << std::endl;
std::cerr << "Aborting to avoid database corruption..." << std::endl;
abort();
}
/* The comparator callable can return any Python object. Compare it
* to our "0" value to get a -1, 0, or 1 for LevelDB. */
if (PyObject_RichCompareBool(compare_result, zero, Py_GT) == 1) {
ret = 1;
} else if (PyObject_RichCompareBool(compare_result, zero, Py_LT) == 1) {
ret = -1;
} else {
ret = 0;
}
if (PyErr_Occurred()) {
PyErr_Print();
std::cerr << "FATAL ERROR: Exception raised while comparing custom Plyvel comparator result with 0" << std::endl;
std::cerr << "Aborting to avoid database corruption..." << std::endl;
abort();
}
Py_DECREF(compare_result);
Py_DECREF(bytes_a);
Py_DECREF(bytes_b);
PyGILState_Release(gstate);
return ret;
}
示例9: load_data
void load_data(leveldb::Slice data)
{
const uint8_t* begin = slice_begin(data.data());
const uint8_t* end = begin + data.size();
BITCOIN_ASSERT(data.size() == 36 + 4);
auto deserial = make_deserializer(begin, end);
inpoint_.hash = deserial.read_hash();
inpoint_.index = deserial.read_4_bytes();
height_ = deserial.read_4_bytes();
BITCOIN_ASSERT(deserial.iterator() == end);
}
示例10: uniform_init
static std::vector<std::string> uniform_init(const leveldb::Slice& begin,
const leveldb::Slice& end,
int K, int prefix_len = 0) {
auto ibegin = std::stoull(begin.ToString().substr(prefix_len));
auto iend = std::stoull(end.ToString().substr(prefix_len));
std::vector<std::string> ret(K);
for (auto i = ibegin; i < iend; i += (iend - ibegin) / K) {
ret.push_back(begin.ToString().substr(0, prefix_len) + std::to_string(i));
}
return ret;
}
示例11: Compare
int EventComparator::Compare(const leveldb::Slice &a, const leveldb::Slice &b) const {
pair < string, size_t > key1 = GtidHandler::ParseGTID(a.ToString());
pair < string, size_t > key2 = GtidHandler::ParseGTID(b.ToString());
if (key1.first == key2.first) {
if (key1.second == key2.second)
return 0;
return key1.second < key2.second ? -1 : 1;
}
return key1.first < key2.first ? -1 : 1;
}
示例12: get
std::string Database::get(const leveldb::Slice& key)
{
std::string s;
leveldb::Status status = db_->Get(readOptions_, key, &s);
CHECK(status.ok()) << "key is " << key.ToString();
return s;
}
示例13: FindShortestSeparator
// skip expired time
void BitcmpLdbComparatorImpl::FindShortestSeparator(
std::string* start,
const leveldb::Slice& limit) const
{
// Find length of common prefix
size_t min_length = std::min(start->size(), limit.size());
assert(min_length > LDB_COMPARE_SKIP_SIZE);
size_t diff_index = LDB_COMPARE_SKIP_SIZE;
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);
}
}
}
示例14: get_centroid
int get_centroid(leveldb::DB* work_db, const leveldb::Slice& key, int K) {
std::string str;
auto keystr = get_centroid_prefix(-1, K) + key.ToString();
auto status = work_db->Get({}, keystr, &str);
if (status.IsNotFound()) return -1;
CHECK_OK(status);
return std::stoi(str);
}
示例15: Delete
virtual void Delete(const leveldb::Slice& key)
{
if (key.ToString() == needle)
{
foundEntry = true;
*deleted = true;
};
};