SortedSet

package
v0.0.0-...-3f02f6f Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	Add(item interface{}) Interface
	Delete(item interface{}) Interface
	Has(item interface{}) bool
	Len() int
	IsEmpty() bool
	Each(fn func(item interface{}) Result.Interface) Result.Interface
	ToArray() Array.Interface
	First() Result.Interface
	Last() Result.Interface
	Union(other Interface) Interface
	Intersection(other Interface) Interface
	Difference(other Interface) Interface
	IsSubset(other Interface) bool
	Equal(other Interface) bool
	IsNull() bool
}

Interface is the public contract of a SortedSet composite — a collection of unique items kept permanently sorted by a caller-supplied comparator (TreeSet-like). It is the comparator-ordered sibling of Set (unordered) and OrderedSet (first-insertion order), and shares the Each/ToArray grammar with Array: iteration, ToArray and the set-algebra results are all emitted in ascending comparator order rather than Go's unspecified map order.

Items must satisfy TWO constraints, which the caller must guarantee:

  • comparable, because the SortedSet is backed by a Go map for O(1) membership and dedup (exactly like a Dictionary key); and
  • orderable by the less comparator passed to New, which defines a strict weak ordering used to keep items in sorted position.

Membership tests return a plain bool, fallible iteration returns a Result, First/Last return a Result (the minimum/maximum by the comparator, or an error Result when the set is empty), and every method honours the Null-Object invariant (never nil).

func New

func New(less func(a, b interface{}) bool, items ...interface{}) Interface

New creates a SortedSet ordered by the less comparator and seeded with the given items, deduplicated and inserted in sorted position. Items must be comparable (they back a Go map for membership) AND orderable by less.

func Null

func Null() Interface

Null returns the Null-Object SortedSet.

Jump to

Keyboard shortcuts

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