File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -450,6 +450,33 @@ std::size_t irept::hash() const
450450 return result;
451451}
452452
453+ std::size_t irept::string_hash () const
454+ {
455+ const irept::subt &sub = get_sub ();
456+ const irept::named_subt &named_sub = get_named_sub ();
457+
458+ std::size_t result = hash_string (id2string (id ()));
459+
460+ for (const auto &irep : sub)
461+ result = hash_combine (result, irep.string_hash ());
462+
463+ std::size_t number_of_named_ireps = 0 ;
464+
465+ for (const auto &irep_entry : named_sub)
466+ {
467+ if (!is_comment (irep_entry.first )) // this variant ignores comments
468+ {
469+ result = hash_combine (result, hash_string (id2string (irep_entry.first )));
470+ result = hash_combine (result, irep_entry.second .string_hash ());
471+ number_of_named_ireps++;
472+ }
473+ }
474+
475+ result = hash_finalize (result, sub.size () + number_of_named_ireps);
476+
477+ return result;
478+ }
479+
453480std::size_t irept::full_hash () const
454481{
455482 const irept::subt &sub=get_sub ();
Original file line number Diff line number Diff line change @@ -452,6 +452,12 @@ class irept
452452
453453 std::size_t hash () const ;
454454 std::size_t full_hash () const ;
455+ // / Compute hash value while hashing the actual string content instead of
456+ // / string indices. These hash values remain stable even when the string
457+ // / container is built in a different order. Note that this can be much slower
458+ // / than using `hash()` as string lookups are required, strings need to be
459+ // / iterated over, and the results are not cached.
460+ std::size_t string_hash () const ;
455461
456462 bool full_eq (const irept &other) const ;
457463
You can’t perform that action at this time.
0 commit comments