# Hash Combining

`hash.h` is a tiny variadic hash-combining utility, used wherever a custom `std::hash` specialization or hash functor needs to combine several fields into one hash value - e.g. [the netlist evaluation context](rpnevalctx.md)'s `MCData::GeneratorIdHash`, `Id`'s `std::pair<Id, Id>` specialization (see [Identifiers](identifier.md)), and KLU matrix indexing. It has no `.cpp` counterpart - everything is a template, defined inline.

`hash_combine(seed, val)` is the actual mixing step: `seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed<<6) + (seed>>2)`, the widely used Boost-style combiner. The constant `0x9e3779b9` is the golden ratio's fractional bits in fixed point, chosen so the shift-and-add spreads bit changes across the whole seed - a plain XOR alone would collide too easily when combining values that individually hash close together.

The `hash_val()` overload set is a small variadic recursion: the multi-argument overload folds the first value into `seed` via `hash_combine()` and recurses on the rest, bottoming out at a single-argument overload; a top-level overload with no `seed` parameter starts one at `0` and returns the combined result. This lets a caller write `hash_val(a, b, c)` for an ad hoc multi-field hash instead of manually seeding and chaining `hash_combine()` calls itself.
