Documentation
¶
Overview ¶
Package hash implements a hash table.
Hash table
hashKey(key) ────────┐
│
↓
┌────┬─────┬─────┬────┬─────┬─────┬─────┬─────┐
│ │ │ │ │ │ │ │ │ ←── bucket
└────┴─────┴─────┴────┴─────┴─────┴─────┴─────┘
│ │
↓ ↓
┌─────────────┐ ┌─────────────┐
│ key │ value │ │ key │ value │ ←── entry
├─────────────┤ ├─────────────┤
│ key │ value │ │ key │ value │
├─────────────┤ └─────────────┘
│ key │ value │
├─────────────┤
│ key │ value │
├─────────────┤
│ key │ value │
└─────────────┘
- hashKey(key) returns a number between 0 to len(buckets)-1
- We use a slice of entries as a bucket to handles cases where two or more keys are hashed to the same bucket
- See more at https://en.wikipedia.org/wiki/Hash_table
Package hash implements a hash table.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hash ¶
type Hash struct {
// contains filtered or unexported fields
}
Hash is a simple Hash table implementation.
func (*Hash) Len ¶
Len return the number of elements in the hash. This function currently uses a linear traversal but could be improved with meta-data.
Click to show internal directories.
Click to hide internal directories.