[PR #11887] [MERGED] Introduce til::hasher for sucessive hashing of structs #28776

Open
opened 2026-01-31 09:30:41 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/11887
Author: @lhecker
Created: 12/6/2021
Status: Merged
Merged: 12/7/2021
Merged by: @undefined

Base: mainHead: dev/lhecker/til-hash


📝 Commits (7)

📊 Changes

12 files changed (+316 additions, -178 deletions)

View changed files

📝 .github/actions/spelling/expect/expect.txt (+2 -11)
📝 src/buffer/out/UnicodeStorage.hpp (+5 -6)
📝 src/buffer/out/textBuffer.cpp (+1 -1)
📝 src/cascadia/TerminalSettingsModel/ActionArgs.h (+30 -31)
📝 src/cascadia/TerminalSettingsModel/ActionArgs.idl (+2 -2)
📝 src/cascadia/TerminalSettingsModel/ActionArgsMagic.h (+52 -49)
📝 src/cascadia/TerminalSettingsModel/ActionMap.cpp (+22 -16)
📝 src/cascadia/TerminalSettingsModel/HashUtils.h (+25 -42)
📝 src/cascadia/TerminalSettingsModel/Microsoft.Terminal.Settings.ModelLib.vcxproj.filters (+1 -0)
📝 src/host/alias.cpp (+8 -11)
📝 src/host/ut_host/TextBufferTests.cpp (+9 -9)
src/inc/til/hash.h (+159 -0)

📄 Description

This commit serves two purposes:

  • Simplify construction of hashes for non-trivial structs
    This is especially helpful for ActionArgs
  • Improve hash quality by not needlessly throwing away entropy

til::hasher is modeled after Rust's std::hash::Hasher and works similar.
The idea is simple: A stateful hash function can hash multiple unrelated fields,
without loosing entropy by running a finalizer after hashing each interim field.
This is especially useful for modern hash functions, which often have a wider
internal state than the output width. Additionally this improves performance
for hash functions with complex finalizers.

Most of this is of course a bit moot right now, considering that til::hasher
is still based on STL's FNV1a algorithm, which offers a very poor hash quality.
But counterintuitively, FNV1a actually benefits most from this PR: Since it
lacks a finalizer entirely, this commit greatly improves hash quality as
it encodes more data into FNV's state and thus improves randomness.

PR Checklist

  • I work here
  • Tests added/passed

Validation Steps Performed

  • No unusual behavior

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/11887 **Author:** [@lhecker](https://github.com/lhecker) **Created:** 12/6/2021 **Status:** ✅ Merged **Merged:** 12/7/2021 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/lhecker/til-hash` --- ### 📝 Commits (7) - [`4459d80`](https://github.com/microsoft/terminal/commit/4459d80915e4a3a0341dae6711558c094d8428de) Introduce til::hasher for sucessive hashing of structs - [`b0dca54`](https://github.com/microsoft/terminal/commit/b0dca54b2b93b4d512cc78ded04c658321a9be16) Address feedback, Fix x86 build, Fix tests - [`5f258cb`](https://github.com/microsoft/terminal/commit/5f258cb62daad2f60ed8c1ce230e0bcdd9f1c858) Fix spelling - [`01ce3c6`](https://github.com/microsoft/terminal/commit/01ce3c6ec241db37cf76556b641b2041b2531836) Fix spelling - [`0ae4f15`](https://github.com/microsoft/terminal/commit/0ae4f154935c58978f8c9118d330b88f4d742daf) Fix audit checks - [`ae0fbc8`](https://github.com/microsoft/terminal/commit/ae0fbc8940d44e692c6c8fb8e389f4b6b18fb641) Fix audit checks - [`5fa8adf`](https://github.com/microsoft/terminal/commit/5fa8adf8e52a872dd1db69c8bc48173c8aff7d70) Make constructor explicit ### 📊 Changes **12 files changed** (+316 additions, -178 deletions) <details> <summary>View changed files</summary> 📝 `.github/actions/spelling/expect/expect.txt` (+2 -11) 📝 `src/buffer/out/UnicodeStorage.hpp` (+5 -6) 📝 `src/buffer/out/textBuffer.cpp` (+1 -1) 📝 `src/cascadia/TerminalSettingsModel/ActionArgs.h` (+30 -31) 📝 `src/cascadia/TerminalSettingsModel/ActionArgs.idl` (+2 -2) 📝 `src/cascadia/TerminalSettingsModel/ActionArgsMagic.h` (+52 -49) 📝 `src/cascadia/TerminalSettingsModel/ActionMap.cpp` (+22 -16) 📝 `src/cascadia/TerminalSettingsModel/HashUtils.h` (+25 -42) 📝 `src/cascadia/TerminalSettingsModel/Microsoft.Terminal.Settings.ModelLib.vcxproj.filters` (+1 -0) 📝 `src/host/alias.cpp` (+8 -11) 📝 `src/host/ut_host/TextBufferTests.cpp` (+9 -9) ➕ `src/inc/til/hash.h` (+159 -0) </details> ### 📄 Description This commit serves two purposes: * Simplify construction of hashes for non-trivial structs This is especially helpful for ActionArgs * Improve hash quality by not needlessly throwing away entropy `til::hasher` is modeled after Rust's `std::hash::Hasher` and works similar. The idea is simple: A stateful hash function can hash multiple unrelated fields, without loosing entropy by running a finalizer after hashing each interim field. This is especially useful for modern hash functions, which often have a wider internal state than the output width. Additionally this improves performance for hash functions with complex finalizers. Most of this is of course a bit moot right now, considering that `til::hasher` is still based on STL's FNV1a algorithm, which offers a very poor hash quality. But counterintuitively, FNV1a actually benefits most from this PR: Since it lacks a finalizer entirely, this commit greatly improves hash quality as it encodes more data into FNV's state and thus improves randomness. ## PR Checklist * [x] I work here * [x] Tests added/passed ## Validation Steps Performed * No unusual behavior ✅ --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:30:41 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#28776