hashtable

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultSize is the default size of the table
	DefaultSize = 16
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	Head *Entry
}

Bucket represents the hash table bucket

type Entry

type Entry struct {
	Key          string
	Value        string
	CreatedAt    time.Time
	ShouldExpire bool
	ExpireAfter  int
	Next         *Entry
}

Entry represents an entry inside the bucket

type HashTable

type HashTable struct {
	// contains filtered or unexported fields
}

HashTable data structure

func New

func New() *HashTable

New returns a new Hash Table

func (*HashTable) Exist

func (ht *HashTable) Exist(k string) bool

Exist returns true if an item with the given key exists otherwise returns false

func (*HashTable) Flush

func (ht *HashTable) Flush()

Flush clears the bucket

func (*HashTable) Get

func (ht *HashTable) Get(k string) string

Get returns the value of the given key if the result is empty then returns an empty string ("")

func (*HashTable) Iter

func (ht *HashTable) Iter() <-chan *Entry

Iter represents an iterator for the hashtable

func (*HashTable) Remove

func (ht *HashTable) Remove(k string) int

Remove deletes an item by the given key

func (*HashTable) Set

func (ht *HashTable) Set(k string, v string)

Set inserts a new key-value pair item into the hash table

func (*HashTable) SetEX

func (ht *HashTable) SetEX(k string, v string, expiresAfter int)

SetEX inserts a new expirable key-value pair item into the hash table

func (*HashTable) Size

func (ht *HashTable) Size() int

Size represents the size of the hash table

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL