## Description
Currently, the name of `bucket` is a bit confusing, because it is considered a 'table' in literature (as well as the whole hash table). A `bucket` is better described as a 'subtable', which is used by the total hash table to perform cuckoo hashing.
In addition, the constructors `NewTable`, `NewTableBy`, and `NewCustomTable` were given shorter names, because the package name `cuckoo` already implies that `New*` would create a hash table with cuckoo hashing. This package has one use-case, and so it unambiguous what constructors produce.
## Changes
- `NewTable` -> `New`
- `NewTableBy` -> `NewBy`
- `NewCustomTable` -> `NewCustom`
- `bucket` -> `subtable`
### Design Decisions
- I would have renamed `Table` and `subtable` to map equivalents, but 'submap' implies that a certain subsection of the map is contained within it, which isn't quite right.
- I chose not to go with `Map` and `table`, because of the split naming convention.
## Checklist
- [x] Tests pass
- [x] Docs updated
Reviewed-on: #22
Co-authored-by: M.V. Hutz <git@maximhutz.me>
Co-committed-by: M.V. Hutz <git@maximhutz.me>
## Description
Currently, the signature for `Table.Get` is `func (K) (V, error)`. This is not very Go-idiomatic, which prefers to return a boolean instead of an error. For instance, a built-in Go map is used like so:
```go
if value, ok := users[id]; !ok {
// ...
}
```
Updating our table to look like that is best practice. In that same vein, to support direct lookup (i.e. `v := users[id]`), this PR also adds `Table.Find`.
## Changes
- BREAKING CHANGE: Update contract of `Table.Get` to `func (K) (V, bool)`. Returns 'false' is the item cannot be found, and 'true' if it is found.
- Add `Table.Find`.
- Updated tests and documentation to match the change.
### Design Decisions
- Chose to make this decision because throwing an error implies that there is something 'wrong' with the table. There is nothing wrong with the table; it is just that the item does not exist.
## Checklist
- [x] Tests pass
- [x] Docs updated
Reviewed-on: #20
Co-authored-by: M.V. Hutz <git@maximhutz.me>
Co-committed-by: M.V. Hutz <git@maximhutz.me>
## Description
Currently, the errors are not sentinel, and so are hard to test for. This PR makes sure hash collision errors are accounted for.
## Changes
- Add `ErrBadHash`. Happens when there are too many collisions for an item to be added.
### Design Decisions
- Chose to name `ErrBadHash` over `ErrCycle` because the feedbach that the user should be given is to evaluate their hash functions. Cycle collision is a bit esoteric.
## Checklist
- [x] Tests pass
- [x] Docs updated
Reviewed-on: #19
Co-authored-by: M.V. Hutz <git@maximhutz.me>
Co-committed-by: M.V. Hutz <git@maximhutz.me>
## Description
The `cuckoo.MinimumLoad()` option was not a very useful option, and prone to error. By removing the ability to modify it, and setting it to something reasonable (like 5%), we can remove a whole set of errors that the user may stumble into.
## Changes
- Remove `MinimumLoad()` option.
- Privated `DefaultMinimumLoad`.
### Design Decisions
- `DefaultMinimumLoad` should be privated because it is no longer an option. The user should not need to interact with it.
## Checklist
- [x] Tests pass
- [x] Docs updated
Reviewed-on: #17
Currently, the `Table.Drop()` function is deprecated because it is not implemented yet. Let's add that functionality.
- Adds true drop functionality to the table, through `Table.Drop()`.
- Adds tests for functionality.
- Rewrites fuzz test using `go_fuzz_utils`, to test arbitrary usage patterns.
- Rewrite `bucket` to allow a capacity of zero.
- Rename `Table.Capacity()` to `Table.TotalCapacity()`, to reflect to different between the capacity of the buckets vs. the whole table.
- Enforce 100% mutation test coverage.
Reviewed-on: #6
Co-authored-by: M.V. Hutz <git@maximhutz.me>
Co-committed-by: M.V. Hutz <git@maximhutz.me>
Moved the implementation of this hash table from `tools/dsa` #1.
Reviewed-on: #1
Co-authored-by: M.V. Hutz <git@maximhutz.me>
Co-committed-by: M.V. Hutz <git@maximhutz.me>