本文整理汇总了C++中hash_table::find_block方法的典型用法代码示例。如果您正苦于以下问题:C++ hash_table::find_block方法的具体用法?C++ hash_table::find_block怎么用?C++ hash_table::find_block使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hash_table
的用法示例。
在下文中一共展示了hash_table::find_block方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_and_delta
void read_and_delta (file_reader & reader
, xdelta_stream & stream
, const hash_table & hashes
, std::set<hole_t> & hole_set
, const int blk_len
, bool need_split_hole)
{
bool adddiff = !need_split_hole;
char_buffer<uchar_t> buf (XDELTA_BUFFER_LEN);
typedef std::set<hole_t>::iterator it_t;
std::list<hole_t> holes2remove;
for (it_t begin = hole_set.begin (); begin != hole_set.end (); ++begin) {
const hole_t & hole = *begin;
uint64_t offset = reader.seek_file (hole.offset, FILE_BEGIN);
if (offset != hole.offset) {
std::string errmsg = fmt_string ("Can't seek file %s(%s)."
, reader.get_fname ().c_str (), error_msg ().c_str ());
THROW_XDELTA_EXCEPTION (errmsg);
}
uint32_t buflen = XDELTA_BUFFER_LEN;
uint32_t to_read_bytes = (uint32_t)hole.length;
buflen = to_read_bytes > buflen ? buflen : to_read_bytes;
uchar_t * rdbuf = buf.begin ();
uint32_t size = reader.read_file (rdbuf, buflen);
if (size != buflen) {
std::string errmsg = fmt_string ("Can't read file %s(%s)."
, reader.get_fname ().c_str (), error_msg ().c_str ());
THROW_XDELTA_EXCEPTION (errmsg);
}
to_read_bytes -= size;
const uchar_t * endbuf = rdbuf + size;
rdbuf = buf.begin ();
if ((int32_t)(endbuf - rdbuf) >= blk_len) {
uchar_t * sentrybuf = rdbuf;
rolling_hasher hasher;
hasher.eat_hash (rdbuf, blk_len);
while (true) {
bool newhash = false;
const slow_hash * bsh = hashes.find_block (hasher.hash_value (), rdbuf, blk_len);
uchar_t outchar = 0;
if (bsh) {
// a match was found.
uint32_t slipsize = (uint32_t)(rdbuf - sentrybuf);
if (slipsize > 0 && adddiff)
stream.add_block (sentrybuf, slipsize, offset);
offset += slipsize;
stream.add_block (bsh->tpos, blk_len, offset);
if (need_split_hole) {
hole_t newhole;
newhole.offset = offset;
newhole.length = blk_len;
holes2remove.push_back (newhole);
}
rdbuf += blk_len;
sentrybuf = rdbuf;
newhash = true;
offset += blk_len;
}
else {
// slip the window by one bytes which size is blk_len.
outchar = *rdbuf;
++rdbuf;
}
//
// beyond the buffer.
int remain = (int)(endbuf - rdbuf);
if (remain < blk_len) {
if (to_read_bytes == 0) {
// no more to read.
uint32_t slipsize = (uint32_t)(endbuf - sentrybuf);
if (slipsize > 0 && adddiff)
stream.add_block (sentrybuf, slipsize, offset);
goto end;
}
else {
memmove (buf.begin (), rdbuf, remain);
rdbuf = buf.begin ();
sentrybuf = rdbuf;
buflen = XDELTA_BUFFER_LEN - remain;
buflen = to_read_bytes > buflen ? buflen : to_read_bytes;
size = reader.read_file (rdbuf + remain, buflen);
if (size != buflen) {
std::string errmsg = fmt_string ("Can't read file %s(%s)."
, reader.get_fname ().c_str (), error_msg ().c_str ());
THROW_XDELTA_EXCEPTION (errmsg);
}
//.........这里部分代码省略.........