refactor for readability: MyHash -> HashKey; Hasher -> Hashable

This commit is contained in:
Denis-Cosmin Nutiu 2024-11-09 14:33:40 +02:00
parent e76cf0638a
commit e0859fa215
2 changed files with 5 additions and 5 deletions

View file

@ -5,21 +5,21 @@ import (
"strings"
)
type MyHash interface {
type HashKey interface {
~string | ~int | ~uint | ~int64 | ~uint64 | ~int32 | ~uint32 | ~int16 | ~uint16 | ~int8 | ~uint8
}
type Hasher[H MyHash] interface {
type Hashable[H HashKey] interface {
Hash() H
}
// MyHashSet is a hash set implementation.
type MyHashSet[T Hasher[H], H MyHash] struct {
type MyHashSet[T Hashable[H], H HashKey] struct {
storage map[H]T
}
// NewSet initializes a new hash set.
func NewSet[T Hasher[H], H MyHash]() MyHashSet[T, H] {
func NewSet[T Hashable[H], H HashKey]() MyHashSet[T, H] {
return MyHashSet[T, H]{
storage: make(map[H]T, 100),
}

View file

@ -10,7 +10,7 @@ type Person struct {
Age int
}
// Hash returns the has of a person, it conforms to the hash_set.Hasher interface
// Hash returns the has of a person, it conforms to the hash_set.Hashable interface
func (p Person) Hash() string {
return fmt.Sprintf("%s-%d", p.Name, p.Age)
}