array

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

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 ENCODING_POOL16_DENSE = 11

ENCODING_POOL16_DENSE is for arrays holding u16 indictes into a pool.

View Source
const ENCODING_POOL16_SPARSE16 = 18

ENCODING_POOL16_SPARSE16 is for arrays holding u16 indictes into a pool, and are stored in a sparse representation (assuming u16 block lengths).

View Source
const ENCODING_POOL16_SPARSE24 = 19

ENCODING_POOL16_SPARSE24 is currently not supported.

View Source
const ENCODING_POOL16_SPARSE32 = 20

ENCODING_POOL16_SPARSE32 is for arrays holding u16 indictes into a pool, and are stored in a sparse representation (assuming u32 block lengths).

View Source
const ENCODING_POOL16_SPARSE8 = 17

ENCODING_POOL16_SPARSE8 is for arrays holding u16 indictes into a pool, and are stored in a sparse representation (assuming u8 block lengths).

View Source
const ENCODING_POOL1_DENSE = 7

ENCODING_POOL1_DENSE is for arrays holding u1 indictes into a pool.

View Source
const ENCODING_POOL2_DENSE = 8

ENCODING_POOL2_DENSE is for arrays holding u2 indictes into a pool.

View Source
const ENCODING_POOL32_DENSE = 12

ENCODING_POOL32_DENSE is for arrays holding u32 indictes into a pool.

View Source
const ENCODING_POOL32_SPARSE16 = 22

ENCODING_POOL32_SPARSE16 is for arrays holding u32 indictes into a pool, and are stored in a sparse representation (assuming u16 block lengths).

View Source
const ENCODING_POOL32_SPARSE24 = 23

ENCODING_POOL32_SPARSE24 is currently not supported.

View Source
const ENCODING_POOL32_SPARSE32 = 24

ENCODING_POOL32_SPARSE32 is for arrays holding u32 indictes into a pool, and are stored in a sparse representation (assuming u32 block lengths).

View Source
const ENCODING_POOL32_SPARSE8 = 21

ENCODING_POOL32_SPARSE8 is for arrays holding u32 indictes into a pool, and are stored in a sparse representation (assuming u8 block lengths).

View Source
const ENCODING_POOL4_DENSE = 9

ENCODING_POOL4_DENSE is for arrays holding u4 indictes into a pool.

View Source
const ENCODING_POOL8_DENSE = 10

ENCODING_POOL8_DENSE is for arrays holding u8 indictes into a pool.

View Source
const ENCODING_POOL8_SPARSE16 = 14

ENCODING_POOL8_SPARSE16 is for arrays holding u8 indictes into a pool, and are stored in a sparse representation (assuming u16 block lengths).

View Source
const ENCODING_POOL8_SPARSE24 = 15

ENCODING_POOL8_SPARSE24 is currently not supported.

View Source
const ENCODING_POOL8_SPARSE32 = 16

ENCODING_POOL8_SPARSE32 is for arrays holding u8 indictes into a pool, and are stored in a sparse representation (assuming u8 block lengths).

View Source
const ENCODING_POOL8_SPARSE8 = 13

ENCODING_POOL8_SPARSE8 is for arrays holding u8 indictes into a pool, and are stored in a sparse representation (assuming u8 block lengths).

View Source
const ENCODING_POOL_CONSTANT = 6

ENCODING_POOL_CONSTANT is for arrays holding a constant index into a pool.

View Source
const ENCODING_STATIC_CONSTANT = 0

ENCODING_STATIC_CONSTANT is for arrays which hold constant values.

View Source
const ENCODING_STATIC_DENSE = 1

ENCODING_STATIC_DENSE is for arrays which hold their values explicitly.

View Source
const ENCODING_STATIC_SPARSE16 = 3

ENCODING_STATIC_SPARSE16 is for arrays which hold their values explicitly, and are stored in a sparse representation (assuming u16 block lengths).

View Source
const ENCODING_STATIC_SPARSE24 = 4

ENCODING_STATIC_SPARSE24 is currently not supported.

View Source
const ENCODING_STATIC_SPARSE32 = 5

ENCODING_STATIC_SPARSE32 is for arrays which hold their values explicitly, and are stored in a sparse representation (assuming u32 block lengths).

View Source
const ENCODING_STATIC_SPARSE8 = 2

ENCODING_STATIC_SPARSE8 is for arrays which hold their values explicitly, and are stored in a sparse representation (assuming u8 block lengths).

Variables

This section is empty.

Functions

func Append

func Append[T any](slice []T, item T) []T

Append creates a new slice containing the result of appending the given item onto the end of the given slice. Observe that, unlike the built-in append() function, this will never modify the given slice.

func AppendAll

func AppendAll[T any](lhs []T, rhs ...T) []T

AppendAll creates a new slice containing the result of appending the given items onto the end of the given slice. Observe that, unlike the built-in append() function, this will never modify the given slice.

func BackPad

func BackPad[T any](slice []T, n uint, item T) []T

BackPad pads an array upto a given length n with a given item. Specifically, new items are inserted at the end of the array.

func BitwidthOfVectors

func BitwidthOfVectors[T any](vectors ...Vector[T]) []uint

BitwidthOfVectors returns the maximum bitwidth of each limb across a given set of vectors.

func Compare

func Compare[T Comparable[T]](lhs []T, rhs []T) int

Compare two slices of ordered elements.

func ContainsMatching

func ContainsMatching[T any](items []T, predicate Predicate[T]) bool

ContainsMatching checks whether a given array contains an item matching a given predicate.

func CountMatching

func CountMatching[T any](items []T, predicate Predicate[T]) uint

CountMatching counts the number of items in the given array for which the predicate returns true.

func CountUnique

func CountUnique[T cmp.Ordered](items []T) uint

CountUnique counts the number of unique items within a given slice.

func Expand

func Expand[T any](data []T, n uint) []T

Expand ensures space for exactly n elements on top of this heap. This may result in allocation only if the underlying capacity is exhausted.

func Filter

func Filter[T any](items []T, predicate Predicate[T]) (nitems []T)

Filter a given slice by retaing only those elements where the given predicate holds.

func FindMatching

func FindMatching[T any](items []T, predicate Predicate[T]) uint

FindMatching determines the index of first matching item in a given array, or returns max.MaxUint otherwise.

func FlatMap

func FlatMap[S, T any](items []S, fn func(S) []T) []T

FlatMap flattens items from an array which expand into arrays of terms.

func Flatten

func Flatten[T any](items []T, fn func(T) []T) []T

Flatten flattens items from an array which expand into arrays of terms.

func FrontPad

func FrontPad[T any](slice []T, n uint, item T) []T

FrontPad pads an array upto a given length n with a given item. Specifically, new items are inserted at the front of the array.

func InsertAllAt

func InsertAllAt[T any](items []T, elements []T, index uint) []T

InsertAllAt constructs an identical slice, except with the given elements inserted at the given index. If the index is beyond the bounds of the array, then the element is simply appended.

func InsertAt

func InsertAt[T any](items []T, element T, index uint) []T

InsertAt constructs an identical slice, except with the element inserted at the given index. If the index is beyond the bounds of the array, then the element is simply appended.

func Map

func Map[S, T any](items []S, mapping func(uint, S) T) []T

Map an array from one type to another using a given mapping (or projection) function.

func MaxWidthOfVectors

func MaxWidthOfVectors[T any](vectors ...Vector[T]) uint

MaxWidthOfVectors returns the maximum width of any vector in a given set of zero or more vectors.

func MergeSorted

func MergeSorted[S Comparable[S]](lhs []S, rhs []S) []S

MergeSorted combines two sorted arrays whilst maintaining the sorted invariant. You can think of this as first appending the second array to the first, then sorting the result. In fact, it uses a merge sort which is slightly more efficient than resorting from scratch.

func Prepend

func Prepend[T any](item T, slice []T) []T

Prepend creates a new slice containing the result of prepending the given item onto the end of the given slice. Observe that, unlike the built-in append() function, this will never modify the given slice.

func RemoveAt

func RemoveAt[T any](items []T, index uint) []T

RemoveAt constructs an identical slice, except with the element at the given index removed. If the index is beyond the bounds of the array, then there is no change.

func RemoveMatching

func RemoveMatching[T any](items []T, predicate Predicate[T]) []T

RemoveMatching removes all elements from an array matching the given item.

func RemoveMatchingIndexed

func RemoveMatchingIndexed[T any](items []T, predicate func(int, T) bool) []T

RemoveMatchingIndexed removes all elements from an array matching the given item.

func ReplaceFirstOrPanic

func ReplaceFirstOrPanic[T comparable](columns []T, from T, to T)

ReplaceFirstOrPanic replaces the first occurrence of a given item (from) in an array with another item (to). If not match is found, then this will panic. In otherwords, we are expecting a match.

func Reverse

func Reverse[T any](items []T) []T

Reverse reverses the contents of an array.

func ReverseInPlace

func ReverseInPlace[T any](items []T)

ReverseInPlace reversees the items in an array in place.

func ToString

func ToString[S fmt.Stringer](arr []S) string

ToString constructs a string representation for an array of values which themselves have String() functions.

func WidthOfVectors

func WidthOfVectors[T any](vectors ...Vector[T]) uint

WidthOfVectors returns the total number of limbs across all vectors.

Types

type Array

type Array[T any] interface {
	// Return the number of bits required to store an element of this array.
	BitWidth() uint
	// Clone this array producing a mutable copy
	Clone() MutArray[T]
	// Get returns the element at the given index in this array.
	Get(uint) T
	// Returns the number of elements in this array.
	Len() uint
	// Slice out a subregion of this array.
	Slice(uint, uint) Array[T]
}

Array provides a generice interface to an array of elements. Typically, we are interested in arrays of field elements here.

type BitArray

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

BitArray implements an array of single bit words simply using an underlying array of packed bytes. That is, where eight bits are packed into a single byte.

func NewBitArray

func NewBitArray[T word.Word[T]](height uint) BitArray[T]

NewBitArray constructs a new word array with a given capacity.

func (*BitArray[T]) Append

func (p *BitArray[T]) Append(word T) MutArray[T]

Append new word on this array

func (*BitArray[T]) BitWidth

func (p *BitArray[T]) BitWidth() uint

BitWidth returns the width (in bits) of elements in this array.

func (*BitArray[T]) Clone

func (p *BitArray[T]) Clone() MutArray[T]

Clone makes clones of this array producing an otherwise identical copy.

func (*BitArray[T]) Get

func (p *BitArray[T]) Get(index uint) T

Get returns the field element at the given index in this array.

func (*BitArray[T]) Len

func (p *BitArray[T]) Len() uint

Len returns the number of elements in this word array.

func (*BitArray[T]) Pad

func (p *BitArray[T]) Pad(n uint, m uint, padding T) MutArray[T]

Pad implementation for MutArray interface.

func (*BitArray[T]) Set

func (p *BitArray[T]) Set(index uint, word T) MutArray[T]

Set sets the field element at the given index in this array, overwriting the original value.

func (*BitArray[T]) SetRaw

func (p *BitArray[T]) SetRaw(index uint, val bool)

SetRaw sets a raw bit at the given index in this array, overwriting the original value.

func (*BitArray[T]) Slice

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

Slice out a subregion of this array.

func (*BitArray[T]) String

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

type Builder

type Builder[T any] interface {
	// NewArray constructs a new array of the given height holding elements of the given bitwidth
	NewArray(height uint, bitwidth uint) MutArray[T]
}

Builder is a mechanism for constructing arrays which aims to select the right representation for a given array.

func NewStaticBuilder

func NewStaticBuilder[T word.Word[T]]() Builder[T]

NewStaticBuilder constructs a new array builder for dynamic words.

type Comparable

type Comparable[T any] interface {
	// Cmp returns < 0 if this is less than other, or 0 if they are equal, or >
	// 0 if this is greater than other.
	Cmp(other T) int
}

Comparable interface which can be implemented by non-primitive types.

type ConstantArray

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

ConstantArray implements an array of a constant value.

func NewConstantArray

func NewConstantArray[T word.Word[T]](height uint, bitwidth uint, value T) *ConstantArray[T]

NewConstantArray constructs a new word array with a given capacity.

func (*ConstantArray[T]) Append

func (p *ConstantArray[T]) Append(word T) MutArray[T]

Append new word on this array

func (*ConstantArray[T]) BitWidth

func (p *ConstantArray[T]) BitWidth() uint

BitWidth returns the width (in bits) of elements in this array.

func (*ConstantArray[T]) Build

func (p *ConstantArray[T]) Build() Array[T]

Build implementation for the array.Builder interface. This simply means that a static array is its own builder.

func (*ConstantArray[T]) Clone

func (p *ConstantArray[T]) Clone() MutArray[T]

Clone makes clones of this array producing an otherwise identical copy.

func (*ConstantArray[T]) Get

func (p *ConstantArray[T]) Get(index uint) T

Get returns the field element at the given index in this array.

func (*ConstantArray[T]) Len

func (p *ConstantArray[T]) Len() uint

Len returns the number of elements in this word array.

func (*ConstantArray[T]) Pad

func (p *ConstantArray[T]) Pad(n uint, m uint, padding T) MutArray[T]

Pad implementation for MutArray interface.

func (*ConstantArray[T]) Set

func (p *ConstantArray[T]) Set(index uint, word T) MutArray[T]

Set sets the field element at the given index in this array, overwriting the original value.

func (*ConstantArray[T]) Slice

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

Slice out a subregion of this array.

func (*ConstantArray[T]) String

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

type DynamicBuilder

type DynamicBuilder[T word.DynamicWord[T], P pool.Pool[uint32, T]] struct {
	// contains filtered or unexported fields
}

DynamicBuilder is for handling dynamic words only.

func NewDynamicBuilder

func NewDynamicBuilder[T word.DynamicWord[T], P pool.Pool[uint32, T]](heap P) DynamicBuilder[T, P]

NewDynamicBuilder constructs a new array builder for dynamic words.

func (*DynamicBuilder[T, P]) Decode

func (p *DynamicBuilder[T, P]) Decode(encoding Encoding) MutArray[T]

Decode reconstructs an array from an array encoding, given the pool as it was when the encoding was made.

func (*DynamicBuilder[T, P]) Encode

func (p *DynamicBuilder[T, P]) Encode(array Array[T]) Encoding

Encode a given array as a sequence of bytes suitable for serialisation.

func (*DynamicBuilder[T, P]) NewArray

func (p *DynamicBuilder[T, P]) NewArray(height uint, bitwidth uint) MutArray[T]

NewArray constructs a new word array with a given capacity.

type Encoding

type Encoding struct {
	// Indicates what encoding method is used for this encoding.
	Encoding uint32
	// Bytes of the encoding itself
	Bytes []byte
}

Encoding represents an encoded form of a word array useful for long term storage (e.g. in a file).

func Encode

func Encode[T word.DynamicWord[T], P Pool[T]](array Array[T]) Encoding

Encode a given array as a sequence of bytes suitable for serialisation.

func (*Encoding) OpCode

func (p *Encoding) OpCode() uint8

OpCode returns the instruction opcode for this encoding.

func (*Encoding) Operand

func (p *Encoding) Operand() uint32

Operand returns the instruction operand for this encoding.

func (*Encoding) Set

func (p *Encoding) Set(opcode uint8, operand uint32)

Set sets the instruction opcode for this encoding.

type MutArray

type MutArray[T any] interface {
	Array[T]
	// Append new element onto the end of array producing an updated array.  In
	// most cases, this updates the array in place and returns it.  In some
	// cases, it may force a change of representation (e.g. moving from a
	// constant array).
	Append(T) MutArray[T]
	// Set the element at the given index in this array, overwriting the
	// original value. In most cases, this updates the array in place and
	// returns it.  In some cases, it may force a change of representation (e.g.
	// moving from a constant array).
	Set(uint, T) MutArray[T]
	// Insert n copies of T at start of the array and m copies at the back. In
	// most cases, this updates the array in place and returns it.  In some
	// cases, it may force a change of representation (e.g. moving from a
	// constant array).
	Pad(uint, uint, T) MutArray[T]
}

MutArray provides a generice interface to an array of elements. Typically, we are interested in arrays of field elements here.

func CloneArray

func CloneArray[W1 word.Word[W1], W2 word.Word[W2]](arr Array[W1], builder Builder[W2]) MutArray[W2]

CloneArray converts a word array for one word geometry into a mutable array for another geometry.

func Decode

func Decode[T word.DynamicWord[T], P Pool[T]](encoding Encoding, heap P) MutArray[T]

Decode a given encoding into a mutable array, using a given heap (which should have been preloaded accordingly).

type MutVector

type MutVector[T any] struct {
	// contains filtered or unexported fields
}

MutVector represents a vector of mutable arrays. As such, this supports not only reading operations but also writing operations.

func MutVectorOf

func MutVectorOf[T any](arrays ...MutArray[T]) MutVector[T]

MutVectorOf constructs a mutable vector from a given set of mutable arrays. All supplied arrays are expected to have the same height, otherwise this will panic.

func NewMutVector

func NewMutVector[T any](height uint, bitwidths []uint, builder Builder[T]) MutVector[T]

NewMutVector creates a new mutable vector with a given number of limbs as determined by the given bitwidths.

func (*MutVector[T]) Len

func (p *MutVector[T]) Len() uint

Len returns the length of each array in this vector.

func (*MutVector[T]) Read

func (p *MutVector[T]) Read(index uint, values []T)

Read the value of each limb at the given index into the given array.

func (*MutVector[T]) Unwrap

func (p *MutVector[T]) Unwrap() []MutArray[T]

Unwrap provides access to the underlying arrays.

func (*MutVector[T]) Width

func (p *MutVector[T]) Width() uint

Width returns the number of arrays in this vector.

func (*MutVector[T]) Write

func (p *MutVector[T]) Write(index uint, values []T)

Write the value of each element in the given array into the corresponding limb at the given index.

type Pool

type Pool[T any] = pool.Pool[uint32, T]

Pool provides a convenient alias

type PoolArray

type PoolArray[K uint8 | uint16 | uint32, T word.Word[T], P pool.Pool[K, T]] struct {
	// contains filtered or unexported fields
}

PoolArray implements an array of elements simply using an underlying array.

func NewPoolArray

func NewPoolArray[K uint8 | uint16 | uint32, T word.Word[T], P pool.Pool[K, T]](height uint, bitwidth uint,
	pool P) *PoolArray[K, T, P]

NewPoolArray constructs a new indexed array.

func (*PoolArray[K, T, P]) Append

func (p *PoolArray[K, T, P]) Append(element T) MutArray[T]

Append adds a new element to the end of this array

func (*PoolArray[K, T, P]) BitWidth

func (p *PoolArray[K, T, P]) BitWidth() uint

BitWidth returns the width (in bits) of elements in this array.

func (*PoolArray[K, T, P]) Clone

func (p *PoolArray[K, T, P]) Clone() MutArray[T]

Clone makes clones of this array producing an otherwise identical copy.

func (*PoolArray[K, T, P]) Get

func (p *PoolArray[K, T, P]) Get(index uint) T

Get returns the field element at the given index in this array.

func (*PoolArray[K, T, P]) Len

func (p *PoolArray[K, T, P]) Len() uint

Len returns the number of elements in this word array.

func (*PoolArray[K, T, P]) Pad

func (p *PoolArray[K, T, P]) Pad(n uint, m uint, padding T) MutArray[T]

Pad implementation for MutArray interface.

func (*PoolArray[K, T, P]) Set

func (p *PoolArray[K, T, P]) Set(index uint, word T) MutArray[T]

Set sets the field element at the given index in this array, overwriting the original value.

func (*PoolArray[K, T, P]) Slice

func (p *PoolArray[K, T, P]) Slice(start uint, end uint) Array[T]

Slice out a subregion of this array.

func (*PoolArray[K, T, P]) String

func (p *PoolArray[K, T, P]) String() string

type Predicate

type Predicate[T any] = func(T) bool

Predicate abstracts the notion of a function which identifies something.

type SmallArray

type SmallArray[K uint8 | uint16 | uint32 | uint64, T word.Word[T]] struct {
	// contains filtered or unexported fields
}

SmallArray implements an array of elements simply using an underlying array.

func NewSmallArray

func NewSmallArray[K uint8 | uint16 | uint32 | uint64, T word.Word[T]](height uint, bitwidth uint) SmallArray[K, T]

NewSmallArray constructs a new word array with a given capacity.

func (*SmallArray[K, T]) Append

func (p *SmallArray[K, T]) Append(word T) MutArray[T]

Append new word on this array

func (*SmallArray[K, T]) BitWidth

func (p *SmallArray[K, T]) BitWidth() uint

BitWidth returns the width (in bits) of elements in this array.

func (*SmallArray[K, T]) Clone

func (p *SmallArray[K, T]) Clone() MutArray[T]

Clone makes clones of this array producing an otherwise identical copy.

func (*SmallArray[K, T]) Get

func (p *SmallArray[K, T]) Get(index uint) T

Get returns the word at the given index in this array.

func (*SmallArray[K, T]) Len

func (p *SmallArray[K, T]) Len() uint

Len returns the number of elements in this word array.

func (*SmallArray[K, T]) Pad

func (p *SmallArray[K, T]) Pad(n uint, m uint, padding T) MutArray[T]

Pad prepend array with n copies and append with m copies of the given padding value.

func (*SmallArray[K, T]) Set

func (p *SmallArray[K, T]) Set(index uint, word T) MutArray[T]

Set the word at the given index in this array, overwriting the original value.

func (*SmallArray[K, T]) SetRaw

func (p *SmallArray[K, T]) SetRaw(index uint, val K)

SetRaw sets a raw value at the given index in this array, overwriting the original value.

func (*SmallArray[K, T]) Slice

func (p *SmallArray[K, T]) Slice(start uint, end uint) Array[T]

Slice out a subregion of this array.

func (*SmallArray[K, T]) String

func (p *SmallArray[K, T]) String() string

type StaticArray

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

StaticArray implements an array of elements simply using an underlying array.

func NewStaticArray

func NewStaticArray[T word.Word[T]](height uint, bitwidth uint) *StaticArray[T]

NewStaticArray constructs a new word array with a given capacity.

func (*StaticArray[T]) Append

func (p *StaticArray[T]) Append(word T) MutArray[T]

Append new word on this array

func (*StaticArray[T]) BitWidth

func (p *StaticArray[T]) BitWidth() uint

BitWidth returns the width (in bits) of elements in this array.

func (*StaticArray[T]) Clone

func (p *StaticArray[T]) Clone() MutArray[T]

Clone makes clones of this array producing an otherwise identical copy.

func (*StaticArray[T]) Get

func (p *StaticArray[T]) Get(index uint) T

Get returns the field element at the given index in this array.

func (*StaticArray[T]) Len

func (p *StaticArray[T]) Len() uint

Len returns the number of elements in this word array.

func (*StaticArray[T]) Pad

func (p *StaticArray[T]) Pad(n uint, m uint, padding T) MutArray[T]

Pad prepend array with n copies and append with m copies of the given padding value.

func (*StaticArray[T]) Set

func (p *StaticArray[T]) Set(index uint, word T) MutArray[T]

Set sets the field element at the given index in this array, overwriting the original value.

func (*StaticArray[T]) Slice

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

Slice out a subregion of this array.

func (*StaticArray[T]) String

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

type Vector

type Vector[T any] struct {
	// contains filtered or unexported fields
}

Vector represents a vector of identically sized arrays. This just makes it easier to work with such vectors, providing various bits of helpful functionality.

func VectorOf

func VectorOf[T any](arrays ...Array[T]) Vector[T]

VectorOf constructs a new vector array from a given set of arrays. All supplied arrays are expected to have the same height, otherwise this will panic.

func (*Vector[T]) All

func (p *Vector[T]) All(index uint, f Predicate[T]) bool

All checks whether, for all limbs, the given predicate holds at a given index.

func (*Vector[T]) Clone

func (p *Vector[T]) Clone() MutVector[T]

Clone each array in this vector, producing a vector of mutable arrays.

func (*Vector[T]) EmptyClone

func (p *Vector[T]) EmptyClone(length uint, builder Builder[T]) MutVector[T]

EmptyClone constructs a vector of mutable arrays of a given height which are all empty, but have matching dimension (i.e. same number of arrays with matching bitwidths).

func (*Vector[T]) Len

func (p *Vector[T]) Len() uint

Len returns the length of each array in this vector.

func (*Vector[T]) Limb

func (p *Vector[T]) Limb(index uint) Array[T]

Limb returns the ith limb in this vector.

func (*Vector[T]) Read

func (p *Vector[T]) Read(index uint, values []T)

Read the value of each limb at the given index into the given array.

func (*Vector[T]) Some

func (p *Vector[T]) Some(index uint, f Predicate[T]) bool

Some checks whether there exists a limb for which the given predicate holds at a given index.

func (*Vector[T]) Width

func (p *Vector[T]) Width() uint

Width returns the number of arrays in this vector.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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