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
- type LocalHeap
- func (p *LocalHeap[T]) Bytes() []byte
- func (p *LocalHeap[T]) Clone() LocalHeap[T]
- func (p *LocalHeap[T]) Get(index uint32) T
- func (p *LocalHeap[T]) MarshalBinaryV3() ([]byte, error)
- func (p *LocalHeap[T]) Put(word T) uint32
- func (p *LocalHeap[T]) Size() uint
- func (p *LocalHeap[T]) UnmarshalBinaryV2(data []byte) error
- func (p *LocalHeap[T]) UnmarshalBinaryV3(data []byte) error
- type LocalIndex
- type Pool
- type SharedHeap
- type SharedIndex
- type SharedPool
- type SmallPool
Constants ¶
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.
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]) MarshalBinaryV3 ¶
MarshalBinaryV3 converts this heap into a sequence of bytes.
func (*LocalHeap[T]) Put ¶
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]) UnmarshalBinaryV2 ¶
UnmarshalBinaryV2 initialises this heap from a given set of data bytes. This should match exactly the encoding above.
func (*LocalHeap[T]) UnmarshalBinaryV3 ¶
UnmarshalBinaryV3 initialises this heap from a given set of data bytes. This should match exactly the encoding above.
type LocalIndex ¶
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 ¶
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 ¶
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 ¶
NewBytePool constructs a new pool which uses a given key type for indexing.
func NewWordPool ¶
NewWordPool constructs a new pool which uses a given key type for indexing.