feat!: Drop returns bool, Put doesn't stack-overflow #21

Merged
mvhutz merged 12 commits from feat/safe-put into main 2026-04-17 01:31:02 +00:00
Owner

Description

Closes #11. This PR attempts to grapple with:

  1. How Table.Put is not atomic, and is non-recoverable upon ErrBadHash.
  2. How Table.Drop cannot provide a meaningful error scenario.
  3. How Table.Put will stack-overflow if it is unable to construct a table on resize.

Changes

  1. Clearly note in the documentation that upon this error, you MUST rebuild the table from the source data.
    • Add this note to the documentation for ErrBadHash.
    • Note in the package-level documentation that Table is NOT a source of truth, and should not be trusted as one.
  2. Update the contract of Table.Drop to return bool. Ignore the error when shrinking the table.
  3. Limit resizes to 64.
    • Add internal defaultResizeLimit constant.

Design Decisions

  • It was tempting to return the displaced entry for Table.Put, and provide this invariant: on error, the displaced entry along + the tables current contents = the inserted entry + the old table. I chose not to, because for developers, receiving this error will probably just prompt them to just propagate it, or ignore it. Both times, the displaced entry is unused, so why return it?
  • Currently, the only error in Table.Drop is caused when the user tries to shrink. But, because Table.shrink is atomic, it won't break the table. Plus, because table capacity is an internal optimization, why should the user care?
  • The resize limit of 64 was arbitrary, and chosen as a large enough number to not get called unless the hash is truly broken.
  • We now return an error immediately if Table.Put cannot grow, due to a hash collision. The chance an even larger table size will fit the items is astronomically small, so we choose to ignore it.

Checklist

  • Tests pass
  • Docs updated
## Description Closes #11. This PR attempts to grapple with: 1. How `Table.Put` is not atomic, and is non-recoverable upon `ErrBadHash`. 2. How `Table.Drop` cannot provide a meaningful error scenario. 3. How `Table.Put` will stack-overflow if it is unable to construct a table on resize. ## Changes 1. Clearly note in the documentation that upon this error, you MUST rebuild the table from the source data. - Add this note to the documentation for `ErrBadHash`. - Note in the package-level documentation that `Table` is NOT a source of truth, and should not be trusted as one. 2. Update the contract of `Table.Drop` to return `bool`. Ignore the error when shrinking the table. 3. Limit resizes to 64. - Add internal `defaultResizeLimit` constant. ### Design Decisions - It was tempting to return the displaced entry for `Table.Put`, and provide this invariant: on error, the displaced entry along + the tables current contents = the inserted entry + the old table. I chose not to, because for developers, receiving this error will probably just prompt them to just propagate it, or ignore it. Both times, the displaced entry is unused, so why return it? - Currently, the only error in `Table.Drop` is caused when the user tries to shrink. But, because `Table.shrink` is atomic, it won't break the table. Plus, because table capacity is an internal optimization, why should the user care? - The resize limit of 64 was arbitrary, and chosen as a large enough number to not get called unless the hash is truly broken. - We now return an error immediately if `Table.Put` cannot grow, due to a hash collision. The chance an even larger table size will fit the items is astronomically small, so we choose to ignore it. ## Checklist - [x] Tests pass - [x] Docs updated
mvhutz added 3 commits 2026-04-03 22:56:32 +00:00
fix: public facing key/value fields in entry
All checks were successful
CI / Check PR Title (pull_request) Successful in 19s
CI / Go Lint (pull_request) Successful in 42s
CI / Markdown Lint (pull_request) Successful in 23s
CI / Makefile Lint (pull_request) Successful in 41s
CI / Unit Tests (pull_request) Successful in 41s
CI / Fuzz Tests (pull_request) Successful in 1m12s
CI / Mutation Tests (pull_request) Successful in 58s
ca66ccd040
mvhutz added 1 commit 2026-04-16 03:59:05 +00:00
Merge remote-tracking branch 'origin' into feat/safe-put
Some checks failed
CI / Check PR Title (pull_request) Successful in 31s
CI / Go Lint (pull_request) Successful in 52s
CI / Markdown Lint (pull_request) Successful in 34s
CI / Makefile Lint (pull_request) Successful in 50s
CI / Unit Tests (pull_request) Successful in 48s
CI / Fuzz Tests (pull_request) Failing after 41s
CI / Mutation Tests (pull_request) Successful in 1m3s
1f7c64366d
mvhutz added 1 commit 2026-04-16 04:00:14 +00:00
revert: forgot about b -> t
Some checks failed
CI / Check PR Title (pull_request) Successful in 31s
CI / Makefile Lint (pull_request) Successful in 50s
CI / Go Lint (pull_request) Successful in 55s
CI / Markdown Lint (pull_request) Successful in 34s
CI / Unit Tests (pull_request) Successful in 49s
CI / Fuzz Tests (pull_request) Failing after 41s
CI / Mutation Tests (pull_request) Successful in 1m1s
78f7d01d5f
mvhutz added 1 commit 2026-04-16 04:05:46 +00:00
feat: use bad hash sentinel error
Some checks failed
CI / Check PR Title (pull_request) Successful in 31s
CI / Go Lint (pull_request) Successful in 53s
CI / Makefile Lint (pull_request) Successful in 50s
CI / Markdown Lint (pull_request) Successful in 34s
CI / Unit Tests (pull_request) Successful in 50s
CI / Mutation Tests (pull_request) Successful in 1m40s
CI / Fuzz Tests (pull_request) Failing after 39s
24b646c5dc
mvhutz added 1 commit 2026-04-17 00:33:39 +00:00
fix: assertion in fuzz test incorrect
All checks were successful
CI / Check PR Title (pull_request) Successful in 32s
CI / Makefile Lint (pull_request) Successful in 54s
CI / Go Lint (pull_request) Successful in 56s
CI / Markdown Lint (pull_request) Successful in 34s
CI / Unit Tests (pull_request) Successful in 1m4s
CI / Mutation Tests (pull_request) Successful in 1m16s
CI / Fuzz Tests (pull_request) Successful in 1m23s
5452c02d4e
mvhutz added 1 commit 2026-04-17 01:05:51 +00:00
docs: note that the table isnt a source of truth
All checks were successful
CI / Check PR Title (pull_request) Successful in 31s
CI / Go Lint (pull_request) Successful in 53s
CI / Makefile Lint (pull_request) Successful in 54s
CI / Markdown Lint (pull_request) Successful in 34s
CI / Unit Tests (pull_request) Successful in 52s
CI / Fuzz Tests (pull_request) Successful in 1m25s
CI / Mutation Tests (pull_request) Successful in 1m10s
d13adcaa49
mvhutz added 1 commit 2026-04-17 01:11:05 +00:00
revert!: old put contract
Some checks failed
CI / Check PR Title (pull_request) Successful in 31s
CI / Go Lint (pull_request) Failing after 43s
CI / Makefile Lint (pull_request) Successful in 49s
CI / Markdown Lint (pull_request) Successful in 34s
CI / Unit Tests (pull_request) Failing after 38s
CI / Mutation Tests (pull_request) Failing after 41s
CI / Fuzz Tests (pull_request) Failing after 41s
24df23218c
mvhutz added 1 commit 2026-04-17 01:12:26 +00:00
fix: tests were out of date
All checks were successful
CI / Check PR Title (pull_request) Successful in 32s
CI / Go Lint (pull_request) Successful in 54s
CI / Markdown Lint (pull_request) Successful in 34s
CI / Makefile Lint (pull_request) Successful in 54s
CI / Unit Tests (pull_request) Successful in 54s
CI / Fuzz Tests (pull_request) Successful in 1m25s
CI / Mutation Tests (pull_request) Successful in 1m8s
b395d6e1f4
mvhutz added 1 commit 2026-04-17 01:15:03 +00:00
revert: Entry -> entry bc Put() doesnt use it
All checks were successful
CI / Check PR Title (pull_request) Successful in 31s
CI / Go Lint (pull_request) Successful in 56s
CI / Markdown Lint (pull_request) Successful in 35s
CI / Makefile Lint (pull_request) Successful in 54s
CI / Unit Tests (pull_request) Successful in 56s
CI / Fuzz Tests (pull_request) Successful in 1m25s
CI / Mutation Tests (pull_request) Successful in 1m9s
7b45099cea
mvhutz changed title from WIP: feat!: put fails gracefully, allows recovery to feat!: `Table.Drop` returns `bool`, `Table.Put` doesn't cause stack-overflow 2026-04-17 01:19:45 +00:00
mvhutz changed title from feat!: `Table.Drop` returns `bool`, `Table.Put` doesn't cause stack-overflow to feat!: `Table.Drop` returns `bool`, `Table.Put` doesn't stack-overflow 2026-04-17 01:19:51 +00:00
mvhutz changed title from feat!: `Table.Drop` returns `bool`, `Table.Put` doesn't stack-overflow to feat!: `Drop` returns `bool`, `Put` doesn't stack-overflow 2026-04-17 01:20:02 +00:00
mvhutz merged commit 39548b4332 into main 2026-04-17 01:31:02 +00:00
mvhutz deleted branch feat/safe-put 2026-04-17 01:31:02 +00:00
Sign in to join this conversation.