Documentation
¶
Overview ¶
Package keyindex is the lookup table of API keys: a lookup costs a bounded amount whatever the key a client presents.
- a key longer than the longest configured key is refused without being hashed: it can not be a configured key, whatever it holds, so the cap never refuses a valid key and it is no fixed limit;
- the key is hashed once with a seeded hash (a random seed per index, so a client can not choose keys that collide), and the table is keyed by the hash: O(1) among any number of keys;
- a key is compared with a configured one only when the hashes are equal, against the full configured key, and the comparison reads every byte (no early exit), so the time of a lookup does not depend on how much of a key is right. A hash is a bucket, not an identity: every key of a hash is kept, none is replaced.
An index is immutable once built: any number of goroutines may read it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is the lookup table of a list of keys: Find returns the position of a key in the list.
func New ¶
New indexes the keys with a random seeded hash. A key that is repeated keeps its first position.
func NewWithHash ¶
NewWithHash is New with the hash function given: it exists so that a test can force collisions.