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
Index ¶
- type Heap
- func (p *Heap[T]) Alloc(n uint)
- func (p *Heap[T]) Clear()
- func (p *Heap[T]) Free(n uint)
- func (p *Heap[T]) Get(offset uint) T
- func (p *Heap[T]) Pop() T
- func (p *Heap[T]) Push(item T)
- func (p *Heap[T]) Set(offset uint, val T)
- func (p *Heap[T]) Size() uint
- func (p *Heap[T]) Slice(start, end uint) []T
- func (p *Heap[T]) SliceEnd(start uint) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Heap ¶
type Heap[T any] struct { // contains filtered or unexported fields }
Heap represents an array of values which can increase or decrease in size, and is expected to do so a lot. The key requirement of a heap is that capacity is retained in order to prevent subsequent reallocation when the heap expands.
func (*Heap[T]) Alloc ¶
Alloc ensures space for exactly n elements on top of this heap. This may result in allocation only if the underlying capacity is exhausted. The newly allocated region is zeroed: the heap retains capacity across Free/Pop, so without this a fresh allocation would inherit stale values from a previously freed region (e.g. leaking a popped call frame's registers into a new one).
func (*Heap[T]) Clear ¶
func (p *Heap[T]) Clear()
Clear resets the heap to an empty state whilst retaining any allocated capacity.
func (*Heap[T]) Get ¶
Get the value at the given offset in this heap. This will panic if offset >= p.Size().
func (*Heap[T]) Pop ¶
func (p *Heap[T]) Pop() T
Pop exactly one off the heap. This retrieves the top item on the heap, and the frees it.
func (*Heap[T]) Push ¶
func (p *Heap[T]) Push(item T)
Push exactly one item onto the heap. This allocates space for one item, and sets that item accordingly.
func (*Heap[T]) Set ¶
Set the value at the given offset in this heap. This will panic if offset >= p.Size().