pool

package
v1.2.24 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0 Imports: 12 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

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

View Source
const HEAP_POOL_INIT_BUCKETS = 128

HEAP_POOL_INIT_BUCKETS determines the initial number of buckets to use for any instance. Since we are geared towards large pools, we set this figure quite high.

View Source
const HEAP_POOL_LOADING = 75

HEAP_POOL_LOADING determines the loading point, overwhich rehashing will occur. This is currently set to 75% capacity forces a rehashing.

Variables

This section is empty.

Functions

This section is empty.

Types

type LocalHeap

type LocalHeap[T word.DynamicWord[T]] struct {
	// contains filtered or unexported fields
}

LocalHeap maintains a heap of bytes representing the words which is *not* thread safe.

func NewLocalHeap

func NewLocalHeap[T word.DynamicWord[T]]() *LocalHeap[T]

NewLocalHeap constructs a new thread-unsafe heap

func (*LocalHeap[T]) Bytes

func (p *LocalHeap[T]) Bytes() []byte

Bytes returns the raw bytes in this heap.

func (*LocalHeap[T]) Clone

func (p *LocalHeap[T]) Clone() LocalHeap[T]

Clone implementation for SharedPool interface.

func (*LocalHeap[T]) Get

func (p *LocalHeap[T]) Get(index uint32) T

Get implementation for the Pool interface.

func (*LocalHeap[T]) MarshalBinaryV3

func (p *LocalHeap[T]) MarshalBinaryV3() ([]byte, error)

MarshalBinaryV3 converts this heap into a sequence of bytes.

func (*LocalHeap[T]) Put

func (p *LocalHeap[T]) Put(word T) uint32

Put implementation for the Pool interface. This is somewhat challenging because it must be thread safe. Since we anticipate a large number of cache hits compared with cache misses, we employ a Read/Write lock.

func (*LocalHeap[T]) Size

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

Size returns the number of distinct entries in this heap.

func (*LocalHeap[T]) UnmarshalBinaryV2

func (p *LocalHeap[T]) UnmarshalBinaryV2(data []byte) error

UnmarshalBinaryV2 initialises this heap from a given set of data bytes. This should match exactly the encoding above.

func (*LocalHeap[T]) UnmarshalBinaryV3

func (p *LocalHeap[T]) UnmarshalBinaryV3(data []byte) error

UnmarshalBinaryV3 initialises this heap from a given set of data bytes. This should match exactly the encoding above.

type LocalIndex

type LocalIndex[T word.Word[T]] struct {
	// contains filtered or unexported fields
}

LocalIndex represents a pool which stores words "as is", and does not attempt to compress them into shorter byte sequences.

func NewLocalIndex

func NewLocalIndex[T word.Word[T]]() *LocalIndex[T]

NewLocalIndex constructs a new shared index

func (*LocalIndex[T]) Get

func (p *LocalIndex[T]) Get(index uint32) T

Get implementation for the Pool interface.

func (*LocalIndex[T]) Put

func (p *LocalIndex[T]) Put(word T) uint32

Put implementation for the Pool interface. This is somewhat challenging because it must be thread safe. Since we anticipate a large number of cache hits compared with cache misses, we employ a Read/Write lock.

type Pool

type Pool[K any, T any] interface {
	// Lookup a given word in the pool using an index.
	Get(K) T
	// Allocate word into pool, returning its index.
	Put(T) K
}

Pool provides an abstraction for referring to large words by a smaller index value. The pool stores the actual word data, and provides fast access via an index. This makes sense when we have a relatively small number of values which can be referred to many times over.

type SharedHeap

type SharedHeap[T word.DynamicWord[T]] struct {
	// contains filtered or unexported fields
}

SharedHeap maintains a heap of bytes representing the words which is thread safe and is protected by an RWMutex.

func NewSharedHeap

func NewSharedHeap[T word.DynamicWord[T]]() *SharedHeap[T]

NewSharedHeap constructs a new thread-safe heap

func (*SharedHeap[T]) Clone

func (p *SharedHeap[T]) Clone() *SharedHeap[T]

Clone implementation for SharedPool interface.

func (*SharedHeap[T]) Get

func (p *SharedHeap[T]) Get(index uint32) T

Get implementation for the Pool interface.

func (*SharedHeap[T]) Localise

func (p *SharedHeap[T]) Localise() *LocalHeap[T]

Localise implementation for SharedPool interface.

func (*SharedHeap[T]) Put

func (p *SharedHeap[T]) Put(word T) uint32

Put implementation for the Pool interface. This is somewhat challenging because it must be thread safe. Since we anticipate a large number of cache hits compared with cache misses, we employ a Read/Write lock.

func (*SharedHeap[T]) Size

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

Size returns the number of distinct entries in this heap.

type SharedIndex

type SharedIndex[T word.Word[T]] struct {
	// contains filtered or unexported fields
}

SharedIndex represents a pool which stores words "as is", and does not attempt to compress them into shorter byte sequences.

func NewSharedIndex

func NewSharedIndex[T word.Word[T]]() *SharedIndex[T]

NewSharedIndex constructs a new shared index

func (*SharedIndex[T]) Clone

func (p *SharedIndex[T]) Clone() *SharedIndex[T]

Clone implementation for SharedPool interface.

func (*SharedIndex[T]) Get

func (p *SharedIndex[T]) Get(index uint32) T

Get implementation for the Pool interface.

func (*SharedIndex[T]) Localise

func (p *SharedIndex[T]) Localise() *LocalIndex[T]

Localise implementation for SharedPool interface.

func (*SharedIndex[T]) Put

func (p *SharedIndex[T]) Put(word T) uint32

Put implementation for the Pool interface. This is somewhat challenging because it must be thread safe. Since we anticipate a large number of cache hits compared with cache misses, we employ a Read/Write lock.

type SharedPool

type SharedPool[K any, T any, P any] interface {
	Pool[K, T]
	// Localise this pool
	Localise() P
}

SharedPool represents a pool which can be safely shared amongst threads.

type SmallPool

type SmallPool[K uint8 | uint16, W word.Word[W]] struct {
	// contains filtered or unexported fields
}

SmallPool is a pool implementation for handling small domains (i.e. where all elements can be enumerated).

func NewBytePool

func NewBytePool[W word.Word[W]]() SmallPool[uint8, W]

NewBytePool constructs a new pool which uses a given key type for indexing.

func NewWordPool

func NewWordPool[W word.Word[W]]() SmallPool[uint16, W]

NewWordPool constructs a new pool which uses a given key type for indexing.

func (SmallPool[K, F]) Clone

func (p SmallPool[K, F]) Clone() Pool[K, F]

Clone implementation for Pool interface.

func (SmallPool[K, F]) Get

func (p SmallPool[K, F]) Get(index K) F

Get implementation for Pool interface.

func (SmallPool[K, F]) Put

func (p SmallPool[K, F]) Put(element F) K

Put implementation for Pool interface.

Jump to

Keyboard shortcuts

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