MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / rapidHash

Method rapidHash

lib/common/hash.cpp:38–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36namespace WasmEdge::Hash {
37
38WASMEDGE_EXPORT uint64_t Hash::rapidHash(Span<const std::byte> Data) noexcept {
39 uint64_t Seed = RandomSeed;
40 Seed ^= rapidMix(Seed ^ Secret[2], Secret[1]);
41 uint64_t A = 0, B = 0;
42 if (likely(Data.size() <= 16)) {
43 if (Data.size() >= 4) {
44 Seed ^= Data.size();
45 if (Data.size() >= 8) {
46 A = read(Data.first<8>());
47 B = read(Data.last<8>());
48 } else {
49 A = read(Data.first<4>());
50 B = read(Data.last<4>());
51 }
52 } else if (Data.size() > 0) {
53 A = (static_cast<uint64_t>(Data[0]) << 45) |
54 static_cast<uint64_t>(Data[Data.size() - 1]);
55 B = static_cast<uint64_t>(Data[Data.size() >> 1]);
56 } else {
57 A = B = 0;
58 }
59 } else {
60 if (Data.size() > 48) {
61 uint64_t See1 = Seed, See2 = Seed;
62 do {
63 Seed = rapidMix(read(Data.first<8>()) ^ Secret[0],
64 read(Data.subspan<8>().first<8>()) ^ Seed);
65 See1 = rapidMix(read(Data.subspan<16>().first<8>()) ^ Secret[1],
66 read(Data.subspan<24>().first<8>()) ^ See1);
67 See2 = rapidMix(read(Data.subspan<32>().first<8>()) ^ Secret[2],
68 read(Data.subspan<40>().first<8>()) ^ See2);
69 Data = Data.subspan<48>();
70 } while (Data.size() > 48);
71 Seed ^= See1;
72 Seed ^= See2;
73 }
74 if (Data.size() > 16) {
75 Seed = rapidMix(read(Data.first<8>()) ^ Secret[2],
76 read(Data.subspan<8>().first<8>()) ^ Seed);
77 if (Data.size() > 32) {
78 Seed = rapidMix(read(Data.subspan<16>().first<8>()) ^ Secret[2],
79 read(Data.subspan<24>().first<8>()) ^ Seed);
80 }
81 }
82 A = read(Data.last<16>().first<8>()) ^ Data.size();
83 B = read(Data.last<8>());
84 }
85 A ^= Secret[1];
86 B ^= Seed;
87 rapidMum(A, B);
88 return rapidMix(A ^ Secret[3], B ^ Secret[1] ^ Data.size());
89}
90
91} // namespace WasmEdge::Hash

Callers

nothing calls this directly

Calls 5

rapidMixFunction · 0.85
readFunction · 0.85
rapidMumFunction · 0.85
likelyFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected