MCPcopy Create free account
hub / github.com/apache/tvm-ffi / HashMapBase

Method HashMapBase

src/ffi/extra/structural_hash.cc:286–318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

284 }
285
286 uint64_t HashMapBase(const MapBaseObj* map) {
287 // Compute a deterministic hash value for the map.
288 uint64_t hash_value = details::StableHashCombine(map->GetTypeKeyHash(), map->size());
289 std::vector<std::pair<uint64_t, Any>> items;
290 for (const auto& [key, value] : *map) {
291 // if we cannot find order independent hash, we skip the key
292 if (auto hash_key = FindOrderIndependentHash(key)) {
293 items.emplace_back(*hash_key, value);
294 }
295 }
296 // sort the items by the hash key, so the hash value is deterministic
297 // and independent of the order of insertion
298 std::sort(items.begin(), items.end(),
299 [](const auto& a, const auto& b) { return a.first < b.first; });
300
301 for (size_t i = 0; i < items.size();) {
302 size_t k = i + 1;
303 for (; k < items.size() && items[k].first == items[i].first; ++k) {
304 }
305 // detect ties, which are rare, but we need to skip value hash during ties
306 // to make sure that the hash value is deterministic.
307 if (k == i + 1) {
308 // no ties, we just hash the key and value
309 hash_value = details::StableHashCombine(hash_value, items[i].first);
310 hash_value = details::StableHashCombine(hash_value, HashAny(items[i].second));
311 } else {
312 // ties occur, we skip the value hash to make sure that the hash value is deterministic.
313 hash_value = details::StableHashCombine(hash_value, items[i].first);
314 }
315 i = k;
316 }
317 return hash_value;
318 }
319
320 // NOLINTNEXTLINE(performance-unnecessary-value-param)
321 uint64_t HashShape(Shape shape) {

Callers

nothing calls this directly

Calls 6

StableHashCombineFunction · 0.85
GetTypeKeyHashMethod · 0.80
sizeMethod · 0.45
emplace_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected