heap

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: 1 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

Index

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

func (p *Heap[T]) Alloc(n uint)

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]) Free

func (p *Heap[T]) Free(n uint)

Free simply reduces the size of the heap by the given amount of cells.

func (*Heap[T]) Get

func (p *Heap[T]) Get(offset uint) T

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

func (p *Heap[T]) Set(offset uint, val T)

Set the value at the given offset in this heap. This will panic if offset >= p.Size().

func (*Heap[T]) Size

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

Size returns the current size of this heap.

func (*Heap[T]) Slice

func (p *Heap[T]) Slice(start, end uint) []T

Slice returns a slice of this heap. Again, this will panic if end >= p.Size().

func (*Heap[T]) SliceEnd

func (p *Heap[T]) SliceEnd(start uint) []T

SliceEnd returns a slice of this heap from the given start position upto the end.

Jump to

Keyboard shortcuts

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