hash

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BloomFilter

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

BloomFilter represents a Bloom filter data structure

func NewBloomFilter

func NewBloomFilter(expectedElements int, falsePositiveRate float64) *BloomFilter

NewBloomFilter creates a new Bloom filter with the given size and desired false positive rate

func (*BloomFilter) Add

func (bf *BloomFilter) Add(data []byte)

Add adds an element to the Bloom filter

func (*BloomFilter) Clear

func (bf *BloomFilter) Clear()

Clear resets the Bloom filter

func (*BloomFilter) Contains

func (bf *BloomFilter) Contains(data []byte) bool

Contains checks if an element might be in the set

func (*BloomFilter) EstimateFalsePositiveRate

func (bf *BloomFilter) EstimateFalsePositiveRate(numElements int) float64

EstimateFalsePositiveRate estimates the current false positive rate

type HashNode

type HashNode struct {
	Key   interface{}
	Value interface{}
	Next  *HashNode // Used for chaining collision resolution
}

HashNode represents a key-value pair in the hash table

type HashTable

type HashTable struct {
	Size     int
	Capacity int
	Table    []*HashNode
	Strategy string // "linear" for linear probing, "chain" for chaining
	// contains filtered or unexported fields
}

HashTable represents the hash table data structure

func NewHashTable

func NewHashTable(capacity int, strategy string) *HashTable

NewHashTable creates a new hash table with specified capacity and collision resolution strategy

func (*HashTable) Get

func (h *HashTable) Get(key interface{}) (interface{}, bool)

Get retrieves a value by key from the hash table

func (*HashTable) Put

func (h *HashTable) Put(key, value interface{}) bool

Put inserts a key-value pair into the hash table

func (*HashTable) Remove

func (h *HashTable) Remove(key interface{}) bool

Remove removes a key-value pair from the hash table

Jump to

Keyboard shortcuts

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