hash

package
v1.2.23 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array[F Hasher[F]] struct {
	// contains filtered or unexported fields
}

Array provides a mechanism for hashing hashes (or other uint64 values).

func NewArray

func NewArray[F Hasher[F]](hashes []F) Array[F]

NewArray constructs a new bytes key.

func (Array[F]) Equals

func (p Array[F]) Equals(other Array[F]) bool

Equals compares two arrays to check whether they represent the same underlying byte array (or not).

func (Array[F]) Hash

func (p Array[F]) Hash() uint64

Hash generat6es a 64-bit hashcode from the underlying bytes array.

type BytesKey

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

BytesKey wraps a bytes array as something which can be safely placed into a HashSet.

func NewBytesKey

func NewBytesKey(bytes []byte) BytesKey

NewBytesKey constructs a new bytes key.

func (BytesKey) Equals

func (p BytesKey) Equals(other BytesKey) bool

Equals compares two BytesKeys to check whether they represent the same underlying byte array (or not).

func (BytesKey) Hash

func (p BytesKey) Hash() uint64

Hash generat6es a 64-bit hashcode from the underlying bytes array.

type Hasher

type Hasher[T any] interface {
	// Check whether two items are equal (or not).
	Equals(T) bool
	// Return a suitable hashcode.
	Hash() uint64
}

Hasher provides a generic definition of a hashing function suitable for use within the hashset. This is similar to the Hasher interface provided in go-set, except that it additionally includes equality.

type Map

type Map[K Hasher[K], V any] struct {
	// contains filtered or unexported fields
}

Map defines a generic set implementation backed by a map. This is a true hashtable in that collisions are handle gracefully using buckets, rather than simply discarding them.

func NewMap

func NewMap[K Hasher[K], V any](size uint) *Map[K, V]

NewMap creates a new HashMap with a given underlying capacity.

func (*Map[K, V]) ContainsKey

func (p *Map[K, V]) ContainsKey(key K) bool

ContainsKey checks whether the given item is contained within this map, or not.

func (*Map[K, V]) Get

func (p *Map[K, V]) Get(key K) (V, bool)

Get item from bucket, or return false otherwise.

func (*Map[K, V]) Insert

func (p *Map[K, V]) Insert(key K, value V) bool

Insert a new item into this map, returning true if it was already contained and false otherwise.

func (*Map[K, V]) KeyValues

func (p *Map[K, V]) KeyValues() iter.Iterator[util.Pair[K, V]]

KeyValues returns the set of all key-value pairs stored in this hash map. Observe that the order in which elements are seen is unspecified.

func (*Map[K, V]) MaxBucket

func (p *Map[K, V]) MaxBucket() uint

MaxBucket returns the size of the largest bucket.

func (*Map[K, V]) Size

func (p *Map[K, V]) Size() uint

Size returns the number of unique items stored in this HashMap.

func (*Map[K, V]) String

func (p *Map[K, V]) String() string

type Set

type Set[T Hasher[T]] struct {
	// contains filtered or unexported fields
}

Set defines a generic set implementation backed by a map. This is a true hashtable in that collisions are handle gracefully using buckets, rather than simply discarding them.

func NewSet

func NewSet[T Hasher[T]](size uint) *Set[T]

NewSet creates a new HashSet with a given underlying capacity.

func (*Set[T]) Contains

func (p *Set[T]) Contains(item T) bool

Contains checks whether the given item is contained within this map, or not.

func (*Set[T]) Insert

func (p *Set[T]) Insert(item T) bool

Insert a new item into this map, returning true if it was already contained and false otherwise.

func (*Set[T]) MaxBucket

func (p *Set[T]) MaxBucket() uint

MaxBucket returns the size of the largest bucket.

func (*Set[T]) Size

func (p *Set[T]) Size() uint

Size returns the number of unique items stored in this HashSet.

func (*Set[T]) String

func (p *Set[T]) String() string

Jump to

Keyboard shortcuts

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