MCPcopy Create free account
hub / github.com/Niko1221/Strata / hash_sampled_file

Function hash_sampled_file

engine/src/core/expert_source.cpp:6201–6232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6199}
6200
6201bool hash_sampled_file(const std::filesystem::path& path, uint64_t& h, std::string& err) {
6202 std::ifstream f(path, std::ios::binary | std::ios::ate);
6203 if (!f) {
6204 err = "ArenaExpertSource: cannot sample pack source " + path.string();
6205 return false;
6206 }
6207 const std::streamoff end = f.tellg();
6208 if (end < 0) {
6209 err = "ArenaExpertSource: cannot size pack source " + path.string();
6210 return false;
6211 }
6212 const uint64_t bytes = (uint64_t) end;
6213 hash_text(h, path.filename().string());
6214 hash_u64(h, bytes);
6215 constexpr uint64_t sample = 64u << 10;
6216 const uint64_t starts[3] = {0, bytes / 2, bytes > sample ? bytes - sample : 0};
6217 std::vector<uint8_t> buf((size_t) std::min<uint64_t>(sample, bytes));
6218 for (uint64_t off : starts) {
6219 if (buf.empty()) break;
6220 const uint64_t at = std::min<uint64_t>(off, bytes - (uint64_t) buf.size());
6221 f.clear();
6222 f.seekg((std::streamoff) at);
6223 f.read((char*) buf.data(), (std::streamsize) buf.size());
6224 if ((size_t) f.gcount() != buf.size()) {
6225 err = "ArenaExpertSource: short read while hashing pack source " + path.string();
6226 return false;
6227 }
6228 hash_u64(h, at);
6229 h = fnv1a64(buf.data(), (uint64_t) buf.size(), h);
6230 }
6231 return true;
6232}
6233
6234bool shared_arena_pack_hash(const std::string& pack_dir, const std::string& experts_path,
6235 const std::string& gguf, const strata::kernels::cpu::ExpertLayout& lay,

Callers 1

shared_arena_pack_hashFunction · 0.70

Calls 9

fnv1a64Function · 0.85
hash_textFunction · 0.70
hash_u64Function · 0.70
stringMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45
readMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected