本文整理汇总了C++中leveldb::WriteBatch::Put方法的典型用法代码示例。如果您正苦于以下问题:C++ WriteBatch::Put方法的具体用法?C++ WriteBatch::Put怎么用?C++ WriteBatch::Put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类leveldb::WriteBatch
的用法示例。
在下文中一共展示了WriteBatch::Put方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeUsrDb
int IndexDbLevelDb::writeUsrDb(const map<string, SiMap>& usrFidMap, leveldb::DB* dbUsrDb, leveldb::WriteBatch& wb_usrdb, const string& dbName)
{
// lookup map
for(const auto& itr : usrFidMap) {
const string& usr = itr.first;
if(usr != "") {
SiMap file_list_map = itr.second;
#ifdef USE_USR2FILE_TABLE2
for(const auto& itr_str : file_list_map) {
wb_usrdb.Put(dbName + "|" + usr + "|" + itr_str.first, "1");
}
#else
// check if already registered
string value;
int rv = dbRead(value, dbUsrDb, dbName + "|" + usr);
if(rv == 0) {
const string delim = ",";
list<string> old_list;
boost::split(old_list, value, boost::is_any_of(delim));
for(const auto& itr_old : old_list) {
file_list_map[itr_old] = 0;
}
}
string file_list_string = "";
for(const auto& itr_str : file_list_map) {
file_list_string.append(itr_str.first+",");
}
file_list_string = file_list_string.substr(0, file_list_string.size()-1);
wb_usrdb.Put(dbName + "|" + usr, file_list_string);
#endif
}
}
return 0;
}
示例2: mark_spent_outputs
bool mark_spent_outputs(leveldb::WriteBatch& spend_batch,
const output_point& previous_output, const input_point& spent_inpoint)
{
data_chunk spent_key = create_spent_key(previous_output),
spend_value = create_spent_key(spent_inpoint);
spend_batch.Put(slice(spent_key), slice(spend_value));
return true;
}
示例3: seq_update
void c_seq::seq_update(leveldb::WriteBatch& bh)
{
m_seq_head.s_uptime(time(0));
m_seq_head.m_head.s_crc(c_crc::crc16(0,
(uint8*)&m_seq_head + sizeof(_zmsg_head),
sizeof(m_seq_head) - sizeof(_zmsg_head)));
leveldb::Slice value( (const char*)&m_seq_head, sizeof(m_seq_head) );
bh.Put(m_key, value);
}
示例4: txSave
TxId DatabaseHelper::txSave(leveldb::WriteBatch& batch, const Hash256& txHash, const DbTransaction& dbTx)
{
auto buffer = bufferTLS.get();
if (buffer == NULL)
{
bufferTLS.reset(buffer = new std::string());
}
auto index = txGetOrCreateId(txHash);
Serialize(*buffer, dbTx);
char searchKey2[1 + sizeof(TxId)];
searchKey2[0] = (uint8_t)DatabaseKeyHeader::Tx;
*(TxId*) &searchKey2[1] = swapByteOrder(index);
batch.Put(leveldb::Slice((const char*)searchKey2, sizeof(searchKey2)), *buffer);
return index;
}
示例5: Put
Status Put(const std::vector<std::pair<std::string, std::string>>& writes)
{
leveldb::WriteBatch batch;
for (auto kv : writes)
{
batch.Put(kv.first, kv.second);
}
leveldb::Status s = db->Write(leveldb::WriteOptions(), &batch);
if (s.ok())
{
return Status::OK();
}
return Status::NotFound();
}
示例6: add_credit
bool add_credit(leveldb::WriteBatch& batch,
const payment_address& address, uint64_t output_value,
const output_point& outpoint, uint32_t block_height)
{
data_chunk addr_key = create_address_key(address, outpoint);
// outpoint, value, block_height
data_chunk row_info(36 + 8 + 4);
auto serial = make_serializer(row_info.begin());
// outpoint
serial.write_hash(outpoint.hash);
serial.write_4_bytes(outpoint.index);
// value
serial.write_8_bytes(output_value);
// block_height
serial.write_4_bytes(block_height);
BITCOIN_ASSERT(
std::distance(row_info.begin(), serial.iterator()) == 36 + 8 + 4);
batch.Put(slice(addr_key), slice(row_info));
return true;
}
示例7: seq_set
void c_seq::seq_set(leveldb::WriteBatch& bh, leveldb::Slice& value)
{
uint32 keyId = m_seq_head.g_index() + 1;
m_seq_head.s_index(keyId);
m_seq_head.s_count(m_seq_head.g_count() + 1);
_zmsg_head head;
head.type = T_SEQ_VALUE;
head.s_effective(time(0));
head.s_crc(c_crc::crc16(0, (uint8*)value.data(), value.size()));
memcpy(TSEQ_BUF(), &head, sizeof(_zmsg_head));
memcpy(TSEQ_BUF() + sizeof(_zmsg_head), (void*)value.data(), value.size());
int len = sizeof(_zmsg_head) + value.size();
if (len > 0)
{
leveldb::Slice data(TSEQ_BUF(), len);
bh.Put(__tos(m_key << "@" << keyId), data);
}
}
示例8: add_debit
bool add_debit(leveldb::WriteBatch& batch,
const transaction_input_type& input, const input_point& inpoint,
uint32_t block_height)
{
payment_address address;
// Not a Bitcoin address so skip this output.
if (!extract(address, input.script))
return true;
data_chunk addr_key = create_address_key(address, input.previous_output);
// inpoint
data_chunk row_info(36 + 4);
auto serial = make_serializer(row_info.begin());
// inpoint
serial.write_hash(inpoint.hash);
serial.write_4_bytes(inpoint.index);
// block_height
serial.write_4_bytes(block_height);
BITCOIN_ASSERT(
std::distance(row_info.begin(), serial.iterator()) == 36 + 4);
batch.Put(slice(addr_key), slice(row_info));
return true;
}