feat!: Drop returns bool, Put doesn't stack-overflow
#21
Reference in New Issue
Block a user
Delete Branch "feat/safe-put"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Closes #11. This PR attempts to grapple with:
Table.Putis not atomic, and is non-recoverable uponErrBadHash.Table.Dropcannot provide a meaningful error scenario.Table.Putwill stack-overflow if it is unable to construct a table on resize.Changes
ErrBadHash.Tableis NOT a source of truth, and should not be trusted as one.Table.Dropto returnbool. Ignore the error when shrinking the table.defaultResizeLimitconstant.Design Decisions
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?Table.Dropis caused when the user tries to shrink. But, becauseTable.shrinkis atomic, it won't break the table. Plus, because table capacity is an internal optimization, why should the user care?Table.Putcannot 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
WIP: feat!: put fails gracefully, allows recoveryto feat!: `Table.Drop` returns `bool`, `Table.Put` doesn't cause stack-overflowfeat!: `Table.Drop` returns `bool`, `Table.Put` doesn't cause stack-overflowto feat!: `Table.Drop` returns `bool`, `Table.Put` doesn't stack-overflowfeat!: `Table.Drop` returns `bool`, `Table.Put` doesn't stack-overflowto feat!: `Drop` returns `bool`, `Put` doesn't stack-overflow