set

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: Apache-2.0 Imports: 8 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSorted added in v1.1.17

func IsSorted[S any, T Comparable[T]](items []S, fn func(S) T) bool

IsSorted checks whether a given set of comparable items are in sorted order.

Types

type AnySortedSet

type AnySortedSet[T Comparable[T]] []T

AnySortedSet is an array of unique sorted values (i.e. no duplicates).

func NewAnySortedSet

func NewAnySortedSet[T Comparable[T]](items ...T) *AnySortedSet[T]

NewAnySortedSet creates a sorted set from a given array by first cloning that array, and then sorting it appropriately, etc. This means the given array will not be mutated by this function, or any subsequent calls on the resulting set.

func RawAnySortedSet added in v1.2.0

func RawAnySortedSet[T Comparable[T]](items ...T) *AnySortedSet[T]

RawAnySortedSet creates a sort set from a given array without first cloning it. That means the array may well be mutated by this function and/or subsequent calls to the resulting set.

func UnionAnySortedSets

func UnionAnySortedSets[S any, T Comparable[T]](elems []S, fn func(S) *AnySortedSet[T]) *AnySortedSet[T]

UnionAnySortedSets unions together a number of things which can be turn into a sorted set using a given mapping function. At some level, this is a map/reduce function.

func (*AnySortedSet[T]) Contains

func (p *AnySortedSet[T]) Contains(element T) bool

Contains returns true if a given element is in the set.

func (*AnySortedSet[T]) Find added in v1.1.17

func (p *AnySortedSet[T]) Find(element T) uint

Find returns the index of the matching element in this set, or it returns MaxUInt.

func (*AnySortedSet[T]) Insert

func (p *AnySortedSet[T]) Insert(element T)

Insert an element into this sorted set.

func (*AnySortedSet[T]) InsertSorted

func (p *AnySortedSet[T]) InsertSorted(q *AnySortedSet[T])

InsertSorted inserts all elements in a given sorted set into this set.

func (*AnySortedSet[T]) Iter

func (p *AnySortedSet[T]) Iter() iter.Iterator[T]

Iter returns an iterator over the elements of this sorted set.

func (*AnySortedSet[T]) Remove added in v1.2.0

func (p *AnySortedSet[T]) Remove(element T) bool

Remove an element from this sorted set.

func (*AnySortedSet[T]) ToArray

func (p *AnySortedSet[T]) ToArray() []T

ToArray extracts the underlying array from this sorted set.

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 provides an interface which types used in a AnySortedSet must implement.

type Order

type Order[T cmp.Ordered] struct {
	Item T
}

Order provides a wrapper around primtive types for use with an AnySortedSet. This is mostly for testing purposes.

func (Order[T]) Cmp added in v1.1.17

func (lhs Order[T]) Cmp(rhs Order[T]) int

Cmp implementation for the Comparable interface.

type SortedSet

type SortedSet[T cmp.Ordered] []T

SortedSet is an array of unique sorted values (i.e. no duplicates).

func NewSortedSet

func NewSortedSet[T cmp.Ordered]() *SortedSet[T]

NewSortedSet returns an empty sorted set.

func UnionSortedSets

func UnionSortedSets[S any, T cmp.Ordered](elems []S, fn func(S) *SortedSet[T]) *SortedSet[T]

UnionSortedSets unions together a number of things which can be turn into a sorted set using a given mapping function. At some level, this is a map/reduce function.

func (*SortedSet[T]) Contains

func (p *SortedSet[T]) Contains(element T) bool

Contains returns true if a given element is in the set.

func (*SortedSet[T]) Insert

func (p *SortedSet[T]) Insert(element T)

Insert an element into this sorted set.

func (*SortedSet[T]) InsertSorted

func (p *SortedSet[T]) InsertSorted(q *SortedSet[T])

InsertSorted inserts all elements in a given sorted set into this set.

func (*SortedSet[T]) Intersect added in v1.1.6

func (p *SortedSet[T]) Intersect(q *SortedSet[T])

Intersect removes all elements from this set which are not in the given set.

func (*SortedSet[T]) Iter

func (p *SortedSet[T]) Iter() iter.Iterator[T]

Iter returns an iterator over the elements of this sorted set.

func (*SortedSet[T]) String added in v0.9.1

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

Jump to

Keyboard shortcuts

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