Documentation ¶
Overview ¶
Package ctmap implements a constant-time key-value map.
Index ¶
- type Map
- func (m *Map) Add(key, val []byte)
- func (m *Map) Contains(key []byte) int
- func (m *Map) Delete(key []byte) int
- func (m *Map) Len() int
- func (m *Map) Lookup(key, val []byte) int
- func (m *Map) Range(f func(key, val []byte))
- func (m *Map) Rename(oldKey, newKey []byte) int
- func (m *Map) Replace(oldKey, newKey, val []byte) int
- func (m *Map) Set(key, val []byte) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is a constant-time key-value map.
func New ¶
New returns a new constant-time map with the given key and value sizes.
Every key and value must be of equal size.
For a constant-time equivalent of map[string]struct{}, use 0 for valSize.
func NewWithCapacity ¶
NewWithCapacity returns a new constant-time map with the given key and value sizes. It preallocates the map's backing storage, sized to fit capacity entries without reallocating.
Every key and value must be of equal size.
For a constant-time equivalent of map[string]struct{}, use 0 for valSize.
func (*Map) Add ¶
Add appends a new entry to the map. It does not check for duplicates, nor does it handle them.
func (*Map) Contains ¶
Contains determines if a key is present in the map in constant-time. It returns 1 if the key is present, 0 otherwise.
func (*Map) Delete ¶
Delete removes an entry with a given key from the map. It returns 1 if an entry was removed, 0 otherwise. The removed entry is zeroed.
If the map contains multiple entries with the same key, only the first is removed.
WARNING: The interaction between Delete and other methods leaks timing information. In particular, if an entry was removed the size of the map is reduced and the time taken by other methods in this package will be reduced. If an entry was not removed, then the time taken does not change.
func (*Map) Lookup ¶
Lookup finds the value associated with a key in constant-time. The value is copied, in constant-time, into val which must be the correct length. It returns 1 if the key was present, 0 otherwise.
If there are multiple entries matching key, only the first will be returned.
func (*Map) Range ¶
Range calls f for each entry in the map. f must be carefull not to leak any timing information about the contents of key.
If the map contains duplicate keys, f will be called once for each key.
The behaviour of the map is undefined if key or val are modified.
func (*Map) Rename ¶
Rename is like Replace but it only changes they key and leaves the value untouched.
If there are duplicate entries matching oldKey, only the first entry's key will be replaced.