本文整理汇总了C++中leveldb::Slice类的典型用法代码示例。如果您正苦于以下问题:C++ Slice类的具体用法?C++ Slice怎么用?C++ Slice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Slice类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:Mumujane,项目名称:ssdb,代码行数:7,代码来源:binlog.cpp
示例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));
}
开发者ID:dolfly,项目名称:ssdb,代码行数:7,代码来源:binlog.cpp
示例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;
}
开发者ID:LngMH,项目名称:phxpaxos,代码行数:27,代码来源:db.cpp
示例4: Put
virtual void Put(const leveldb::Slice& key, const leveldb::Slice& value) {
if (key.ToString() == needle) {
foundEntry = true;
*deleted = false;
*foundValue = value.ToString();
}
}
开发者ID:Azotroph,项目名称:current,代码行数:7,代码来源:txdb-leveldb.cpp
示例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;
}
开发者ID:Mumujane,项目名称:ssdb,代码行数:8,代码来源:binlog.cpp
示例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());
}
开发者ID:xcodecraft,项目名称:qssdb,代码行数:8,代码来源:binlog.cpp
示例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);
}
开发者ID:favioflamingo,项目名称:libbitcoin,代码行数:9,代码来源:leveldb_blockchain.cpp
示例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;
}
开发者ID:bjmgeek,项目名称:plyvel,代码行数:56,代码来源:comparator.cpp
示例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);
}
开发者ID:favioflamingo,项目名称:libbitcoin,代码行数:11,代码来源:leveldb_blockchain.cpp
示例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;
}
开发者ID:Alex223124,项目名称:COS513-Finance,代码行数:11,代码来源:leveldb_kmedoids.cpp
示例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;
}
开发者ID:tencent-wechat,项目名称:phxsql,代码行数:13,代码来源:event_index.cpp
示例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;
}
开发者ID:NICTA,项目名称:obsidian,代码行数:7,代码来源:db.cpp
示例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);
}
}
}
开发者ID:DengzhiLiu,项目名称:tair,代码行数:30,代码来源:ldb_comparator.cpp
示例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);
}
开发者ID:Alex223124,项目名称:COS513-Finance,代码行数:8,代码来源:leveldb_kmedoids.cpp
示例15: Delete
virtual void Delete(const leveldb::Slice& key)
{
if (key.ToString() == needle)
{
foundEntry = true;
*deleted = true;
};
};
开发者ID:KOJIFENG,项目名称:SkullBuzz,代码行数:8,代码来源:richlistdb.cpp
示例16: iter
void
persistence_leveldb::retrieve (es::storage& es)
{
std::unique_ptr<leveldb::Iterator> iter (db_->NewIterator(leveldb::ReadOptions()));
uint32_t start_key[2];
start_key[0] = type_entity;
start_key[1] = 0;
uint32_t end_key[2];
end_key[0] = type_entity;
end_key[1] = 0xffffffff;
leveldb::Slice start (reinterpret_cast<const char*>(start_key), sizeof(start_key));
leveldb::Slice end (reinterpret_cast<const char*>(end_key), sizeof(end_key));
for (iter->Seek(start);
iter->Valid() && options_.comparator->Compare(iter->key(), end) <= 0;
iter->Next())
{
const leveldb::Slice value (iter->value());
if (value.empty())
{
continue;
}
const leveldb::Slice key (iter->key());
const uint32_t entity (*reinterpret_cast<const uint32_t*>(key.data() + 4));
es.deserialize(es.make(entity), { value.data(), value.data() + value.size() });
}
}
开发者ID:friederschueler,项目名称:hexahedra,代码行数:31,代码来源:persistence_leveldb.cpp
示例17: Put
void MojDbLevelTableTxn::Put(const leveldb::Slice& key,
const leveldb::Slice& val)
{
// populate local view
std::string keyStr = key.ToString();
m_pendingValues[keyStr] = val.ToString();
m_pendingDeletes.erase(keyStr); // if hidden before
// notify all iterators
for(std::set<MojDbLevelTxnIterator*>::const_iterator i = m_iterators.begin();
i != m_iterators.end();
++i)
{
(*i)->notifyPut(key);
}
}
开发者ID:KyleMaas,项目名称:db8,代码行数:18,代码来源:MojDbLevelTxn.cpp
示例18: set_centroid
void set_centroid(leveldb::DB* work_db, const leveldb::Slice& key,
int oldc, int newc, int K) {
if (oldc == newc) return;
auto rawkey = key.ToString();
auto keystr = get_centroid_prefix(-1, K) + rawkey;
CHECK_OK(work_db->Put({}, key, std::to_string(newc)));
CHECK_OK(work_db->Delete({}, get_centroid_prefix(oldc, K) + rawkey));
CHECK_OK(work_db->Put({}, get_centroid_prefix(newc, K) + rawkey, key));
}
开发者ID:Alex223124,项目名称:COS513-Finance,代码行数:9,代码来源:leveldb_kmedoids.cpp
示例19: lookup
static void lookup(leveldb::DB* db, const leveldb::Slice& key, GDELTMini& val) {
std::string strval;
leveldb::Status status = db->Get({}, key, &strval);
if (status.IsNotFound()) {
std::cerr << "Key " << key.ToString() << " not found." << std::endl;
}
CHECK_OK(status);
std::stringstream sstr;
sstr.str(std::move(strval));
sstr >> val;
}
开发者ID:Alex223124,项目名称:COS513-Finance,代码行数:11,代码来源:leveldb_kmedoids.cpp
示例20: parse_one_key
bool LdbLogsReader::parse_one_key(int32_t type, leveldb::Slice& key)
{
bool ret = leveldb::GetLengthPrefixedSlice(last_log_record_, &key);
log_debug("@@ parse key ret : %d", ret);
if (ret && filter_ != NULL && filter_->ok(type, key, last_sequence_))
{
// skip this key
key.clear();
}
return ret;
}
开发者ID:solitaire2015,项目名称:Nair,代码行数:11,代码来源:ldb_define.cpp
注:本文中的leveldb::Slice类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论