emory/chunk/map: move chunking to a free function
This commit is contained in:
parent
66ec824b44
commit
db6c4f54a2
@ -16,13 +16,17 @@ using emory::chunk::map;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
map::map (
|
||||
cruft::view<u08 const *> src,
|
||||
template <typename HashT, typename OutputT>
|
||||
static
|
||||
OutputT
|
||||
find_chunks (
|
||||
OutputT &&dst,
|
||||
cruft::view<u08 const*> src,
|
||||
emory::chunk::params const &p
|
||||
) {
|
||||
using hash_type = cruft::hash::buzhash<u64>;
|
||||
if (src.size () < p.window)
|
||||
return;
|
||||
return dst;
|
||||
|
||||
using digest_type = hash_type::digest_type ;
|
||||
digest_type const mask = ~digest_type (0) >> (sizeof (digest_type) * 8 - p.bits);
|
||||
@ -46,13 +50,13 @@ map::map (
|
||||
|
||||
cruft::view<u08 const*> const region { start, cursor };
|
||||
|
||||
elements.push_back ({
|
||||
*dst = {
|
||||
.offset = {
|
||||
std::distance (src.begin (), start),
|
||||
std::distance (src.begin (), cursor)
|
||||
},
|
||||
.digest = static_hash {} (region)
|
||||
});
|
||||
.digest = HashT {} (region)
|
||||
};
|
||||
|
||||
start = cursor;
|
||||
break;
|
||||
@ -62,12 +66,22 @@ map::map (
|
||||
if (start != src.end ()) {
|
||||
cruft::view<u08 const*> const region { start, src.end () };
|
||||
|
||||
elements.push_back ({
|
||||
*dst++ = {
|
||||
.offset = {
|
||||
std::distance (src.begin (), start),
|
||||
std::distance (src.begin (), src.end ())
|
||||
},
|
||||
.digest = static_hash {} (region)
|
||||
});
|
||||
.digest = HashT {} (region)
|
||||
};
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
map::map (
|
||||
cruft::view<u08 const *> src,
|
||||
emory::chunk::params const &p
|
||||
) {
|
||||
::find_chunks<static_hash> (std::back_inserter (elements), src, p);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user