gost

package module
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 14 Imported by: 0

README

gost

GitHub license

Experience the true taste of Rust in Go

document

Install

go get github.com/myyrakle/gost@v0.11.0

Basic Principles

gost implements its main operations through primitive wrappers and traits.

So, you should use the ISize type instead of the int type, and the String type instead of the string type.

import (
	"math"

	. "github.com/myyrakle/gost"
)

func main() {
	a := ISize(1)
	b := ISize(2)
	c := a + b

	Println("{} + {} = {}", a, b, c) // "1 + 2 = 3"

	d := String("foo")
	Println(d) // "foo"
}

Traits

gost defines common operations through a trait-type interface. Most of the traits are similar to Rust's traits.

For example, the Clone trait defines deep copying. This allows you to consistently define and use specific behaviors in a type-safe manner.

func DoSomethingWithClone[T any](source Clone[T]) {
	cloned := source.Clone()
	Println("{}", cloned)
}

func main() {
	vec := VecNew[I32]()
	vec.Push(I32(1))
	vec.Push(I32(2))
	DoSomethingWithClone[Vec[I32]](vec)
}

(Of course, there are limitations to type inference due to Go's poor generic support.)

The basic traits currently provided include the following, and are defined for most types.

  • Clone
  • Display
  • Debug
  • ToString
  • Iterator
  • AsRef
  • Ord
  • Eq
  • Add
  • Sub
  • Mul
  • Div
  • Rem
  • AddAssign
  • SubAssign
  • MulAssign
  • DivAssign
  • RemAssign

Option and Result

gost handles errors through the rusty monad types Option and Result.

For example, CheckedAdd, a function that detects overflow and fails, returns an Option type. If Option is None, it fails, and if Option is Some, it succeeds.

a := I8(150)
b := I8(555)

result := a.CheckedAdd(b)

if result.IsNone() {
	Println("overflow")
} else {
	Println("{}", result.Unwrap())
}

In normal Go, errors are controlled very loosely through regular pointers and tuples, but Option and Result allow for tighter restrictions.

Collections

gost supports all of Rust's collection types: Vec, VecDeque, LinkedList, HashSet, HashMap, BTreeSet, BTreeMap, and BinaryHeap. It is implemented as a generic, and traits and Iterators can be used.

vector sample

vec := VecNew[I32]()
vec.Push(I32(1))
vec.Push(I32(2))
vec.Push(I32(3))
vec.Push(I32(4))
Println("{}", vec)

otherVec := vec.IntoIter().Map(func (e I32) I32 { return e * 2 }).CollectToVec()
Println("{}", vec)

hashset sample

set := HashSetNew[I32]()
set.Insert(gost.I32(3))
set.Insert(gost.I32(4))
set.Insert(gost.I32(5))
set.Insert(gost.I32(6))
set.Insert(gost.I32(7))

Println("{}", set.Contains(I32(33)))
Println("{}", set.Contains(I32(3)))

Println("{}", set)

Documentation

Index

Constants

View Source
const I16_MAX = I16(math.MaxInt16)
View Source
const I16_MIN = I16(math.MinInt16)
View Source
const I32_MAX = I32(math.MaxInt32)
View Source
const I32_MIN = I32(math.MinInt32)
View Source
const I64_MAX = I64(math.MaxInt64)
View Source
const I64_MIN = I64(math.MinInt64)
View Source
const I8_MAX = I8(math.MaxInt8)
View Source
const I8_MIN = I8(math.MinInt8)
View Source
const ISize_MAX = ISize(math.MaxInt)
View Source
const ISize_MIN = ISize(math.MinInt)
View Source
const U16_MAX = U16(math.MaxUint16)
View Source
const U16_MIN = U16(0)
View Source
const U32_MAX = U32(math.MaxUint32)
View Source
const U32_MIN = U32(0)
View Source
const U64_MAX = U64(math.MaxUint64)
View Source
const U64_MIN = U64(0)
View Source
const U8_MAX = U8(math.MaxUint8)
View Source
const U8_MIN = U8(0)
View Source
const USize_MAX = USize(math.MaxUint)
View Source
const USize_MIN = USize(0)

Variables

View Source
var I128_MAX = I128{
	// contains filtered or unexported fields
}
View Source
var I128_MIN = I128{
	// contains filtered or unexported fields
}
View Source
var U128_MAX = U128{
	// contains filtered or unexported fields
}
View Source
var U128_MIN = U128{
	// contains filtered or unexported fields
}

Functions

func Assert added in v0.7.3

func Assert(condition Bool, args ...any)

Asserts that a boolean expression is true at runtime.

gost.Assert(true, "This is true")

func AssertEq added in v0.7.3

func AssertEq[T Eq[T]](lhs T, rhs T, args ...any)

Asserts that two expressions are equal to each other

gost.AssertEq(1, 1, "These are equal")

func AssertNe added in v0.7.3

func AssertNe[T Eq[T]](lhs T, rhs T, args ...any)

Asserts that two expressions are not equal to each other

gost.AssertNe(1, 2, "These are not equal")

func If added in v0.9.0

func If[T any](condition Bool, expression func() T) ifElseContext[T]

If-else statement.

n := I32(5)
foo := If(n == 10, func() String {
	return "This is 10"
}).ElseIf(n == 5, func() String {
	return "This is 5"
}).Else(func() String {
 	return "This is not 5 or 10"
})
AssertEq(foo, String("This is 5"))

func Panic added in v0.7.3

func Panic(message String, args ...any)

Panics the current thread.

gost.Panic("This is a panic")

func Print

func Print(format String, params ...any)

func Println

func Println(format String, params ...any)

func Sleep added in v0.11.0

func Sleep(dur Duration)

Puts the current thread to sleep for at least the specified amount of time.

gost.Sleep(gost.DurationFromSecs(5)) // Sleep for 5 seconds

func Todo added in v0.7.3

func Todo(messages ...String)

Indicates unfinished code.

gost.Todo()

func Unimplemented added in v0.7.3

func Unimplemented(messages ...String)

Indicates unimplemented code by panicking with a message of “not implemented”.

gost.Unimplemented()

func Unreachable added in v0.7.3

func Unreachable(messages ...String)

Indicates unreachable code.

gost.Unreachable()

Types

type Add

type Add[T any] interface {
	Add(rhs T) T
}

Add is a trait for types that support addition.

type AddAssign

type AddAssign[T any] interface {
	AddAssign(rhs T)
}

The addition assignment operator +=.

type Any

type Any interface{}

type AsRef added in v0.7.3

type AsRef[T any] interface {
	AsRef() *T
}

Used to do a cheap reference-to-reference conversion.

type BTreeMap added in v0.7.0

type BTreeMap[K Ord[K], V any] struct {
	// contains filtered or unexported fields
}

An ordered map based on a B-Tree.

func BTreeMapNew added in v0.7.0

func BTreeMapNew[K Ord[K], V any]() BTreeMap[K, V]

Creates an empty BTreeMap.

func (BTreeMap[K, V]) AsRef added in v0.7.3

func (self BTreeMap[K, V]) AsRef() *BTreeMap[K, V]

impl AsRef for BTreeMap

func (*BTreeMap[K, V]) Clear added in v0.7.0

func (self *BTreeMap[K, V]) Clear()

Clears the map, removing all elements.

someMap := gost.BTreeMapNew[gost.String, gost.I32]()
someMap.Insert(gost.String("foo"), gost.I32(1))
someMap.Clear()
gost.AssertEq(someMap.IsEmpty(), gost.Bool(true))

func (*BTreeMap[K, V]) ContainsKey added in v0.7.0

func (self *BTreeMap[K, V]) ContainsKey(key K) Bool

Returns true if the map contains a value for the specified key. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

someMap := gost.BTreeMapNew[gost.String, gost.I32]()
someMap.Insert(gost.String("foo"), gost.I32(1))
gost.AssertEq(someMap.ContainsKey(gost.String("foo")), gost.Bool(true))

func (BTreeMap[K, V]) Debug added in v0.7.0

func (self BTreeMap[K, V]) Debug() String

impl Debug for HashMap

func (BTreeMap[K, V]) Display added in v0.7.0

func (self BTreeMap[K, V]) Display() String

impl Display for BTreeMap

func (BTreeMap[K, V]) Eq added in v0.7.3

func (self BTreeMap[K, V]) Eq(other *BTreeMap[K, V]) bool

impl Eq for BTreeMap

func (*BTreeMap[K, V]) Get added in v0.7.0

func (self *BTreeMap[K, V]) Get(key K) Option[V]

Returns value corresponding to the key.

someMap := gost.BTreeMapNew[gost.String, gost.I32]()
someMap.Insert(gost.String("foo"), gost.I32(1))
gost.AssertEq(someMap.Get(gost.String("foo")), Some[gost.I32](gost.I32(1)))

func (*BTreeMap[K, V]) Insert added in v0.7.0

func (self *BTreeMap[K, V]) Insert(key K, value V) Option[V]

Inserts a key-value pair into the map. If the map did not have this key present, None is returned. If the map did have this key present, the value is updated, and the old value is returned. The key is not updated, though; this matters for types that can be == without being identical. See the module-level documentation for more.

someMap := gost.BTreeMapNew[gost.String, gost.I32]()
gost.AssertEq(someMap.Insert(gost.String("foo"), gost.I32(1)), None[gost.I32]())
gost.AssertEq(someMap.IsEmpty(), gost.Bool(false)))

someMap.Insert(gost.String("foo"), gost.I32(2))
gost.AssertEq(someMap.Insert(gost.String("foo"), gost.I32(3)), Some[gost.I32](gost.I32(2)))

func (BTreeMap[K, V]) IntoIter added in v0.7.0

func (self BTreeMap[K, V]) IntoIter() Iterator[Pair[K, V]]

into_iter

func (*BTreeMap[K, V]) IsEmpty added in v0.7.0

func (self *BTreeMap[K, V]) IsEmpty() Bool

Returns true if the map contains no elements.

someMap := gost.BTreeMapNew[gost.String, gost.I32]()
someMap.Insert(gost.String("foo"), gost.I32(1))
gost.AssertEq(someMap.IsEmpty(), gost.Bool(false))

func (BTreeMap[K, V]) Keys added in v0.7.0

func (self BTreeMap[K, V]) Keys() Iterator[K]

An iterator visiting all keys in arbitrary order. The iterator element type is K.

someMap := gost.BTreeMapNew[gost.String, gost.I32]()
someMap.Insert(gost.String("foo"), gost.I32(1))
someMap.Insert(gost.String("bar"), gost.I32(2))
someMap.Insert(gost.String("baz"), gost.I32(3))
keys := someMap.Keys().CollectToVec()
gost.AssertEq(keys.Len(), gost.USize(3))

func (*BTreeMap[K, V]) Len added in v0.7.0

func (self *BTreeMap[K, V]) Len() USize

Returns the number of elements in the map.

someMap := gost.BTreeMapNew[gost.String, gost.I32]()
someMap.Insert(gost.String("foo"), gost.I32(1))
gost.AssertEq(someMap.Len(), gost.USize(1))

func (*BTreeMap[K, V]) Remove added in v0.7.0

func (self *BTreeMap[K, V]) Remove(key K) Option[V]

Removes a key from the map, returning the value at the key if the key was previously in the map. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

someMap := gost.BTreeMapNew[gost.String, gost.I32]()
someMap.Insert(gost.String("foo"), gost.I32(1))
gost.AssertEq(someMap.Remove(gost.String("foo")), Some[gost.I32](gost.I32(1)))

func (BTreeMap[K, V]) Values added in v0.7.0

func (self BTreeMap[K, V]) Values() Iterator[V]

An iterator visiting all values in arbitrary order. The iterator element type is V.

someMap := gost.BTreeMapNew[gost.String, gost.I32]()
someMap.Insert(gost.String("foo"), gost.I32(1))
someMap.Insert(gost.String("bar"), gost.I32(2))
someMap.Insert(gost.String("baz"), gost.I32(3))
values := someMap.Values().CollectToVec()
gost.AssertEq(values.Len(), gost.USize(3))

type BTreeMapIter added in v0.7.0

type BTreeMapIter[K Ord[K], V any] struct {
	// contains filtered or unexported fields
}

func (BTreeMapIter[K, V]) CollectToLinkedList added in v0.7.0

func (self BTreeMapIter[K, V]) CollectToLinkedList() LinkedList[Pair[K, V]]

Collect to LinkedList

func (BTreeMapIter[K, V]) CollectToVec added in v0.7.0

func (self BTreeMapIter[K, V]) CollectToVec() Vec[Pair[K, V]]

Collect to Vec

func (*BTreeMapIter[K, V]) Filter added in v0.7.0

func (self *BTreeMapIter[K, V]) Filter(f func(Pair[K, V]) Bool) Iterator[Pair[K, V]]

filter

func (*BTreeMapIter[K, V]) Fold added in v0.7.0

func (self *BTreeMapIter[K, V]) Fold(init Pair[K, V], f func(Pair[K, V], Pair[K, V]) Pair[K, V]) Pair[K, V]

fold

func (*BTreeMapIter[K, V]) Map added in v0.7.0

func (self *BTreeMapIter[K, V]) Map(f func(Pair[K, V]) Pair[K, V]) Iterator[Pair[K, V]]

map

func (*BTreeMapIter[K, V]) Next added in v0.7.0

func (self *BTreeMapIter[K, V]) Next() Option[Pair[K, V]]

next

func (BTreeMapIter[K, V]) Rev added in v0.7.0

func (self BTreeMapIter[K, V]) Rev() Iterator[Pair[K, V]]

rev

type BTreeMapKeys added in v0.7.0

type BTreeMapKeys[K any] struct {
	// contains filtered or unexported fields
}

An iterator visiting all keys in arbitrary order. The iterator element type is K.

func (BTreeMapKeys[K]) CollectToLinkedList added in v0.7.0

func (self BTreeMapKeys[K]) CollectToLinkedList() LinkedList[K]

Collect to LinkedList

func (BTreeMapKeys[K]) CollectToVec added in v0.7.0

func (self BTreeMapKeys[K]) CollectToVec() Vec[K]

Collect to Vec

func (*BTreeMapKeys[K]) Filter added in v0.7.0

func (self *BTreeMapKeys[K]) Filter(f func(K) Bool) Iterator[K]

filter

func (*BTreeMapKeys[K]) Fold added in v0.7.0

func (self *BTreeMapKeys[K]) Fold(init K, f func(K, K) K) K

fold

func (*BTreeMapKeys[K]) Map added in v0.7.0

func (self *BTreeMapKeys[K]) Map(f func(K) K) Iterator[K]

map

func (*BTreeMapKeys[K]) Next added in v0.7.0

func (self *BTreeMapKeys[K]) Next() Option[K]

next

func (BTreeMapKeys[K]) Rev added in v0.7.0

func (self BTreeMapKeys[K]) Rev() Iterator[K]

rev

type BTreeMapValues added in v0.7.0

type BTreeMapValues[V any] struct {
	// contains filtered or unexported fields
}

An iterator visiting all values in arbitrary order. The iterator element type is V.

func (BTreeMapValues[V]) CollectToLinkedList added in v0.7.0

func (self BTreeMapValues[V]) CollectToLinkedList() LinkedList[V]

Collect to LinkedList

func (BTreeMapValues[V]) CollectToVec added in v0.7.0

func (self BTreeMapValues[V]) CollectToVec() Vec[V]

Collect to Vec

func (*BTreeMapValues[V]) Filter added in v0.7.0

func (self *BTreeMapValues[V]) Filter(f func(V) Bool) Iterator[V]

filter

func (*BTreeMapValues[V]) Fold added in v0.7.0

func (self *BTreeMapValues[V]) Fold(init V, f func(V, V) V) V

fold

func (*BTreeMapValues[V]) Map added in v0.7.0

func (self *BTreeMapValues[V]) Map(f func(V) V) Iterator[V]

map

func (*BTreeMapValues[V]) Next added in v0.7.0

func (self *BTreeMapValues[V]) Next() Option[V]

next

func (BTreeMapValues[V]) Rev added in v0.7.0

func (self BTreeMapValues[V]) Rev() Iterator[V]

rev

type BTreeNode added in v0.7.0

type BTreeNode[K Ord[K], V any] struct {
	// contains filtered or unexported fields
}

type BTreeSet added in v0.7.0

type BTreeSet[K Ord[K]] struct {
	// contains filtered or unexported fields
}

A ordered set based on a B-Tree.

func BTreeSetNew added in v0.7.0

func BTreeSetNew[K Ord[K]]() BTreeSet[K]

Creates an empty BTreeSet.

func (BTreeSet[K]) AsRef added in v0.7.3

func (self BTreeSet[K]) AsRef() *BTreeSet[K]

impl AsRef for BTreeSet

func (*BTreeSet[K]) Clear added in v0.7.0

func (self *BTreeSet[K]) Clear()

Clears the set, removing all elements.

set := gost.BTreeSetNew[Int]()
set.Insert(gost.I32(1))
set.Insert(gost.I32(2))
set.Clear()
gost.AssertEq(set.Len(), gost.USize(0))

func (BTreeSet[K]) Clone added in v0.7.3

func (self BTreeSet[K]) Clone() BTreeSet[K]

impl Clone for BTreeSet

func (*BTreeSet[K]) Contains added in v0.7.0

func (self *BTreeSet[K]) Contains(key K) Bool

Returns true if the set contains an element equal to the value. The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form must match the ordering on the element type.

set := gost.BTreeSetNew[Int]()
set.Insert(gost.I32(1))
set.Insert(gost.I32(2))
gost.Assert(set.Contains(gost.I32(1)))
gost.Assert(!set.Contains(gost.I32(3)))

func (BTreeSet[K]) Debug added in v0.7.0

func (self BTreeSet[K]) Debug() String

impl Debug for BTreeSet

func (BTreeSet[K]) Display added in v0.7.0

func (self BTreeSet[K]) Display() String

impl Display for BTreeSet

func (BTreeSet[K]) Eq added in v0.7.3

func (self BTreeSet[K]) Eq(other BTreeSet[K]) Bool

impl Eq for BTreeSet

func (*BTreeSet[K]) Insert added in v0.7.0

func (self *BTreeSet[K]) Insert(key K) Bool

Adds a value to the set. Returns whether the value was newly inserted. That is: If the set did not previously contain an equal value, true is returned. If the set already contained an equal value, false is returned, and the entry is not updated.

set := gost.BTreeSetNew[Int]()
gost.Assert(set.Insert(gost.I32(1)))
gost.Assert(!set.Insert(gost.I32(1)))

func (BTreeSet[K]) Intersection added in v0.10.0

func (self BTreeSet[K]) Intersection(other BTreeSet[K]) BTreeSet[K]

Visits the elements representing the intersection, i.e., the elements that are both in self and other, in ascending order.

set1 := gost.BTreeSetNew[I32]()
set1.Insert(gost.I32(1))
set1.Insert(gost.I32(2))
set1.Insert(gost.I32(5))

set2 := gost.BTreeSetNew[I32]()
set2.Insert(gost.I32(1))
set2.Insert(gost.I32(2))
set2.Insert(gost.I32(3))

intersection := set1.Intersection(set2)
gost.Assert(intersection.Len() == gost.USize(2))
gost.Assert(intersection.Contains(gost.I32(1)))
gost.Assert(intersection.Contains(gost.I32(2)))

func (*BTreeSet[K]) IntoIter added in v0.7.0

func (self *BTreeSet[K]) IntoIter() Iterator[K]

into_iter

func (BTreeSet[K]) IsDisjoint added in v0.10.0

func (self BTreeSet[K]) IsDisjoint(other BTreeSet[K]) Bool

Returns true if self has no elements in common with other. This is equivalent to checking for an empty intersection.

set1 := gost.BTreeSetNew[I32]()
set1.Insert(gost.I32(1))
set1.Insert(gost.I32(2))

set2 := gost.BTreeSetNew[I32]()
set2.Insert(gost.I32(3))
set2.Insert(gost.I32(4))

gost.Assert(set1.IsDisjoint(set2))

func (BTreeSet[K]) IsEmpty added in v0.7.0

func (self BTreeSet[K]) IsEmpty() Bool

Returns true if the set contains no elements.

set := gost.BTreeSetNew[Int]()
gost.Assert(set.IsEmpty())

set.Insert(gost.I32(1))
gost.Assert(!set.IsEmpty())

func (BTreeSet[K]) IsSubset added in v0.10.0

func (self BTreeSet[K]) IsSubset(other BTreeSet[K]) Bool

Returns true if the set is a subset of another, i.e., other contains at least all the elements in self.

set1 := gost.BTreeSetNew[I32]()
set1.Insert(gost.I32(1))
set1.Insert(gost.I32(2))

set2 := gost.BTreeSetNew[I32]()
set2.Insert(gost.I32(1))
set2.Insert(gost.I32(2))
set2.Insert(gost.I32(3))

gost.Assert(set1.IsSubset(set2))
gost.Assert(!set2.IsSubset(set1))

func (BTreeSet[K]) IsSuperset added in v0.10.0

func (self BTreeSet[K]) IsSuperset(other BTreeSet[K]) Bool

Returns true if the set is a superset of another, i.e., self contains at least all the elements in other.

set1 := gost.BTreeSetNew[I32]()
set1.Insert(gost.I32(1))
set1.Insert(gost.I32(2))

set2 := gost.BTreeSetNew[I32]()
set2.Insert(gost.I32(1))
set2.Insert(gost.I32(2))
set2.Insert(gost.I32(3))

gost.Assert(!set1.IsSuperset(set2))
gost.Assert(set2.IsSuperset(set1))

func (BTreeSet[K]) Len added in v0.7.0

func (self BTreeSet[K]) Len() USize

Returns the number of elements in the set.

set := gost.BTreeSetNew[Int]()
gost.AssertEq(set.Len(), gost.USize(0))

set.Insert(gost.I32(1))
gost.AssertEq(set.Len(), gost.USize(1))

func (*BTreeSet[K]) Remove added in v0.7.0

func (self *BTreeSet[K]) Remove(key K) Bool

If the set contains an element equal to the value, removes it from the set and drops it. Returns whether such an element was present. The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form must match the ordering on the element type.

set := gost.BTreeSetNew[Int]()
set.Insert(gost.I32(1))
set.Insert(gost.I32(2))
gost.Assert(set.Remove(gost.I32(1)))
gost.Assert(!set.Remove(gost.I32(3)))

func (BTreeSet[K]) SymmetricDifference added in v0.10.0

func (self BTreeSet[K]) SymmetricDifference(other BTreeSet[K]) BTreeSet[K]

Visits the elements representing the symmetric difference, i.e., the elements that are in self or in other but not in both, in ascending order.

set1 := gost.BTreeSetNew[I32]()
set1.Insert(gost.I32(1))
set1.Insert(gost.I32(2))
set1.Insert(gost.I32(5))

set2 := gost.BTreeSetNew[I32]()
set2.Insert(gost.I32(1))
set2.Insert(gost.I32(2))
set2.Insert(gost.I32(3))

symmetricDifference := set1.SymmetricDifference(set2)
gost.Assert(symmetricDifference.Len() == gost.USize(2))
gost.Assert(symmetricDifference.Contains(gost.I32(3)))
gost.Assert(symmetricDifference.Contains(gost.I32(5)))

func (BTreeSet[K]) Union added in v0.10.0

func (self BTreeSet[K]) Union(other BTreeSet[K]) BTreeSet[K]

Visits the elements representing the union, i.e., all the elements in self or other, without duplicates, in ascending order.

set1 := gost.BTreeSetNew[I32]()
set1.Insert(gost.I32(1))
set1.Insert(gost.I32(2))
set1.Insert(gost.I32(3))

set2 := gost.BTreeSetNew[I32]()
set2.Insert(gost.I32(3))
set2.Insert(gost.I32(4))

union := set1.Union(set2)
gost.Assert(union.Len() == gost.USize(4))
gost.Assert(union.Contains(gost.I32(1)))
gost.Assert(union.Contains(gost.I32(2)))
gost.Assert(union.Contains(gost.I32(3)))
gost.Assert(union.Contains(gost.I32(4)))

type BTreeSetIter added in v0.7.0

type BTreeSetIter[K Ord[K]] struct {
	// contains filtered or unexported fields
}

Returns an iterator over the set.

func (BTreeSetIter[K]) CollectToLinkedList added in v0.7.0

func (self BTreeSetIter[K]) CollectToLinkedList() LinkedList[K]

Collect to LinkedList

func (BTreeSetIter[K]) CollectToVec added in v0.7.0

func (self BTreeSetIter[K]) CollectToVec() Vec[K]

Collect to Vec

func (BTreeSetIter[K]) Filter added in v0.7.0

func (self BTreeSetIter[K]) Filter(f func(K) Bool) Iterator[K]

filter

func (BTreeSetIter[K]) Fold added in v0.7.0

func (self BTreeSetIter[K]) Fold(init K, f func(K, K) K) K

fold

func (BTreeSetIter[K]) Map added in v0.7.0

func (self BTreeSetIter[K]) Map(f func(K) K) Iterator[K]

map

func (*BTreeSetIter[K]) Next added in v0.7.0

func (self *BTreeSetIter[K]) Next() Option[K]

next

func (BTreeSetIter[K]) Rev added in v0.7.0

func (self BTreeSetIter[K]) Rev() Iterator[K]

rev

type BinaryHeap added in v0.9.0

type BinaryHeap[T Ord[T]] struct {
	// contains filtered or unexported fields
}

A priority queue implemented with a binary heap. This will be a max-heap. It is a logic error for an item to be modified in such a way that the item’s ordering relative to any other item, as determined by the Ord trait, changes while it is in the heap. This is normally only possible through interior mutability, global state, I/O, or unsafe code. The behavior resulting from such a logic error is not specified, but will be encapsulated to the BinaryHeap that observed the logic error and not result in undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and non-termination. As long as no elements change their relative order while being in the heap as described above, the API of BinaryHeap guarantees that the heap invariant remains intact i.e. its methods all behave as documented. For example if a method is documented as iterating in sorted order, that’s guaranteed to work as long as elements in the heap have not changed order, even in the presence of closures getting unwinded out of, iterators getting leaked, and similar foolishness.

func BinaryHeapNew added in v0.9.0

func BinaryHeapNew[T Ord[T]]() BinaryHeap[T]

Constructs a new, empty BinaryHeapNew<T>.

func BinaryHeapWithCapacity added in v0.9.0

func BinaryHeapWithCapacity[T Ord[T]](capacity USize) BinaryHeap[T]

Constructs a new, empty BinaryHeap<T> with at least the specified capacity.

func BinaryHeapWithLen added in v0.9.0

func BinaryHeapWithLen[T Ord[T]](len USize) BinaryHeap[T]

Constructs a new, empty BinaryHeap<T> with at least the specified len.

func (*BinaryHeap[T]) Append added in v0.9.0

func (self *BinaryHeap[T]) Append(other *BinaryHeap[T])

Moves all the elements of other into self, leaving other empty.

	heap := gost.BinaryHeapNew[gost.I32]()
	heap.Push(1)
	heap.Push(2)
	heap.Push(3)
	heap2 := gost.BinaryHeapNew[gost.I32]()
	heap2.Push(4)
	heap2.Push(5)
 heap.Append(&heap2)
	gost.AssertEq(heap.Len(), gost.USize(5))
	gost.AssertEq(heap2.Len(), gost.USize(0))

func (*BinaryHeap[T]) AsSlice added in v0.9.0

func (self *BinaryHeap[T]) AsSlice() []T

Extracts a slice containing the entire heap.

func (BinaryHeap[T]) Capacity added in v0.9.0

func (self BinaryHeap[T]) Capacity() USize

Returns the total number of elements the heap can hold without reallocating.

heap := gost.BinaryHeapNew[gost.I32]()
gost.AssertEq(heap.Capacity(), gost.USize(0))

heap.Reserve(10)
gost.AssertEq(heap.Capacity(), gost.USize(10))

func (*BinaryHeap[T]) Clear added in v0.9.0

func (self *BinaryHeap[T]) Clear()

Clears the heap, removing all values.

heap := gost.BinaryHeapNew[gost.I32]()
heap.Push(1)
heap.Push(2)
heap.Push(3)
heap.Clear()
gost.AssertEq(heap.Len(), gost.USize(0))

func (*BinaryHeap[T]) IntoSortedVec added in v0.9.0

func (self *BinaryHeap[T]) IntoSortedVec() Vec[T]

Consumes the BinaryHeap and returns a vector in sorted (ascending) order.

	heap := gost.BinaryHeapNew[gost.I32]()
	heap.Push(1)
	heap.Push(3)
	heap.Push(2)
 vec := gost.VecNew[gost.I32]()
 vec.Push(1)
 vec.Push(2)
 vec.Push(3)
	gost.AssertEq(heap.IntoSortedVec(), vec)

func (*BinaryHeap[T]) IntoVec added in v0.9.0

func (self *BinaryHeap[T]) IntoVec() Vec[T]

Consumes the BinaryHeap and returns the underlying vector in arbitrary order.

	heap := gost.BinaryHeapNew[gost.I32]()
	heap.Push(1)
	heap.Push(2)
	heap.Push(3)
 vec := gost.VecNew[gost.I32]()
 vec.Push(3)
 vec.Push(1)
 vec.Push(2)
	gost.AssertEq(heap.IntoVec(), vec)

func (BinaryHeap[T]) IsEmpty added in v0.9.0

func (self BinaryHeap[T]) IsEmpty() Bool

Returns true if the heap contains no elements.

heap := gost.BinaryHeapNew[gost.I32]()
gost.Assert(heap.IsEmpty())

heap.Push(1)
gost.Assert(!heap.IsEmpty())

func (BinaryHeap[T]) Len added in v0.9.0

func (self BinaryHeap[T]) Len() USize

Returns the number of elements in the heap, also referred to as its ‘length’.

heap := gost.BinaryHeapNew[gost.I32]()
gost.AssertEq(heap.Len(), gost.USize(0))

heap.Push(1)
gost.AssertEq(heap.Len(), gost.USize(1))

func (*BinaryHeap[T]) Pop added in v0.9.0

func (self *BinaryHeap[T]) Pop() Option[T]

Removes the greatest item from the binary heap and returns it, or None if it is empty.

	heap := gost.BinaryHeapNew[gost.I32]()
	heap.Push(1)
	heap.Push(2)
	heap.Push(3)
 gost.AssertEq(heap.Len(), gost.I32(3))
 gost.AssertEq(heap.Pop(), gost.Some[gost.I32](3))
 gost.AssertEq(heap.Len(), gost.I32(2))

func (*BinaryHeap[T]) Push added in v0.9.0

func (self *BinaryHeap[T]) Push(item T)

Pushes an item onto the binary heap.

heap := gost.BinaryHeapNew[gost.I32]() heap.Push(1) gost.AssertEq(heap.Len(), gost.USize(1))

func (*BinaryHeap[T]) Reserve added in v0.9.0

func (self *BinaryHeap[T]) Reserve(capacity USize)

Reserves capacity for at least additional more elements to be inserted in the given Vec<T>. The collection may reserve more space to speculatively avoid frequent reallocations. After calling reserve, capacity will be greater than or equal to self.len() + additional. Does nothing if capacity is already sufficient.

deque := gost.BinaryHeapNew[gost.I32]()
gost.AssertEq(deque.Capacity(), gost.USize(0))

deque.Reserve(10)
gost.AssertEq(deque.Capacity(), gost.USize(10))

type Bool

type Bool bool

func (Bool) AsRef added in v0.7.3

func (self Bool) AsRef() *Bool

func (Bool) Clone

func (self Bool) Clone() Bool

func (Bool) Cmp

func (self Bool) Cmp(rhs Bool) Ordering

func (Bool) Debug

func (self Bool) Debug() String

func (Bool) Display

func (self Bool) Display() String

func (Bool) Eq

func (self Bool) Eq(rhs Bool) Bool

func (Bool) ToString

func (self Bool) ToString() String

type Byte

type Byte byte

func (Byte) Add added in v0.6.0

func (self Byte) Add(rhs Byte) Byte

func (*Byte) AddAssign added in v0.6.0

func (self *Byte) AddAssign(rhs Byte)

func (Byte) AsRef added in v0.7.3

func (self Byte) AsRef() *Byte

func (Byte) Clone

func (self Byte) Clone() Byte

func (Byte) Cmp

func (self Byte) Cmp(rhs Byte) Ordering

func (Byte) Debug

func (self Byte) Debug() String

func (Byte) Display

func (self Byte) Display() String

func (Byte) Div added in v0.6.0

func (self Byte) Div(rhs Byte) Byte

func (*Byte) DivAssign added in v0.6.0

func (self *Byte) DivAssign(rhs Byte)

func (Byte) Eq

func (self Byte) Eq(rhs Byte) Bool

func (Byte) Mul added in v0.6.0

func (self Byte) Mul(rhs Byte) Byte

func (*Byte) MulAssign added in v0.6.0

func (self *Byte) MulAssign(rhs Byte)

func (Byte) Sub added in v0.6.0

func (self Byte) Sub(rhs Byte) Byte

func (*Byte) SubAssign added in v0.6.0

func (self *Byte) SubAssign(rhs Byte)

func (Byte) ToString

func (self Byte) ToString() String

type Char added in v0.6.0

type Char rune

func (Char) Add added in v0.6.0

func (self Char) Add(rhs Char) Char

func (*Char) AddAssign added in v0.6.0

func (self *Char) AddAssign(rhs Char)

func (Char) AsRef added in v0.7.3

func (self Char) AsRef() *Char

func (Char) Clone added in v0.6.0

func (self Char) Clone() Char

func (Char) Cmp added in v0.6.0

func (self Char) Cmp(rhs Char) Ordering

func (Char) Debug added in v0.6.0

func (self Char) Debug() String

func (Char) Display added in v0.6.0

func (self Char) Display() String

func (Char) Div added in v0.6.0

func (self Char) Div(rhs Char) Char

func (*Char) DivAssign added in v0.6.0

func (self *Char) DivAssign(rhs Char)

func (Char) Eq added in v0.6.0

func (self Char) Eq(rhs Char) Bool

func (Char) Mul added in v0.6.0

func (self Char) Mul(rhs Char) Char

func (*Char) MulAssign added in v0.6.0

func (self *Char) MulAssign(rhs Char)

func (Char) Sub added in v0.6.0

func (self Char) Sub(rhs Char) Char

func (*Char) SubAssign added in v0.6.0

func (self *Char) SubAssign(rhs Char)

func (Char) ToString added in v0.6.0

func (self Char) ToString() String

type Clone

type Clone[T any] interface {
	Clone() T
}

A common trait for the ability to explicitly duplicate an object.

type Complex128

type Complex128 complex128

func (Complex128) Add added in v0.6.0

func (self Complex128) Add(rhs Complex128) Complex128

func (*Complex128) AddAssign added in v0.6.0

func (self *Complex128) AddAssign(rhs Complex128)

func (Complex128) AsRef added in v0.7.3

func (self Complex128) AsRef() *Complex128

func (Complex128) Clone

func (self Complex128) Clone() Complex128

func (Complex128) Debug

func (self Complex128) Debug() String

func (Complex128) Display

func (self Complex128) Display() String

func (Complex128) Div added in v0.6.0

func (self Complex128) Div(rhs Complex128) Complex128

func (*Complex128) DivAssign added in v0.6.0

func (self *Complex128) DivAssign(rhs Complex128)

func (Complex128) Mul added in v0.6.0

func (self Complex128) Mul(rhs Complex128) Complex128

func (*Complex128) MulAssign added in v0.6.0

func (self *Complex128) MulAssign(rhs Complex128)

func (Complex128) Sub added in v0.6.0

func (self Complex128) Sub(rhs Complex128) Complex128

func (*Complex128) SubAssign added in v0.6.0

func (self *Complex128) SubAssign(rhs Complex128)

func (Complex128) ToString

func (self Complex128) ToString() String

type Complex64

type Complex64 complex64

func (Complex64) Add added in v0.6.0

func (self Complex64) Add(rhs Complex64) Complex64

func (*Complex64) AddAssign added in v0.6.0

func (self *Complex64) AddAssign(rhs Complex64)

func (Complex64) AsRef added in v0.7.3

func (self Complex64) AsRef() *Complex64

func (Complex64) Clone

func (self Complex64) Clone() Complex64

func (Complex64) Debug

func (self Complex64) Debug() String

func (Complex64) Display

func (self Complex64) Display() String

func (Complex64) Div added in v0.6.0

func (self Complex64) Div(rhs Complex64) Complex64

func (*Complex64) DivAssign added in v0.6.0

func (self *Complex64) DivAssign(rhs Complex64)

func (Complex64) Mul added in v0.6.0

func (self Complex64) Mul(rhs Complex64) Complex64

func (*Complex64) MulAssign added in v0.6.0

func (self *Complex64) MulAssign(rhs Complex64)

func (Complex64) Sub added in v0.6.0

func (self Complex64) Sub(rhs Complex64) Complex64

func (*Complex64) SubAssign added in v0.6.0

func (self *Complex64) SubAssign(rhs Complex64)

func (Complex64) ToString

func (self Complex64) ToString() String

type Debug

type Debug[T any] interface {
	Debug() string
}

? formatting. Debug should format the output in a programmer-facing, debugging context.

type Default

type Default[T any] interface {
	Default() T
}

A trait for giving a type a useful default value.

type DirEntry

type DirEntry struct {
	FileName String
	Path     String
	FileType FileType
}

type Display

type Display[T any] interface {
	Display() String
}

Format trait for an empty format, {}

type Div

type Div[T any] interface {
	Div(rhs T) T
}

Div is a trait for types that support division.

type DivAssign

type DivAssign[T any] interface {
	DivAssign(rhs T)
}

The division assignment operator /=.

type Duration added in v0.11.0

type Duration struct {
	// contains filtered or unexported fields
}

A Duration type to represent a span of time, typically used for system timeouts. Each Duration is composed of a whole number of seconds and a fractional part represented in nanoseconds. If the underlying system does not support nanosecond-level precision, APIs binding a system timeout will typically round up the number of nanoseconds.

func DurationFromMicros added in v0.11.0

func DurationFromMicros(micros U64) Duration

Creates a new Duration from the specified number of microseconds.

func DurationFromMillis added in v0.11.0

func DurationFromMillis(millis U64) Duration

Creates a new Duration from the specified number of milliseconds.

func DurationFromNanos added in v0.11.0

func DurationFromNanos(nanos U64) Duration

Creates a new Duration from the specified number of nanoseconds.

func DurationFromSecs added in v0.11.0

func DurationFromSecs(secs U64) Duration

Creates a new Duration from the specified number of whole seconds.

func DurationNew added in v0.11.0

func DurationNew(secs U64, nanos U32) Duration

Creates a new Duration from the specified number of whole seconds and additional nanoseconds. If the number of nanoseconds is greater than 1 billion (the number of nanoseconds in a second), then it will carry over into the seconds provided.

func (Duration) AsMicros added in v0.11.0

func (self Duration) AsMicros() U128

Returns the total number of whole microseconds contained by this Duration.

func (Duration) AsMillis added in v0.11.0

func (self Duration) AsMillis() U128

Returns the total number of whole milliseconds contained by this Duration.

func (Duration) AsNanos added in v0.11.0

func (self Duration) AsNanos() U128

Returns the total number of nanoseconds contained by this Duration.

func (Duration) AsSecs added in v0.11.0

func (self Duration) AsSecs() U64

Returns the number of whole seconds contained by this Duration. The returned value does not include the fractional (nanosecond) part of the duration, which can be obtained using subsec_nanos.

func (Duration) IsZero added in v0.11.0

func (self Duration) IsZero() bool

Returns true if this Duration spans no time.

func (Duration) SubsecMicros added in v0.11.0

func (self Duration) SubsecMicros() U32

Returns the fractional part of this Duration, in whole microseconds. This method does not return the length of the duration when represented by microseconds. The returned number always represents a fractional portion of a second (i.e., it is less than one million).

func (Duration) SubsecMillis added in v0.11.0

func (self Duration) SubsecMillis() U32

Returns the fractional part of this Duration, in whole milliseconds. This method does not return the length of the duration when represented by milliseconds. The returned number always represents a fractional portion of a second (i.e., it is less than one thousand).

func (Duration) SubsecNanos added in v0.11.0

func (self Duration) SubsecNanos() U32

Returns the fractional part of this Duration, in nanoseconds. This method does not return the length of the duration when represented by nanoseconds. The returned number always represents a fractional portion of a second (i.e., it is less than one billion).

type Eq

type Eq[T any] interface {
	Eq(rhs T) Bool
}

Trait for equality comparisons which are equivalence relations.

type Error

type Error error

type F32 added in v0.6.0

type F32 float32

func (F32) Abs added in v0.10.0

func (self F32) Abs() F32

Computes the absolute value of self.

f := gost.F32(-3.0)
g := gost.F32(3.0)

gost.AssertEq(f.Abs(), F32(3.0))
gost.AssertEq(g.Abs(), F32(3.0))

func (F32) Add added in v0.6.0

func (self F32) Add(rhs F32) F32

func (*F32) AddAssign added in v0.6.0

func (self *F32) AddAssign(rhs F32)

func (F32) AsRef added in v0.7.3

func (self F32) AsRef() *F32

func (F32) Ceil added in v0.10.0

func (self F32) Ceil() F32

Returns the smallest integer greater than or equal to self.

f := gost.F32(3.01)
g := gost.F32(4.0)

gost.AssertEq(f.Ceil(), F32(4.0))
gost.AssertEq(g.Ceil(), F32(4.0))

func (F32) Clone added in v0.6.0

func (self F32) Clone() F32

func (F32) Cmp added in v0.6.0

func (self F32) Cmp(rhs F32) Ordering

func (F32) Debug added in v0.6.0

func (self F32) Debug() String

func (F32) Display added in v0.6.0

func (self F32) Display() String

func (F32) Div added in v0.6.0

func (self F32) Div(rhs F32) F32

func (*F32) DivAssign added in v0.6.0

func (self *F32) DivAssign(rhs F32)

func (F32) Eq added in v0.6.0

func (self F32) Eq(rhs F32) Bool

func (F32) Exp added in v0.10.0

func (self F32) Exp() F32

Returns e^(self), (the exponential function).

f := gost.F32(1.0)
g := gost.F32(2.0)

gost.AssertEq(f.Exp(), F32(2.7182817))
gost.AssertEq(g.Exp(), F32(7.389056))

func (F32) Exp2 added in v0.10.0

func (self F32) Exp2() F32

Returns 2^(self).

f := gost.F32(1.0)
g := gost.F32(2.0)

gost.AssertEq(f.Exp2(), F32(2.0))
gost.AssertEq(g.Exp2(), F32(4.0))

func (F32) Floor added in v0.10.0

func (self F32) Floor() F32

Returns the largest integer less than or equal to self.

f := gost.F32(3.7)
g := gost.F32(3.0)
h := gost.F32(-3.7)

gost.AssertEq(f.Floor(), F32(3.0))
gost.AssertEq(g.Floor(), F32(3.0))
gost.AssertEq(h.Floor(), F32(-4.0))

func (F32) Frac added in v0.10.0

func (self F32) Frac() F32

Returns the fractional part of self.

f := gost.F32(3.7)
g := gost.F32(-3.7)

gost.AssertEq(f.Frac(), F32(0.7))
gost.AssertEq(g.Frac(), F32(-0.7))

func (F32) Ln added in v0.10.0

func (self F32) Ln() F32

Returns the natural logarithm of the number.

f := gost.F32(2.7182817)
g := gost.F32(7.389056)

gost.AssertEq(f.Ln(), F32(1.0))
gost.AssertEq(g.Ln(), F32(2.0))

func (F32) Log added in v0.10.0

func (self F32) Log(base F32) F32

Returns the logarithm of the number with respect to an arbitrary base. The result might not be correctly rounded owing to implementation details; self.log2() can produce more accurate results for base 2, and self.log10() can produce more accurate results for base 10.

f := gost.F32(2.0)
g := gost.F32(4.0)

gost.AssertEq(f.Log(2.0), F32(1.0))
gost.AssertEq(g.Log(2.0), F32(2.0))

func (F32) Log10 added in v0.10.0

func (self F32) Log10() F32

Returns the base 10 logarithm of the number.

f := gost.F32(10.0)
g := gost.F32(100.0)

gost.AssertEq(f.Log10(), F32(1.0))
gost.AssertEq(g.Log10(), F32(2.0))

func (F32) Log2 added in v0.10.0

func (self F32) Log2() F32

Returns the base 2 logarithm of the number.

f := gost.F32(2.0)
g := gost.F32(4.0)

gost.AssertEq(f.Log2(), F32(1.0))
gost.AssertEq(g.Log2(), F32(2.0))

func (F32) Mul added in v0.6.0

func (self F32) Mul(rhs F32) F32

func (*F32) MulAssign added in v0.6.0

func (self *F32) MulAssign(rhs F32)

func (F32) Powf added in v0.10.0

func (self F32) Powf(n F32) F32

Raises a number to a floating point power.

f := gost.F32(3.0)
g := gost.F32(3.0)

gost.AssertEq(f.Powf(2.0), F32(9.0))
gost.AssertEq(g.Powf(3.0), F32(27.0))

func (F32) Powi added in v0.10.0

func (self F32) Powi(n int) F32

Raises a number to an integer power. Using this function is generally faster than using powf. It might have a different sequence of rounding operations than powf, so the results are not guaranteed to agree.

f := gost.F32(3.0)
g := gost.F32(3.0)

gost.AssertEq(f.Powi(2), F32(9.0))
gost.AssertEq(g.Powi(3), F32(27.0))

func (F32) Round added in v0.10.0

func (self F32) Round() F32

Returns the nearest integer to self. If a value is half-way between two integers, round away from 0.0.

f := gost.F32(3.3)
g := gost.F32(-3.3)
h := gost.F32(-3.7)
i := gost.F32(3.5)
j := gost.F32(4.5)

gost.AssertEq(f.Round(), F32(3.0))
gost.AssertEq(g.Round(), F32(-3.0))
gost.AssertEq(h.Round(), F32(-4.0))
gost.AssertEq(i.Round(), F32(4.0))
gost.AssertEq(j.Round(), F32(5.0))

func (F32) Sqrt added in v0.10.0

func (self F32) Sqrt() F32

Returns the square root of a number. Returns NaN if self is a negative number other than -0.0.

f := gost.F32(9.0)
g := gost.F32(16.0)

gost.AssertEq(f.Sqrt(), F32(3.0))
gost.AssertEq(g.Sqrt(), F32(4.0))

func (F32) Sub added in v0.6.0

func (self F32) Sub(rhs F32) F32

func (*F32) SubAssign added in v0.6.0

func (self *F32) SubAssign(rhs F32)

func (F32) ToString added in v0.6.0

func (self F32) ToString() String

func (F32) Trunc added in v0.10.0

func (self F32) Trunc() F32

Returns the integer part of self. This means that non-integer numbers are always truncated towards zero.

f := gost.F32(3.7)
g := gost.F32(-3.7)

gost.AssertEq(f.Trunc(), F32(3.0))
gost.AssertEq(g.Trunc(), F32(-3.0))

type F64 added in v0.6.0

type F64 float64

func (F64) Abs added in v0.10.0

func (self F64) Abs() F64

Computes the absolute value of self.

f := gost.F64(-3.0)
g := gost.F64(3.0)

gost.AssertEq(f.Abs(), F64(3.0))
gost.AssertEq(g.Abs(), F64(3.0))

func (F64) Add added in v0.6.0

func (self F64) Add(rhs F64) F64

func (*F64) AddAssign added in v0.6.0

func (self *F64) AddAssign(rhs F64)

func (F64) AsRef added in v0.7.3

func (self F64) AsRef() *F64

func (F64) Ceil added in v0.10.0

func (self F64) Ceil() F64

Returns the smallest integer greater than or equal to self.

f := gost.F64(3.01)
g := gost.F64(4.0)

gost.AssertEq(f.Ceil(), F64(4.0))
gost.AssertEq(g.Ceil(), F64(4.0))

func (F64) Clone added in v0.6.0

func (self F64) Clone() F64

func (F64) Cmp added in v0.6.0

func (self F64) Cmp(rhs F64) Ordering

func (F64) Debug added in v0.6.0

func (self F64) Debug() String

func (F64) Display added in v0.6.0

func (self F64) Display() String

func (F64) Div added in v0.6.0

func (self F64) Div(rhs F64) F64

func (*F64) DivAssign added in v0.6.0

func (self *F64) DivAssign(rhs F64)

func (F64) Eq added in v0.6.0

func (self F64) Eq(rhs F64) Bool

func (F64) Exp added in v0.10.0

func (self F64) Exp() F64

Returns e^(self), (the exponential function).

f := gost.F64(1.0)
g := gost.F64(2.0)

gost.AssertEq(f.Exp(), F64(2.718281828459045))
gost.AssertEq(g.Exp(), F64(7.38905609893065))

func (F64) Exp2 added in v0.10.0

func (self F64) Exp2() F64

Returns 2^(self).

f := gost.F64(1.0)
g := gost.F64(2.0)

gost.AssertEq(f.Exp2(), F64(2.0))
gost.AssertEq(g.Exp2(), F64(4.0))

func (F64) Floor added in v0.10.0

func (self F64) Floor() F64

Returns the largest integer less than or equal to self.

f := gost.F64(3.7)
g := gost.F64(3.0)
h := gost.F64(-3.7)

gost.AssertEq(f.Floor(), F64(3.0))
gost.AssertEq(g.Floor(), F64(3.0))
gost.AssertEq(h.Floor(), F64(-4.0))

func (F64) Frac added in v0.10.0

func (self F64) Frac() F64

Returns the fractional part of self.

f := gost.F64(3.7)
g := gost.F64(-3.7)

gost.AssertEq(f.Frac(), F64(0.7))
gost.AssertEq(g.Frac(), F64(-0.7))

func (F64) Ln added in v0.10.0

func (self F64) Ln() F64

Returns the natural logarithm of the number.

f := gost.F64(2.718281828459045)
g := gost.F64(7.38905609893065)

gost.AssertEq(f.Ln(), F64(1.0))
gost.AssertEq(g.Ln(), F64(2.0))

func (F64) Log added in v0.10.0

func (self F64) Log(base F64) F64

Returns the logarithm of the number with respect to an arbitrary base. The result might not be correctly rounded owing to implementation details; self.log2() can produce more accurate results for base 2, and self.log10() can produce more accurate results for base 10.

f := gost.F64(2.0)
g := gost.F64(4.0)

gost.AssertEq(f.Log(2.0), F64(1.0))
gost.AssertEq(g.Log(2.0), F64(2.0))

func (F64) Log10 added in v0.10.0

func (self F64) Log10() F64

Returns the base 10 logarithm of the number.

f := gost.F64(10.0)
g := gost.F64(100.0)

gost.AssertEq(f.Log10(), F64(1.0))
gost.AssertEq(g.Log10(), F64(2.0))

func (F64) Log2 added in v0.10.0

func (self F64) Log2() F64

Returns the base 2 logarithm of the number.

f := gost.F64(2.0)
g := gost.F64(4.0)

gost.AssertEq(f.Log2(), F64(1.0))
gost.AssertEq(g.Log2(), F64(2.0))

func (F64) Mul added in v0.6.0

func (self F64) Mul(rhs F64) F64

func (*F64) MulAssign added in v0.6.0

func (self *F64) MulAssign(rhs F64)

func (F64) Powf added in v0.10.0

func (self F64) Powf(n F64) F64

Raises a number to a floating point power.

f := gost.F64(3.0)
g := gost.F64(3.0)

gost.AssertEq(f.Powf(2.0), F64(9.0))
gost.AssertEq(g.Powf(3.0), F64(27.0))

func (F64) Powi added in v0.10.0

func (self F64) Powi(n int) F64

Raises a number to an integer power. Using this function is generally faster than using powf. It might have a different sequence of rounding operations than powf, so the results are not guaranteed to agree.

f := gost.F64(3.0)
g := gost.F64(3.0)

gost.AssertEq(f.Powi(2), F64(9.0))
gost.AssertEq(g.Powi(3), F64(27.0))

func (F64) Round added in v0.10.0

func (self F64) Round() F64

Returns the nearest integer to self. If a value is half-way between two integers, round away from 0.0.

f := gost.F64(3.3)
g := gost.F64(-3.3)
h := gost.F64(-3.7)
i := gost.F64(3.5)
j := gost.F64(4.5)

gost.AssertEq(f.Round(), F64(3.0))
gost.AssertEq(g.Round(), F64(-3.0))
gost.AssertEq(h.Round(), F64(-4.0))
gost.AssertEq(i.Round(), F64(4.0))
gost.AssertEq(j.Round(), F64(5.0))

func (F64) Sqrt added in v0.10.0

func (self F64) Sqrt() F64

Returns the square root of a number. Returns NaN if self is a negative number other than -0.0.

f := gost.F64(9.0)
g := gost.F64(16.0)

gost.AssertEq(f.Sqrt(), F64(3.0))
gost.AssertEq(g.Sqrt(), F64(4.0))

func (F64) Sub added in v0.6.0

func (self F64) Sub(rhs F64) F64

func (*F64) SubAssign added in v0.6.0

func (self *F64) SubAssign(rhs F64)

func (F64) ToString added in v0.6.0

func (self F64) ToString() String

func (F64) Trunc added in v0.10.0

func (self F64) Trunc() F64

Returns the integer part of self. This means that non-integer numbers are always truncated towards zero.

f := gost.F64(3.7)
g := gost.F64(-3.7)

gost.AssertEq(f.Trunc(), F64(3.0))
gost.AssertEq(g.Trunc(), F64(-3.0))

type FileType

type FileType struct {
	// contains filtered or unexported fields
}

func (FileType) IsDir

func (self FileType) IsDir() bool

func (FileType) IsFile

func (self FileType) IsFile() bool
func (self FileType) IsSymlink() bool

type Future added in v0.9.0

type Future[T any] interface {
	Await() T
}

A future represents an asynchronous computation obtained by use of async.

type HashMap

type HashMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

A hash map

func HashMapNew

func HashMapNew[K comparable, V any]() HashMap[K, V]

Creates an empty HashMap.

func HashMapWithCapacity

func HashMapWithCapacity[K comparable, V any](capacity USize) HashMap[K, V]

Creates an empty HashMap with at least the specified capacity.

func (HashMap[K, V]) AsMap

func (self HashMap[K, V]) AsMap() map[K]V

As Raw Map

func (HashMap[K, V]) AsRef added in v0.7.3

func (self HashMap[K, V]) AsRef() *HashMap[K, V]

impl AsRef for HashMap

func (*HashMap[K, V]) Clear

func (self *HashMap[K, V]) Clear()

Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.

map := gost.HashMapNew[Int, Int]()
map.Insert(gost.I32(1), gost.I32(2))
map.Clear()
gost.Assert(map.IsEmpty())

func (HashMap[K, V]) Clone added in v0.7.3

func (self HashMap[K, V]) Clone() HashMap[K, V]

impl Clone for HashMap

func (HashMap[K, V]) ContainsKey

func (self HashMap[K, V]) ContainsKey(key K) Bool

Returns true if the map contains a value for the specified key.

map := gost.HashMapNew[Int, Int]()
map.Insert(gost.I32(1), gost.I32(2))
gost.Assert(map.ContainsKey(gost.I32(1)))
gost.Assert(!map.ContainsKey(gost.I32(3)))

func (HashMap[K, V]) Debug

func (self HashMap[K, V]) Debug() String

impl Debug for HashMap

func (HashMap[K, V]) Display

func (self HashMap[K, V]) Display() String

impl Display for HashMap

func (HashMap[K, V]) Eq added in v0.7.3

func (self HashMap[K, V]) Eq(rhs HashMap[K, V]) Bool

impl Eq for HashMap

func (HashMap[K, V]) Get

func (self HashMap[K, V]) Get(key K) Option[V]

Returns value corresponding to the key.

map := gost.HashMapNew[Int, Int]()
map.Insert(gost.I32(1), gost.I32(2))
gost.AssertEq(map.Get(gost.I32(1)), gost.Some[gost.I32](gost.I32(2)))

func (*HashMap[K, V]) Insert

func (self *HashMap[K, V]) Insert(key K, value V) Option[V]

Inserts a key-value pair into the map. If the map did not have this key present, None is returned.

map := gost.HashMapNew[Int, Int]()
gost.Assert(map.Insert(gost.I32(1), gost.I32(2)).IsNone())
gost.AssertEq(map.Insert(gost.I32(1), gost.I32(3)), gost.Some[gost.I32](gost.I32(2)))

func (HashMap[K, V]) IntoIter

func (self HashMap[K, V]) IntoIter() Iterator[Pair[K, V]]

into_iter

func (HashMap[K, V]) IsEmpty

func (self HashMap[K, V]) IsEmpty() Bool

Returns true if the map contains no elements.

map := gost.HashMapNew[Int, Int]()
gost.Assert(map.IsEmpty())

map.Insert(gost.I32(1), gost.I32(2))
gost.Assert(!map.IsEmpty())

func (HashMap[K, V]) Keys

func (self HashMap[K, V]) Keys() Iterator[K]

An iterator visiting all keys in arbitrary order. The iterator element type is K.

map := gost.HashMapNew[Int, Int]()
map.Insert(gost.I32(1), gost.I32(2))
map.Insert(gost.I32(3), gost.I32(4))
map.Insert(gost.I32(5), gost.I32(6))
keys := map.Keys()
gost.AssertEq(keys.Next(), gost.Some[gost.I32](gost.I32(1)))

func (HashMap[K, V]) Len

func (self HashMap[K, V]) Len() USize

Returns the number of elements in the map.

map := gost.HashMapNew[Int, Int]()
gost.AssertEq(map.Len(), gost.USize(0))

map.Insert(gost.I32(1), gost.I32(2))
gost.AssertEq(map.Len(), gost.USize(1))

func (*HashMap[K, V]) Remove

func (self *HashMap[K, V]) Remove(key K) Option[V]

Removes a key from the map, returning the value at the key if the key was previously in the map.

map := gost.HashMapNew[Int, Int]()
gost.Assert(map.Insert(gost.I32(1), gost.I32(2)).IsNone())
gost.AssertEq(map.Insert(gost.I32(1), gost.I32(3)), gost.Some[gost.I32](gost.I32(2)))

func (HashMap[K, V]) Values

func (self HashMap[K, V]) Values() Iterator[V]

An iterator visiting all values in arbitrary order. The iterator element type is V.

type HashMapIter

type HashMapIter[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Returns true if the map contains a value for the specified value.

func (HashMapIter[K, V]) CollectToLinkedList added in v0.6.0

func (self HashMapIter[K, V]) CollectToLinkedList() LinkedList[Pair[K, V]]

Collect to LinkedList

func (HashMapIter[K, V]) CollectToVec

func (self HashMapIter[K, V]) CollectToVec() Vec[Pair[K, V]]

Collect to Vec

func (HashMapIter[K, V]) Filter

func (self HashMapIter[K, V]) Filter(f func(Pair[K, V]) Bool) Iterator[Pair[K, V]]

filter

func (HashMapIter[K, V]) Fold

func (self HashMapIter[K, V]) Fold(init Pair[K, V], f func(Pair[K, V], Pair[K, V]) Pair[K, V]) Pair[K, V]

fold

func (HashMapIter[K, V]) Map

func (self HashMapIter[K, V]) Map(f func(Pair[K, V]) Pair[K, V]) Iterator[Pair[K, V]]

map

func (*HashMapIter[K, V]) Next

func (self *HashMapIter[K, V]) Next() Option[Pair[K, V]]

next

func (HashMapIter[K, V]) Rev

func (self HashMapIter[K, V]) Rev() Iterator[Pair[K, V]]

rev

type HashMapKeys

type HashMapKeys[K any] struct {
	// contains filtered or unexported fields
}

An iterator visiting all keys in arbitrary order. The iterator element type is K.

func (HashMapKeys[K]) CollectToLinkedList added in v0.6.0

func (self HashMapKeys[K]) CollectToLinkedList() LinkedList[K]

Collect to LinkedList

func (HashMapKeys[K]) CollectToVec

func (self HashMapKeys[K]) CollectToVec() Vec[K]

Collect to Vec

func (HashMapKeys[K]) Filter

func (self HashMapKeys[K]) Filter(f func(K) Bool) Iterator[K]

filter

func (HashMapKeys[K]) Fold

func (self HashMapKeys[K]) Fold(init K, f func(K, K) K) K

fold

func (HashMapKeys[K]) Map

func (self HashMapKeys[K]) Map(f func(K) K) Iterator[K]

map

func (*HashMapKeys[K]) Next

func (self *HashMapKeys[K]) Next() Option[K]

next

func (HashMapKeys[K]) Rev

func (self HashMapKeys[K]) Rev() Iterator[K]

rev

type HashMapValues

type HashMapValues[V any] struct {
	// contains filtered or unexported fields
}

An iterator visiting all values in arbitrary order. The iterator element type is V.

func (HashMapValues[V]) CollectToLinkedList added in v0.6.0

func (self HashMapValues[V]) CollectToLinkedList() LinkedList[V]

Collect to LinkedList

func (HashMapValues[V]) CollectToVec

func (self HashMapValues[V]) CollectToVec() Vec[V]

Collect to Vec

func (HashMapValues[V]) Filter

func (self HashMapValues[V]) Filter(f func(V) Bool) Iterator[V]

filter

func (HashMapValues[V]) Fold

func (self HashMapValues[V]) Fold(init V, f func(V, V) V) V

fold

func (HashMapValues[V]) Map

func (self HashMapValues[V]) Map(f func(V) V) Iterator[V]

map

func (*HashMapValues[V]) Next

func (self *HashMapValues[V]) Next() Option[V]

next

func (HashMapValues[V]) Rev

func (self HashMapValues[V]) Rev() Iterator[V]

rev

type HashSet added in v0.7.0

type HashSet[K comparable] struct {
	// contains filtered or unexported fields
}

A unordered set based on a HashMap.

func HashSetFromSlice added in v0.7.0

func HashSetFromSlice[K comparable](slice []K) HashSet[K]

From Slice

func HashSetNew added in v0.7.0

func HashSetNew[K comparable]() HashSet[K]

Creates an empty HashSet.

func HashSetWithCapacity added in v0.7.0

func HashSetWithCapacity[K comparable](capacity USize) HashSet[K]

Creates an empty HashSet with at least the specified capacity.

func (HashSet[K]) AsRef added in v0.7.3

func (self HashSet[K]) AsRef() *HashSet[K]

impl AsRef for HashSet

func (HashSet[K]) AsSlice added in v0.7.0

func (self HashSet[K]) AsSlice() []K

As Slice

func (*HashSet[K]) Clear added in v0.7.0

func (self *HashSet[K]) Clear()

Clears the set, removing all values.

set := gost.HashSetNew[gost.I32]()
set.Insert(gost.I32(1))
set.Insert(gost.I32(2))
set.Clear()
gost.Assert(set.IsEmpty())

func (HashSet[K]) Clone added in v0.7.3

func (self HashSet[K]) Clone() HashSet[K]

impl Clone for HashSet

func (HashSet[K]) Contains added in v0.7.0

func (self HashSet[K]) Contains(value K) Bool

Returns true if the set contains a value. The value may be any borrowed form of the set’s value type, but Hash and Eq on the borrowed form must match those for the value type.

set := gost.HashSetNew[gost.I32]()
set.Insert(gost.I32(1))
set.Insert(gost.I32(2))
gost.Assert(set.Contains(gost.I32(1)))
gost.Assert(!set.Contains(gost.I32(3)))

func (HashSet[K]) Debug added in v0.7.0

func (self HashSet[K]) Debug() String

impl Debug for HashSet

func (HashSet[K]) Display added in v0.7.0

func (self HashSet[K]) Display() String

impl Display for HashSet

func (HashSet[K]) Eq added in v0.7.3

func (self HashSet[K]) Eq(rhs HashSet[K]) Bool

impl Eq for HashSet

func (HashSet[K]) Get added in v0.7.0

func (self HashSet[K]) Get(value K) Option[K]

Returns a reference to the value in the set, if any, that is equal to the given value. The value may be any borrowed form of the set’s value type, but Hash and Eq on the borrowed form must match those for the value type.

set := gost.HashSetNew[gost.I32]()
set.Insert(gost.I32(1))
set.Insert(gost.I32(2))
gost.Assert(set.Get(gost.I32(1)).IsSome())
gost.Assert(set.Get(gost.I32(3)).IsNone())

func (*HashSet[K]) Insert added in v0.7.0

func (self *HashSet[K]) Insert(value K) Bool

Adds a value to the set. Returns whether the value was newly inserted. That is: If the set did not previously contain this value, true is returned. If the set already contained this value, false is returned, and the set is not modified: original value is not replaced, and the value passed as argument is dropped.

set := gost.HashSetNew[gost.I32]()
gost.Assert(set.Insert(gost.I32(1)))
gost.Assert(!set.Insert(gost.I32(1)))

func (HashSet[K]) Intersection added in v0.10.0

func (self HashSet[K]) Intersection(other HashSet[K]) HashSet[K]

Visits the elements representing the intersection, i.e., the elements that are both in self and other, in ascending order.

set1 := gost.HashSetNew[I32]()
set1.Insert(gost.I32(1))
set1.Insert(gost.I32(2))
set1.Insert(gost.I32(5))

set2 := gost.HashSetNew[I32]()
set2.Insert(gost.I32(1))
set2.Insert(gost.I32(2))
set2.Insert(gost.I32(3))

intersection := set1.Intersection(set2)
gost.Assert(intersection.Len() == gost.USize(2))
gost.Assert(intersection.Contains(gost.I32(1)))
gost.Assert(intersection.Contains(gost.I32(2)))

func (HashSet[K]) IntoIter added in v0.7.0

func (self HashSet[K]) IntoIter() Iterator[K]

into_iter

func (HashSet[K]) IsDisjoint added in v0.10.0

func (self HashSet[K]) IsDisjoint(other HashSet[K]) Bool

Returns true if self has no elements in common with other. This is equivalent to checking for an empty intersection.

set1 := gost.HashSetNew[I32]()
set1.Insert(gost.I32(1))
set1.Insert(gost.I32(2))

set2 := gost.HashSetNew[I32]()
set2.Insert(gost.I32(3))
set2.Insert(gost.I32(4))

gost.Assert(set1.IsDisjoint(set2))

func (HashSet[K]) IsEmpty added in v0.7.0

func (self HashSet[K]) IsEmpty() Bool

Returns true if the set contains no elements.

set := gost.HashSetNew[gost.I32]()
gost.Assert(set.IsEmpty())

set.Insert(gost.I32(1))
gost.Assert(!set.IsEmpty())

func (HashSet[K]) IsSubset added in v0.10.0

func (self HashSet[K]) IsSubset(other HashSet[K]) Bool

Returns true if the set is a subset of another, i.e., other contains at least all the elements in self.

set1 := gost.HashSetNew[I32]()
set1.Insert(gost.I32(1))
set1.Insert(gost.I32(2))

set2 := gost.HashSetNew[I32]()
set2.Insert(gost.I32(1))
set2.Insert(gost.I32(2))
set2.Insert(gost.I32(3))

gost.Assert(set1.IsSubset(set2))
gost.Assert(!set2.IsSubset(set1))

func (HashSet[K]) IsSuperset added in v0.10.0

func (self HashSet[K]) IsSuperset(other HashSet[K]) Bool

Returns true if the set is a superset of another, i.e., self contains at least all the elements in other.

set1 := gost.HashSetNew[I32]()
set1.Insert(gost.I32(1))
set1.Insert(gost.I32(2))

set2 := gost.HashSetNew[I32]()
set2.Insert(gost.I32(1))
set2.Insert(gost.I32(2))
set2.Insert(gost.I32(3))

gost.Assert(!set1.IsSuperset(set2))
gost.Assert(set2.IsSuperset(set1))

func (HashSet[K]) Len added in v0.7.0

func (self HashSet[K]) Len() USize

Returns the number of elements in the set.

set := gost.HashSetNew[gost.I32]()
set.Insert(gost.I32(1))
set.Insert(gost.I32(2))
gost.AssertEq(set.Len(), gost.USize(2))

func (*HashSet[K]) Remove added in v0.7.0

func (self *HashSet[K]) Remove(value K) Bool

Removes a value from the set. Returns whether the value was present in the set. The value may be any borrowed form of the set’s value type, but Hash and Eq on the borrowed form must match those for the value type.

set := gost.HashSetNew[gost.I32]()
set.Insert(gost.I32(1))
set.Insert(gost.I32(2))
gost.Assert(set.Remove(gost.I32(1)))
gost.Assert(!set.Remove(gost.I32(3)))

func (HashSet[K]) SymmetricDifference added in v0.10.0

func (self HashSet[K]) SymmetricDifference(other HashSet[K]) HashSet[K]

Visits the elements representing the symmetric difference, i.e., the elements that are in self or in other but not in both, in ascending order.

set1 := gost.HashSetNew[I32]()
set1.Insert(gost.I32(1))
set1.Insert(gost.I32(2))
set1.Insert(gost.I32(5))

set2 := gost.HashSetNew[I32]()
set2.Insert(gost.I32(1))
set2.Insert(gost.I32(2))
set2.Insert(gost.I32(3))

symmetricDifference := set1.SymmetricDifference(set2)
gost.Assert(symmetricDifference.Len() == gost.USize(2))
gost.Assert(symmetricDifference.Contains(gost.I32(3)))
gost.Assert(symmetricDifference.Contains(gost.I32(5)))

func (HashSet[K]) Union added in v0.10.0

func (self HashSet[K]) Union(other HashSet[K]) HashSet[K]

Visits the elements representing the union, i.e., all the elements in self or other, without duplicates, in ascending order.

set1 := gost.HashSetNew[I32]()
set1.Insert(gost.I32(1))
set1.Insert(gost.I32(2))
set1.Insert(gost.I32(3))

set2 := gost.HashSetNew[I32]()
set2.Insert(gost.I32(3))
set2.Insert(gost.I32(4))

union := set1.Union(set2)
gost.Assert(union.Len() == gost.USize(4))
gost.Assert(union.Contains(gost.I32(1)))
gost.Assert(union.Contains(gost.I32(2)))
gost.Assert(union.Contains(gost.I32(3)))
gost.Assert(union.Contains(gost.I32(4)))

type HashSetIter added in v0.7.0

type HashSetIter[K comparable] struct {
	// contains filtered or unexported fields
}

Returns true if the set contains an element equal to the value.

func (HashSetIter[K]) CollectToLinkedList added in v0.7.0

func (self HashSetIter[K]) CollectToLinkedList() LinkedList[K]

Collect to LinkedList

func (HashSetIter[K]) CollectToVec added in v0.7.0

func (self HashSetIter[K]) CollectToVec() Vec[K]

Collect to Vec

func (HashSetIter[K]) Filter added in v0.7.0

func (self HashSetIter[K]) Filter(f func(K) Bool) Iterator[K]

filter

func (HashSetIter[K]) Fold added in v0.7.0

func (self HashSetIter[K]) Fold(init K, f func(K, K) K) K

fold

func (HashSetIter[K]) Map added in v0.7.0

func (self HashSetIter[K]) Map(f func(K) K) Iterator[K]

map

func (*HashSetIter[K]) Next added in v0.7.0

func (self *HashSetIter[K]) Next() Option[K]

next

func (HashSetIter[K]) Rev added in v0.7.0

func (self HashSetIter[K]) Rev() Iterator[K]

rev

type I128 added in v0.11.0

type I128 struct {
	// contains filtered or unexported fields
}

func I128_FromI64 added in v0.11.0

func I128_FromI64(low I64) I128

func I128_FromU64 added in v0.11.0

func I128_FromU64(low U64) I128

func (I128) Abs added in v0.11.0

func (self I128) Abs() I128

Absolute value. Returns the absolute value of self.

func (I128) Add added in v0.11.0

func (self I128) Add(rhs I128) I128

func (*I128) AddAssign added in v0.11.0

func (self *I128) AddAssign(rhs I128)

func (I128) Cmp added in v0.11.0

func (self I128) Cmp(rhs I128) Ordering

func (I128) Debug added in v0.11.0

func (self I128) Debug() String

func (I128) Display added in v0.11.0

func (self I128) Display() String

func (I128) Div added in v0.11.0

func (lhs I128) Div(rhs I128) I128

func (*I128) DivAssign added in v0.11.0

func (self *I128) DivAssign(rhs I128)

func (I128) Eq added in v0.11.0

func (self I128) Eq(rhs I128) Bool

func (I128) IsNegative added in v0.11.0

func (self I128) IsNegative() Bool

Returns true if self is negative and false if the number is zero or positive.

func (I128) IsPositive added in v0.11.0

func (self I128) IsPositive() Bool

Returns true if self is positive and false if the number is zero or negative.

func (I128) Mul added in v0.11.0

func (self I128) Mul(rhs I128) I128

func (*I128) MulAssign added in v0.11.0

func (self *I128) MulAssign(rhs I128)

func (I128) Neg added in v0.11.0

func (self I128) Neg() I128

func (I128) Rem added in v0.11.0

func (lhs I128) Rem(rhs I128) I128

func (*I128) RemAssign added in v0.11.0

func (self *I128) RemAssign(rhs I128)

func (I128) Shl added in v0.11.0

func (lhs I128) Shl(rhs I128) I128

func (I128) Shr added in v0.11.0

func (lhs I128) Shr(rhs I128) I128

func (I128) Sub added in v0.11.0

func (self I128) Sub(rhs I128) I128

func (*I128) SubAssign added in v0.11.0

func (self *I128) SubAssign(rhs I128)

func (I128) ToString added in v0.11.0

func (self I128) ToString() String

type I16 added in v0.6.0

type I16 int16

func (I16) Abs added in v0.10.0

func (self I16) Abs() I16

Absolute value. Returns the absolute value of self.

func (I16) AbsDiff added in v0.10.0

func (self I16) AbsDiff(other I16) U16

Computes the absolute difference between self and other. This function always returns the correct answer without overflow or panics by returning an unsigned integer.

func (I16) Add added in v0.6.0

func (self I16) Add(rhs I16) I16

func (*I16) AddAssign added in v0.6.0

func (self *I16) AddAssign(rhs I16)

func (I16) AsRef added in v0.7.3

func (self I16) AsRef() *I16

func (I16) CheckedAdd added in v0.9.0

func (self I16) CheckedAdd(rhs I16) Option[I16]

func (I16) CheckedDiv added in v0.9.0

func (self I16) CheckedDiv(rhs I16) Option[I16]

func (I16) CheckedMul added in v0.9.0

func (self I16) CheckedMul(rhs I16) Option[I16]

func (I16) CheckedRem added in v0.9.0

func (self I16) CheckedRem(rhs I16) Option[I16]

func (I16) CheckedSub added in v0.9.0

func (self I16) CheckedSub(rhs I16) Option[I16]

func (I16) Clone added in v0.6.0

func (self I16) Clone() I16

func (I16) Cmp added in v0.6.0

func (self I16) Cmp(rhs I16) Ordering

func (I16) Debug added in v0.6.0

func (self I16) Debug() String

func (I16) Display added in v0.6.0

func (self I16) Display() String

func (I16) Div added in v0.6.0

func (self I16) Div(rhs I16) I16

func (*I16) DivAssign added in v0.6.0

func (self *I16) DivAssign(rhs I16)

func (I16) Eq added in v0.6.0

func (self I16) Eq(rhs I16) Bool

func (I16) IsNegative added in v0.10.0

func (self I16) IsNegative() Bool

Returns true if self is negative and false if the number is zero or positive.

func (I16) IsPositive added in v0.10.0

func (self I16) IsPositive() Bool

Returns true if self is positive and false if the number is zero or negative.

func (I16) Mul added in v0.6.0

func (self I16) Mul(rhs I16) I16

func (*I16) MulAssign added in v0.6.0

func (self *I16) MulAssign(rhs I16)

func (I16) Neg added in v0.11.0

func (self I16) Neg(rhs I16) I16

func (I16) Pow added in v0.10.0

func (self I16) Pow(exp U32) I16

Raises self to the power of exp, using exponentiation by squaring.

func (I16) Rem added in v0.9.0

func (self I16) Rem(rhs I16) I16

func (*I16) RemAssign added in v0.9.0

func (self *I16) RemAssign(rhs I16)

func (I16) SaturatingAdd added in v0.10.0

func (self I16) SaturatingAdd(rhs I16) I16

func (I16) SaturatingDiv added in v0.10.0

func (self I16) SaturatingDiv(rhs I16) I16

func (I16) SaturatingMul added in v0.10.0

func (self I16) SaturatingMul(rhs I16) I16

func (I16) SaturatingSub added in v0.9.0

func (self I16) SaturatingSub(rhs I16) I16

func (I16) Shl added in v0.11.0

func (lhs I16) Shl(rhs I16) I16

func (I16) Shr added in v0.11.0

func (lhs I16) Shr(rhs I16) I16

func (I16) Sub added in v0.6.0

func (self I16) Sub(rhs I16) I16

func (*I16) SubAssign added in v0.6.0

func (self *I16) SubAssign(rhs I16)

func (I16) ToString added in v0.6.0

func (self I16) ToString() String

func (I16) WrappingAdd added in v0.8.0

func (self I16) WrappingAdd(rhs I16) I16

func (I16) WrappingDiv added in v0.9.0

func (self I16) WrappingDiv(rhs I16) I16

func (I16) WrappingMul added in v0.9.0

func (self I16) WrappingMul(rhs I16) I16

func (I16) WrappingSub added in v0.8.0

func (self I16) WrappingSub(rhs I16) I16

type I32 added in v0.6.0

type I32 int32

func (I32) Abs added in v0.10.0

func (self I32) Abs() I32

Absolute value. Returns the absolute value of self.

func (I32) AbsDiff added in v0.10.0

func (self I32) AbsDiff(other I32) U32

Computes the absolute difference between self and other. This function always returns the correct answer without overflow or panics by returning an unsigned integer.

func (I32) Add added in v0.6.0

func (self I32) Add(rhs I32) I32

func (*I32) AddAssign added in v0.6.0

func (self *I32) AddAssign(rhs I32)

func (I32) AsRef added in v0.7.3

func (self I32) AsRef() *I32

func (I32) CheckedAdd added in v0.9.0

func (self I32) CheckedAdd(rhs I32) Option[I32]

func (I32) CheckedDiv added in v0.9.0

func (self I32) CheckedDiv(rhs I32) Option[I32]

func (I32) CheckedMul added in v0.9.0

func (self I32) CheckedMul(rhs I32) Option[I32]

func (I32) CheckedRem added in v0.9.0

func (self I32) CheckedRem(rhs I32) Option[I32]

func (I32) CheckedSub added in v0.9.0

func (self I32) CheckedSub(rhs I32) Option[I32]

func (I32) Clone added in v0.6.0

func (self I32) Clone() I32

func (I32) Cmp added in v0.6.0

func (self I32) Cmp(rhs I32) Ordering

func (I32) Debug added in v0.6.0

func (self I32) Debug() String

func (I32) Display added in v0.6.0

func (self I32) Display() String

func (I32) Div added in v0.6.0

func (self I32) Div(rhs I32) I32

func (*I32) DivAssign added in v0.6.0

func (self *I32) DivAssign(rhs I32)

func (I32) Eq added in v0.6.0

func (self I32) Eq(rhs I32) Bool

func (I32) IsNegative added in v0.10.0

func (self I32) IsNegative() Bool

Returns true if self is negative and false if the number is zero or positive.

func (I32) IsPositive added in v0.10.0

func (self I32) IsPositive() Bool

Returns true if self is positive and false if the number is zero or negative.

func (I32) Mul added in v0.6.0

func (self I32) Mul(rhs I32) I32

func (*I32) MulAssign added in v0.6.0

func (self *I32) MulAssign(rhs I32)

func (I32) Neg added in v0.11.0

func (self I32) Neg(rhs I32) I32

func (I32) Pow added in v0.10.0

func (self I32) Pow(exp U32) I32

Raises self to the power of exp, using exponentiation by squaring.

func (I32) Rem added in v0.9.0

func (self I32) Rem(rhs I32) I32

func (*I32) RemAssign added in v0.9.0

func (self *I32) RemAssign(rhs I32)

func (I32) SaturatingAdd added in v0.10.0

func (self I32) SaturatingAdd(rhs I32) I32

func (I32) SaturatingDiv added in v0.10.0

func (self I32) SaturatingDiv(rhs I32) I32

func (I32) SaturatingMul added in v0.10.0

func (self I32) SaturatingMul(rhs I32) I32

func (I32) SaturatingSub added in v0.9.0

func (self I32) SaturatingSub(rhs I32) I32

func (I32) Shl added in v0.11.0

func (lhs I32) Shl(rhs I32) I32

func (I32) Shr added in v0.11.0

func (lhs I32) Shr(rhs I32) I32

func (I32) Sub added in v0.6.0

func (self I32) Sub(rhs I32) I32

func (*I32) SubAssign added in v0.6.0

func (self *I32) SubAssign(rhs I32)

func (I32) ToString added in v0.6.0

func (self I32) ToString() String

func (I32) WrappingAdd added in v0.8.0

func (self I32) WrappingAdd(rhs I32) I32

func (I32) WrappingDiv added in v0.9.0

func (self I32) WrappingDiv(rhs I32) I32

func (I32) WrappingMul added in v0.9.0

func (self I32) WrappingMul(rhs I32) I32

func (I32) WrappingSub added in v0.8.0

func (self I32) WrappingSub(rhs I32) I32

type I64 added in v0.6.0

type I64 int64

func (I64) Abs added in v0.10.0

func (self I64) Abs() I64

Absolute value. Returns the absolute value of self.

func (I64) AbsDiff added in v0.10.0

func (self I64) AbsDiff(other I64) U64

Computes the absolute difference between self and other. This function always returns the correct answer without overflow or panics by returning an unsigned integer.

func (I64) Add added in v0.6.0

func (self I64) Add(rhs I64) I64

func (*I64) AddAssign added in v0.6.0

func (self *I64) AddAssign(rhs I64)

func (I64) AsRef added in v0.7.3

func (self I64) AsRef() *I64

func (I64) CheckedAdd added in v0.9.0

func (self I64) CheckedAdd(rhs I64) Option[I64]

func (I64) CheckedDiv added in v0.9.0

func (self I64) CheckedDiv(rhs I64) Option[I64]

func (I64) CheckedMul added in v0.9.0

func (self I64) CheckedMul(rhs I64) Option[I64]

func (I64) CheckedRem added in v0.9.0

func (self I64) CheckedRem(rhs I64) Option[I64]

func (I64) CheckedSub added in v0.9.0

func (self I64) CheckedSub(rhs I64) Option[I64]

func (I64) Clone added in v0.6.0

func (self I64) Clone() I64

func (I64) Cmp added in v0.6.0

func (self I64) Cmp(rhs I64) Ordering

func (I64) Debug added in v0.6.0

func (self I64) Debug() String

func (I64) Display added in v0.6.0

func (self I64) Display() String

func (I64) Div added in v0.6.0

func (self I64) Div(rhs I64) I64

func (*I64) DivAssign added in v0.6.0

func (self *I64) DivAssign(rhs I64)

func (I64) Eq added in v0.6.0

func (self I64) Eq(rhs I64) Bool

func (I64) IsNegative added in v0.10.0

func (self I64) IsNegative() Bool

Returns true if self is negative and false if the number is zero or positive.

func (I64) IsPositive added in v0.10.0

func (self I64) IsPositive() Bool

Returns true if self is positive and false if the number is zero or negative.

func (I64) Mul added in v0.6.0

func (self I64) Mul(rhs I64) I64

func (*I64) MulAssign added in v0.6.0

func (self *I64) MulAssign(rhs I64)

func (I64) Neg added in v0.11.0

func (self I64) Neg(rhs I64) I64

func (I64) Pow added in v0.10.0

func (self I64) Pow(exp U32) I64

Raises self to the power of exp, using exponentiation by squaring.

func (I64) Rem added in v0.9.0

func (self I64) Rem(rhs I64) I64

func (*I64) RemAssign added in v0.9.0

func (self *I64) RemAssign(rhs I64)

func (I64) SaturatingAdd added in v0.10.0

func (self I64) SaturatingAdd(rhs I64) I64

func (I64) SaturatingDiv added in v0.10.0

func (self I64) SaturatingDiv(rhs I64) I64

func (I64) SaturatingMul added in v0.10.0

func (self I64) SaturatingMul(rhs I64) I64

func (I64) SaturatingSub added in v0.9.0

func (self I64) SaturatingSub(rhs I64) I64

func (I64) Shl added in v0.11.0

func (lhs I64) Shl(rhs I64) I64

func (I64) Shr added in v0.11.0

func (lhs I64) Shr(rhs I64) I64

func (I64) Sub added in v0.6.0

func (self I64) Sub(rhs I64) I64

func (*I64) SubAssign added in v0.6.0

func (self *I64) SubAssign(rhs I64)

func (I64) ToString added in v0.6.0

func (self I64) ToString() String

func (I64) WrappingAdd added in v0.8.0

func (self I64) WrappingAdd(rhs I64) I64

func (I64) WrappingDiv added in v0.9.0

func (self I64) WrappingDiv(rhs I64) I64

func (I64) WrappingMul added in v0.9.0

func (self I64) WrappingMul(rhs I64) I64

func (I64) WrappingSub added in v0.8.0

func (self I64) WrappingSub(rhs I64) I64

type I8 added in v0.6.0

type I8 int8

func (I8) Abs added in v0.10.0

func (self I8) Abs() I8

Absolute value. Returns the absolute value of self.

func (I8) AbsDiff added in v0.10.0

func (self I8) AbsDiff(other I8) U8

Computes the absolute difference between self and other. This function always returns the correct answer without overflow or panics by returning an unsigned integer.

func (I8) Add added in v0.6.0

func (self I8) Add(rhs I8) I8

func (*I8) AddAssign added in v0.6.0

func (self *I8) AddAssign(rhs I8)

func (I8) AsRef added in v0.7.3

func (self I8) AsRef() *I8

func (I8) CheckedAdd added in v0.9.0

func (self I8) CheckedAdd(rhs I8) Option[I8]

func (I8) CheckedDiv added in v0.9.0

func (self I8) CheckedDiv(rhs I8) Option[I8]

func (I8) CheckedMul added in v0.9.0

func (self I8) CheckedMul(rhs I8) Option[I8]

func (I8) CheckedRem added in v0.9.0

func (self I8) CheckedRem(rhs I8) Option[I8]

func (I8) CheckedSub added in v0.9.0

func (self I8) CheckedSub(rhs I8) Option[I8]

func (I8) Clone added in v0.6.0

func (self I8) Clone() I8

func (I8) Cmp added in v0.6.0

func (self I8) Cmp(rhs I8) Ordering

func (I8) Debug added in v0.6.0

func (self I8) Debug() String

func (I8) Display added in v0.6.0

func (self I8) Display() String

func (I8) Div added in v0.6.0

func (self I8) Div(rhs I8) I8

func (*I8) DivAssign added in v0.6.0

func (self *I8) DivAssign(rhs I8)

func (I8) Eq added in v0.6.0

func (self I8) Eq(rhs I8) Bool

func (I8) IsNegative added in v0.10.0

func (self I8) IsNegative() Bool

Returns true if self is negative and false if the number is zero or positive.

func (I8) IsPositive added in v0.10.0

func (self I8) IsPositive() Bool

Returns true if self is positive and false if the number is zero or negative.

func (I8) Mul added in v0.6.0

func (self I8) Mul(rhs I8) I8

func (*I8) MulAssign added in v0.6.0

func (self *I8) MulAssign(rhs I8)

func (I8) Neg added in v0.11.0

func (self I8) Neg(rhs I8) I8

func (I8) Pow added in v0.10.0

func (self I8) Pow(exp U32) I8

Raises self to the power of exp, using exponentiation by squaring.

func (I8) Rem added in v0.9.0

func (self I8) Rem(rhs I8) I8

func (*I8) RemAssign added in v0.9.0

func (self *I8) RemAssign(rhs I8)

func (I8) SaturatingAdd added in v0.10.0

func (self I8) SaturatingAdd(rhs I8) I8

func (I8) SaturatingDiv added in v0.10.0

func (self I8) SaturatingDiv(rhs I8) I8

func (I8) SaturatingMul added in v0.10.0

func (self I8) SaturatingMul(rhs I8) I8

func (I8) SaturatingSub added in v0.9.0

func (self I8) SaturatingSub(rhs I8) I8

func (I8) Shl added in v0.11.0

func (lhs I8) Shl(rhs I8) I8

func (I8) Shr added in v0.11.0

func (lhs I8) Shr(rhs I8) I8

func (I8) Sub added in v0.6.0

func (self I8) Sub(rhs I8) I8

func (*I8) SubAssign added in v0.6.0

func (self *I8) SubAssign(rhs I8)

func (I8) ToString added in v0.6.0

func (self I8) ToString() String

func (I8) WrappingAdd added in v0.8.0

func (self I8) WrappingAdd(rhs I8) I8

func (I8) WrappingDiv added in v0.9.0

func (self I8) WrappingDiv(rhs I8) I8

func (I8) WrappingMul added in v0.9.0

func (self I8) WrappingMul(rhs I8) I8

func (I8) WrappingSub added in v0.8.0

func (self I8) WrappingSub(rhs I8) I8

type ISize added in v0.6.0

type ISize int

func (ISize) Abs added in v0.10.0

func (self ISize) Abs() ISize

Absolute value. Returns the absolute value of self.

func (ISize) AbsDiff added in v0.10.0

func (self ISize) AbsDiff(other ISize) USize

Computes the absolute difference between self and other. This function always returns the correct answer without overflow or panics by returning an unsigned integer.

func (ISize) Add added in v0.6.0

func (self ISize) Add(rhs ISize) ISize

Add implements

func (*ISize) AddAssign added in v0.6.0

func (self *ISize) AddAssign(rhs ISize)

AddAssign implements

func (ISize) AsRef added in v0.7.3

func (self ISize) AsRef() *ISize

func (ISize) CheckedAdd added in v0.9.0

func (self ISize) CheckedAdd(rhs ISize) Option[ISize]

Checked integer addition. Computes self + rhs, returning None if overflow occurred.

func (ISize) CheckedDiv added in v0.9.0

func (self ISize) CheckedDiv(rhs ISize) Option[ISize]

Checked integer division. Computes self / rhs, returning None if rhs == 0 or the operation results in overflow.

func (ISize) CheckedMul added in v0.9.0

func (self ISize) CheckedMul(rhs ISize) Option[ISize]

Checked integer multiplication. Computes self * rhs, returning None if overflow occurred.

func (ISize) CheckedRem added in v0.9.0

func (self ISize) CheckedRem(rhs ISize) Option[ISize]

Checked integer remainder. Computes self % rhs, returning None if rhs == 0 or the operation results in overflow.

func (ISize) CheckedSub added in v0.9.0

func (self ISize) CheckedSub(rhs ISize) Option[ISize]

Checked integer subtraction. Computes self - rhs, returning None if overflow occurred.

func (ISize) Clone added in v0.6.0

func (self ISize) Clone() ISize

func (ISize) Cmp added in v0.6.0

func (self ISize) Cmp(rhs ISize) Ordering

func (ISize) Debug added in v0.6.0

func (self ISize) Debug() String

func (ISize) Display added in v0.6.0

func (self ISize) Display() String

func (ISize) Div added in v0.6.0

func (self ISize) Div(rhs ISize) ISize

Div implements

func (*ISize) DivAssign added in v0.6.0

func (self *ISize) DivAssign(rhs ISize)

DivAssign implements

func (ISize) Eq added in v0.6.0

func (self ISize) Eq(rhs ISize) Bool

func (ISize) IsNegative added in v0.10.0

func (self ISize) IsNegative() Bool

Returns true if self is negative and false if the number is zero or positive.

func (ISize) IsPositive added in v0.10.0

func (self ISize) IsPositive() Bool

Returns true if self is positive and false if the number is zero or negative.

func (ISize) Mul added in v0.6.0

func (self ISize) Mul(rhs ISize) ISize

Mul implements

func (*ISize) MulAssign added in v0.6.0

func (self *ISize) MulAssign(rhs ISize)

MulAssign implements

func (ISize) Neg added in v0.11.0

func (self ISize) Neg(rhs ISize) ISize

func (ISize) Pow added in v0.10.0

func (self ISize) Pow(exp U32) ISize

Raises self to the power of exp, using exponentiation by squaring.

func (ISize) Rem added in v0.9.0

func (self ISize) Rem(rhs ISize) ISize

Rem implements

func (*ISize) RemAssign added in v0.9.0

func (self *ISize) RemAssign(rhs ISize)

RemAssign implements

func (ISize) SaturatingAdd added in v0.10.0

func (self ISize) SaturatingAdd(rhs ISize) ISize

Saturating integer addition. Computes self + rhs, saturating at the numeric bounds instead of overflowing.

func (ISize) SaturatingDiv added in v0.10.0

func (self ISize) SaturatingDiv(rhs ISize) ISize

Saturating integer division. Computes self / rhs, saturating at the numeric bounds instead of overflowing.

func (ISize) SaturatingMul added in v0.10.0

func (self ISize) SaturatingMul(rhs ISize) ISize

Saturating integer multiplication. Computes self * rhs, saturating at the numeric bounds instead of overflowing.

func (ISize) SaturatingSub added in v0.9.0

func (self ISize) SaturatingSub(rhs ISize) ISize

Saturating integer subtraction. Computes self - rhs, saturating at the numeric bounds instead of overflowing.

func (ISize) Shl added in v0.11.0

func (lhs ISize) Shl(rhs ISize) ISize

func (ISize) Shr added in v0.11.0

func (lhs ISize) Shr(rhs ISize) ISize

func (ISize) Sub added in v0.6.0

func (self ISize) Sub(rhs ISize) ISize

Sub implements

func (*ISize) SubAssign added in v0.6.0

func (self *ISize) SubAssign(rhs ISize)

SubAssign implements

func (ISize) ToString added in v0.6.0

func (self ISize) ToString() String

func (ISize) WrappingAdd added in v0.8.0

func (self ISize) WrappingAdd(rhs ISize) ISize

Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.

func (ISize) WrappingDiv added in v0.9.0

func (self ISize) WrappingDiv(rhs ISize) ISize

Wrapping (modular) division. Computes self / rhs, wrapping around at the boundary of the type.

func (ISize) WrappingMul added in v0.9.0

func (self ISize) WrappingMul(rhs ISize) ISize

Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

func (ISize) WrappingSub added in v0.8.0

func (self ISize) WrappingSub(rhs ISize) ISize

Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.

type IntoIterator

type IntoIterator[T any] interface {
	IntoIter() Iterator[T]
}

type Iterator

type Iterator[T any] interface {
	Next() Option[T]
	Map(f func(T) T) Iterator[T]
	Filter(f func(T) Bool) Iterator[T]
	Fold(init T, f func(T, T) T) T
	Rev() Iterator[T]
	CollectToVec() Vec[T]
	CollectToLinkedList() LinkedList[T]
}

type JoinHandle added in v0.11.0

type JoinHandle struct {
	// contains filtered or unexported fields
}

An owned permission to join on a thread (block on its termination).

func Spawn added in v0.11.0

func Spawn(f func()) JoinHandle

Spawns a new thread, returning a JoinHandle for it.

func (JoinHandle) IsFinished added in v0.11.0

func (self JoinHandle) IsFinished() bool

Checks if the associated thread has finished running its main function.

func (JoinHandle) Join added in v0.11.0

func (self JoinHandle) Join() Result[Unit]

Waits for the associated thread to finish.

type LinkedList added in v0.5.0

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

LinkedList is a doubly-linked list.

func LinkedListNew added in v0.5.0

func LinkedListNew[T any]() LinkedList[T]

Creates an empty LinkedList.

func (*LinkedList[T]) Append added in v0.5.0

func (list *LinkedList[T]) Append(other *LinkedList[T])

Moves all elements from other to the end of the list. This reuses all the nodes from other and moves them into self. After this operation, other becomes empty. This operation should compute in O(1) time and O(1) memory.

	list1 := gost.LinkedListNew[gost.I32]()
	list1.PushBack(gost.I32(1))
	list1.PushBack(gost.I32(2))
	list1.PushBack(gost.I32(3))
	list2 := gost.LinkedListNew[gost.I32]()
	list2.PushBack(gost.I32(4))
	list2.PushBack(gost.I32(5))
 list1.Append(&list2)
	gost.AssertEq(list1.Len(), gost.USize(5))
	gost.AssertEq(list2.Len(), gost.USize(0))

func (LinkedList[T]) AsRef added in v0.7.3

func (self LinkedList[T]) AsRef() *LinkedList[T]

impl AsRef for LinkedList

func (*LinkedList[T]) Back added in v0.5.0

func (list *LinkedList[T]) Back() Option[*T]

Provides a reference to the back element, or None if the list is empty. This operation should compute in O(1) time.

list := gost.LinkedListNew[gost.I32]()
list.PushBack(gost.I32(1))
list.PushBack(gost.I32(2))
gost.AssertEq(list.Back().Unwrap(), gost.I32(2))

func (*LinkedList[T]) Clear added in v0.5.0

func (list *LinkedList[T]) Clear()

Removes all elements from the LinkedList. This operation should compute in O(1) time. +GC

list := gost.LinkedListNew[gost.I32]()
list.PushBack(gost.I32(1))
list.PushBack(gost.I32(2))
list.Clear()
gost.Assert(list.IsEmpty())

func (LinkedList[T]) Clone added in v0.7.3

func (self LinkedList[T]) Clone() LinkedList[T]

impl Clone for LinkedList

func (LinkedList[T]) Debug added in v0.5.0

func (self LinkedList[T]) Debug() String

impl Debug for LinkedList

func (LinkedList[T]) Display added in v0.5.0

func (self LinkedList[T]) Display() String

impl Display for LinkedList

func (LinkedList[T]) Eq added in v0.7.3

func (self LinkedList[T]) Eq(rhs LinkedList[T]) Bool

impl Eq for LinkedList

func (*LinkedList[T]) Front added in v0.5.0

func (list *LinkedList[T]) Front() Option[*T]

Provides a reference to the front element, or None if the list is empty. This operation should compute in O(1) time.

list := gost.LinkedListNew[gost.I32]()
list.PushFront(gost.I32(1))
list.PushFront(gost.I32(2))
gost.AssertEq(list.Front().Unwrap(), gost.I32(2))

func (*LinkedList[T]) IntoIter added in v0.5.0

func (list *LinkedList[T]) IntoIter() Iterator[T]

into_iter

func (LinkedList[T]) IsEmpty added in v0.5.0

func (list LinkedList[T]) IsEmpty() Bool

Returns true if the LinkedList is empty. This operation should compute in O(1) time.

list := gost.LinkedListNew[gost.I32]()
gost.Assert(list.IsEmpty())

list.PushBack(gost.I32(1))
gost.Assert(!list.IsEmpty())

func (LinkedList[T]) Len added in v0.5.0

func (list LinkedList[T]) Len() USize

Returns the length of the LinkedList. This operation should compute in O(1) time.

list := gost.LinkedListNew[gost.I32]()
list.PushBack(gost.I32(1))
list.PushBack(gost.I32(2))
gost.AssertEq(list.Len(), gost.USize(2))

func (*LinkedList[T]) PopBack added in v0.5.0

func (list *LinkedList[T]) PopBack() Option[T]

Removes the last element from a list and returns it, or None if it is empty. This operation should compute in O(1) time.

list := gost.LinkedListNew[gost.I32]()
list.PushBack(gost.I32(1))
list.PushBack(gost.I32(2))
gost.AssertEq(list.PopBack().Unwrap(), gost.I32(2))
gost.AssertEq(list.PopBack().Unwrap(), gost.I32(1))
gost.Assert(list.PopBack().IsNone())

func (*LinkedList[T]) PopFront added in v0.5.0

func (list *LinkedList[T]) PopFront() Option[T]

Removes the first element and returns it, or None if the list is empty. This operation should compute in O(1) time.

list := gost.LinkedListNew[gost.I32]()
list.PushFront(gost.I32(1))
list.PushFront(gost.I32(2))
gost.AssertEq(list.PopFront().Unwrap(), gost.I32(2))
gost.AssertEq(list.PopFront().Unwrap(), gost.I32(1))

func (*LinkedList[T]) PushBack added in v0.5.0

func (list *LinkedList[T]) PushBack(value T)

Appends an element to the back of a list. This operation should compute in O(1) time.

list := gost.LinkedListNew[gost.I32]()
list.PushBack(gost.I32(1))
list.PushBack(gost.I32(2))
gost.AssertEq(list.Len(), gost.USize(2))

func (*LinkedList[T]) PushFront added in v0.5.0

func (list *LinkedList[T]) PushFront(value T)

Adds an element first in the list. This operation should compute in O(1) time.

list := gost.LinkedListNew[gost.I32]()
list.PushFront(gost.I32(1))
list.PushFront(gost.I32(2))
gost.AssertEq(list.Len(), gost.USize(2))

type LinkedListIter added in v0.5.0

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

linked list iterator

func (LinkedListIter[T]) CollectToLinkedList added in v0.6.0

func (self LinkedListIter[T]) CollectToLinkedList() LinkedList[T]

Collect To LinkedList

func (LinkedListIter[T]) CollectToVec added in v0.5.0

func (self LinkedListIter[T]) CollectToVec() Vec[T]

Collect To Vec

func (LinkedListIter[T]) Filter added in v0.5.0

func (self LinkedListIter[T]) Filter(f func(T) Bool) Iterator[T]

filter

func (LinkedListIter[T]) Fold added in v0.5.0

func (self LinkedListIter[T]) Fold(init T, f func(T, T) T) T

fold

func (LinkedListIter[T]) Map added in v0.5.0

func (self LinkedListIter[T]) Map(f func(T) T) Iterator[T]

map

func (*LinkedListIter[T]) Next added in v0.5.0

func (self *LinkedListIter[T]) Next() Option[T]

next

func (LinkedListIter[T]) Rev added in v0.5.0

func (self LinkedListIter[T]) Rev() Iterator[T]

rev

type LinkedListNode added in v0.5.0

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

type Mul

type Mul[T any] interface {
	Mul(rhs T) T
}

Mul is a trait for types that support multiplication.

type MulAssign

type MulAssign[T any] interface {
	MulAssign(rhs T)
}

The multiplication assignment operator *=.

type Mutex added in v0.7.3

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

A mutual exclusion lock.

locker := MutexNew[ISize](0)
ptr := locker.Lock()
*ptr = 1
locker.Unlock()

func MutexNew added in v0.7.3

func MutexNew[T any](value T) Mutex[T]

func (*Mutex[T]) Lock added in v0.7.3

func (self *Mutex[T]) Lock() *T

Acquires a mutex, blocking the current thread until it is able to do so.

locker := MutexNew[ISize](0)
ptr := locker.Lock()
*ptr = 1

func (*Mutex[T]) TryLock added in v0.7.3

func (self *Mutex[T]) TryLock() Result[*T]

Attempts to acquire this lock. If the lock could not be acquired at this time, then Err is returned. Otherwise, an RAII guard is returned. The lock will be unlocked when the guard is dropped.

locker := MutexNew[ISize](0)
ptr := locker.TryLock()
if ptr.IsErr() {
    panic("Mutex is locked")
}
*ptr.Unwrap() = 1

func (*Mutex[T]) Unlock added in v0.7.3

func (self *Mutex[T]) Unlock()

Immediately drops the guard, and consequently unlocks the mutex.

locker := MutexNew[ISize](0)
ptr := locker.Lock()
*ptr = 1
locker.Unlock()

type Neg added in v0.11.0

type Neg[T any] interface {
	Neg() T
}

type Option

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

Type Option represents an optional value: every Option is either Some and contains a value, or None, and does not. Option types are very common in Rust code

func None

func None[T any]() Option[T]

None returns an Option<T> with a None value.

func Some

func Some[T any](value T) Option[T]

Some returns an Option<T> with a Some value.

func (Option[T]) And

func (self Option[T]) And(optb Option[any]) Option[any]

Returns None if the option is None, otherwise returns optb. Arguments passed to and are eagerly evaluated; if you are passing the result of a function call, it is recommended to use and_then, which is lazily evaluated.

x := Some(gost.I32(2))
y := None[gost.I32]()
gost.AssertEq(x.and(y), None);

x := Some(gost.I32(2))
y := Some(gost.I32(3))
gost.AssertEq(x.and(y), Some(gost.I32(3)));

x := None[gost.I32]()
y := None[gost.I32]()
gost.AssertEq(x.and(y), None);

x := Some(gost.I32(2))
y := Some(gost.I32(3))
gost.AssertEq(x.and(y), Some(gost.I32(3)));

func (Option[T]) AndThen

func (self Option[T]) AndThen(f func(T) Option[any]) Option[any]

Returns None if the option is None, otherwise calls f with the wrapped value and returns the result. Some languages call this operation flatmap.

x := Some(gost.I32(2))
gost.AssertEq(x.and_then(func(value gost.I32) Option[gost.I32] { return Some[gost.I32](value + 1) }), Some(gost.I32(3)))

x := None[gost.I32]()
gost.AssertEq(x.and_then(func(value gost.I32) Option[gost.I32] { return Some[gost.I32](value + 1) }), None[gost.I32]())

func (Option[T]) AsRef added in v0.7.3

func (self Option[T]) AsRef() *Option[T]

impl AsRef for Option

func (Option[T]) Clone added in v0.7.3

func (self Option[T]) Clone() Option[T]

impl Clone for Option

func (Option[T]) Debug

func (self Option[T]) Debug() String

impl Debug for Option

func (Option[T]) Display

func (self Option[T]) Display() String

impl Display for Option

func (Option[T]) Eq added in v0.7.3

func (self Option[T]) Eq(rhs Option[T]) Bool

impl Eq for Option

func (Option[T]) Expect

func (self Option[T]) Expect(message string) T

Returns the contained Some value, consuming the self value.

x := Some(gost.I32(2))
gost.AssertEq(x.Expect(gost.String("failed")), gost.I32(2))

func (Option[T]) Filter

func (self Option[T]) Filter(predicate func(T) Bool) Option[T]

Returns None if the option is None, otherwise calls predicate with the wrapped value and returns: 1. Some(t) if predicate returns true (where t is the wrapped value), and 2. None if predicate returns false.

x := Some(gost.I32(2))
gost.AssertEq(x.filter(func(value gost.I32) gost.Bool { return value == 2 }), Some(gost.I32(2)))

func (*Option[T]) GetOrInsert

func (self *Option[T]) GetOrInsert(value T) *T

Inserts value into the option if it is None, then returns a mutable reference to the contained value. See also Option::insert, which updates the value even if the option already contains Some.

x := None[gost.I32]()
gost.AssertEq(x.GetOrInsert(gost.I32(2)), Some(gost.I32(2)))

x := Some(gost.I32(3))
gost.AssertEq(x.GetOrInsert(gost.I32(2)), Some(gost.I32(3)))

func (*Option[T]) GetOrInsertWith

func (self *Option[T]) GetOrInsertWith(f func() T) *T

Inserts a value computed from f into the option if it is None, then returns a mutable reference to the contained value.

x := None[gost.I32]()
gost.AssertEq(x.GetOrInsertWith(func() gost.I32 { return gost.I32(2) }), Some(gost.I32(2)))

x := Some(gost.I32(3))
gost.AssertEq(x.GetOrInsertWith(func() gost.I32 { return gost.I32(2) }), Some(gost.I32(3)))

func (*Option[T]) Insert

func (self *Option[T]) Insert(value T) *T

Inserts value into the option, then returns a mutable reference to it. If the option already contains a value, the old value is dropped. See also Option::get_or_insert, which doesn’t update the value if the option already contains Some.

x := None[gost.I32]()
gost.AssertEq(x.Insert(gost.I32(2)), Some(gost.I32(2)))

x := Some(gost.I32(3))
gost.AssertEq(x.Insert(gost.I32(2)), Some(gost.I32(2)))

func (Option[T]) IsNone

func (self Option[T]) IsNone() Bool

Returns true if the option is a None value.

x := None[gost.I32]()
gost.Assert(x.IsNone())

func (Option[T]) IsSome

func (self Option[T]) IsSome() Bool

Returns true if the option is a Some value.

x := Some(gost.I32(2))
gost.Assert(x.IsSome())

func (*Option[T]) IsSomeAnd

func (self *Option[T]) IsSomeAnd(f func(T) Bool) Bool

Returns true if the option is a Some and the value inside of it matches a predicate.

x := Some(gost.I32(2))
gost.Assert(x.IsSomeAnd(func(value gost.I32) gost.Bool { return value == 2 }))

func (Option[T]) Map

func (self Option[T]) Map(f func(T) T) Option[T]

Maps an Option<T> to other Option<T> by applying a function to a contained value (if Some) or returns None (if None).

x := Some(gost.I32(2))
gost.AssertEq(x.Map(func(value gost.I32) gost.I32 { return value + 1 }), Some(gost.I32(3)))

x := None[gost.I32]()
gost.AssertEq(x.Map(func(value gost.I32) gost.I32 { return value + 1 }), None[gost.I32]())

func (Option[T]) MapOr

func (self Option[T]) MapOr(defaultValue T, f func(T) T) T

Returns the provided default result (if none), or applies a function to the contained value (if any). Arguments passed to map_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use map_or_else, which is lazily evaluated.

x := Some(gost.I32(2))
gost.AssertEq(x.MapOr(gost.I32(3), func(value gost.I32) gost.I32 { return value + 1 }), gost.I32(3))

x := None[gost.I32]()
gost.AssertEq(x.MapOr(gost.I32(3), func(value gost.I32) gost.I32 { return value + 1 }), gost.I32(3))

func (Option[T]) MapOrElse

func (self Option[T]) MapOrElse(defaultValue func() T, f func(T) T) T

Computes a default function result (if none), or applies a different function to the contained value (if any).

x := Some(gost.I32(2))
gost.AssertEq(x.MapOrElse(func() gost.I32 { return gost.I32(3) }, func(value gost.I32) gost.I32 { return value + 1 }), gost.I32(3))

func (Option[T]) Or

func (self Option[T]) Or(optb Option[T]) Option[T]

Returns the option if it contains a value, otherwise returns optb. Arguments passed to or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use or_else, which is lazily evaluated.

x := Some(gost.I32(2))
y := None[gost.I32]()
gost.AssertEq(x.or(y), Some(gost.I32(2)));

x := Some(gost.I32(2))
y := Some(gost.I32(3))
gost.AssertEq(x.or(y), Some(gost.I32(2)));

func (Option[T]) OrElse

func (self Option[T]) OrElse(f func() Option[T]) Option[T]

Returns the option if it contains a value, otherwise calls f and returns the result.

x := Some(gost.I32(2))
gost.AssertEq(x.or_else(func() Option[gost.I32] { return Some[gost.I32](3) }), Some(gost.I32(2)))

x := None[gost.I32]()
gost.AssertEq(x.or_else(func() Option[gost.I32] { return Some[gost.I32](3) }), Some(gost.I32(3)))

func (*Option[T]) Replace

func (self *Option[T]) Replace(value T) Option[T]

Replaces the actual value in the option by the value given in parameter, returning the old value if present, leaving a Some in its place without deinitializing either one.

x := Some(gost.I32(2))
gost.AssertEq(x.Replace(gost.I32(3)), Some(gost.I32(2)))

x := None[gost.I32]()
gost.AssertEq(x.Replace(gost.I32(3)), None[gost.I32]())

func (*Option[T]) Take

func (self *Option[T]) Take() Option[T]

Takes the value out of the option, leaving a None in its place.

x := Some(gost.I32(2))
gost.AssertEq(x.Take(), Some(gost.I32(2)))

x := None[gost.I32]()
gost.AssertEq(x.Take(), None[gost.I32]())

func (Option[T]) Unwrap

func (self Option[T]) Unwrap() T

Returns the contained Some value, consuming the self value. Because this function may panic, its use is generally discouraged. Instead, prefer to use pattern matching and handle the None case explicitly, or call unwrap_or, unwrap_or_else, or unwrap_or_default.

x := Some(gost.I32(2))
gost.AssertEq(x.Unwrap(), gost.I32(2))

func (Option[T]) UnwrapOr

func (self Option[T]) UnwrapOr(value T) T

Returns the contained Some value or a provided default. Arguments passed to unwrap_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrap_or_else, which is lazily evaluated.

x := Some(gost.I32(2))
gost.AssertEq(x.UnwrapOr(gost.I32(3)), gost.I32(2))

x := None[gost.I32]()
gost.AssertEq(x.UnwrapOr(gost.I32(3)), gost.I32(3))

func (Option[T]) UnwrapOrElse

func (self Option[T]) UnwrapOrElse(f func() T) T

Returns the contained Some value or computes it from a closure.

x := Some(gost.I32(2))
gost.AssertEq(x.UnwrapOrElse(func() gost.I32 { return gost.I32(3) }), gost.I32(2))

func (Option[T]) Xor

func (self Option[T]) Xor(optb Option[T]) Option[T]

Returns Some if exactly one of self, optb is Some, otherwise returns None.

x := Some(gost.I32(2))
y := None[gost.I32]()
gost.AssertEq(x.Xor(y), Some(gost.I32(2)));

x := Some(gost.I32(2))
y := Some(gost.I32(3))
gost.AssertEq(x.Xor(y), None[gost.I32]());

type Ord

type Ord[T any] interface {
	Cmp(rhs T) Ordering
	Eq[T]
}

Trait for types that form a total order.

type Ordering

type Ordering int
const OrderingEqual Ordering = Ordering(0)
const OrderingGreater Ordering = Ordering(1)
const OrderingLess Ordering = Ordering(-1)

Ordering enum values

type Pair

type Pair[K any, V any] struct {
	Key   K
	Value V
}

Pair is a tuple of two values.

func (Pair[K, V]) AsRef added in v0.7.3

func (p Pair[K, V]) AsRef() *Pair[K, V]

impl AsRef for Pair

func (Pair[K, V]) Clone added in v0.7.0

func (p Pair[K, V]) Clone() Pair[K, V]

impl Clone for Pair

func (Pair[K, V]) Cmp added in v0.7.0

func (p Pair[K, V]) Cmp(other Pair[K, V]) Ordering

impl Ord for Pair

func (Pair[K, V]) Debug added in v0.7.0

func (p Pair[K, V]) Debug() string

impl Debug for Pair

func (Pair[K, V]) Display added in v0.10.0

func (p Pair[K, V]) Display() string

impl Display for Pair

func (Pair[K, V]) Eq added in v0.7.0

func (p Pair[K, V]) Eq(other Pair[K, V]) Bool

impl Eq for Pair

func (Pair[K, V]) ToString added in v0.7.0

func (p Pair[K, V]) ToString() string

impl Display for Pair

type Rem added in v0.9.0

type Rem[T any] interface {
	Rem(rhs T) T
}

Rem is a trait for types that support remainder after division.

type RemAssign added in v0.9.0

type RemAssign[T any] interface {
	RemAssign(rhs T)
}

The remainder assignment operator %=.

type Result

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

Error handling with the Result type. Result<T> is the type used for returning and propagating errors. It is an enum with the variants, Ok(T), representing success and containing a value, and Err, representing error and containing an error value.

func Copy

func Copy(from String, to String) Result[any]

Copies the contents of one file to another. This function will also copy the permission bits of the original file to the destination file. This function will overwrite the contents of to.

func CreateDir

func CreateDir(path String) Result[any]

Creates a new, empty directory at the provided path

func Err

func Err[T any](err error) Result[T]

Creates a new Result<T> containing an Err value.

func Ok

func Ok[T any](value T) Result[T]

Creates a new Result<T> containing an Ok value.

func Read

func Read(path String) Result[[]Byte]

Read the entire contents of a file into a bytes vector.

func ReadDir

func ReadDir(path String) Result[Vec[DirEntry]]

Returns an iterator over the entries within a directory.

func ReadToString

func ReadToString(path String) Result[String]

Read the entire contents of a file into a string.

func RemoveDir

func RemoveDir(path String) Result[any]

Removes an empty directory.

func RemoveFile

func RemoveFile(path String) Result[any]

Removes a file from the filesystem.

func Rename

func Rename(from String, to String) Result[any]

Rename a file or directory to a new name, replacing the original file if to already exists. This will not work if the new name is on a different mount point.

func StringFromUTF16 added in v0.10.0

func StringFromUTF16(bytes Vec[U16]) Result[String]

Decode a UTF-16–encoded vector v into a String, returning Err if v contains any invalid data.

func Write

func Write(path String, data []Byte) Result[any]

Write a slice as the entire contents of a file.

func (Result[T]) And

func (self Result[T]) And(res Result[T]) Result[T]

Returns res if the result is Ok, otherwise returns the Err value of self. Arguments passed to and are eagerly evaluated; if you are passing the result of a function call, it is recommended to use and_then, which is lazily evaluated.

x := gost.Ok[gost.I32](gost.I32(2))
gost.AssertEq(x.And(gost.Ok[gost.I32](gost.I32(3))), gost.Ok[gost.I32](gost.I32(3)))

y := gost.Err[gost.I32](errors.New("error"))
gost.AssertEq(y.And(gost.Ok[gost.I32](gost.I32(3))), gost.Err[gost.I32](errors.New("error")))

func (Result[T]) AndThen

func (self Result[T]) AndThen(op func(T) Result[T]) Result[T]

Calls op if the result is Ok, otherwise returns the Err value of self. This function can be used for control flow based on Result values.

x := gost.Ok[gost.I32](gost.I32(2))
gost.AssertEq(x.AndThen(func(value Int) Result[Int] { return gost.Ok[Int](value + 1) }), gost.Ok[gost.I32](gost.I32(3)))

y := gost.Err[gost.I32](errors.New("error"))
gost.AssertEq(y.AndThen(func(value Int) Result[Int] { return gost.Ok[Int](value + 1) }), gost.Err[gost.I32](errors.New("error")))

func (Result[T]) AsRef added in v0.7.3

func (self Result[T]) AsRef() *Result[T]

impl AsRef for Result

func (Result[T]) Clone added in v0.7.3

func (self Result[T]) Clone() Result[T]

impl Clone for Result

func (Result[T]) Debug

func (self Result[T]) Debug() String

impl Debug for Result

func (Result[T]) Display

func (self Result[T]) Display() String

impl Display for Result

func (Result[T]) Eq added in v0.7.3

func (self Result[T]) Eq(rhs Result[T]) Bool

impl Eq for Result

func (Result[T]) Err

func (self Result[T]) Err() Option[error]

Converts from Result<T, E> to Option<E>. Converts self into an Option<E>, consuming self, and discarding the success value, if any.

x := gost.Ok[gost.I32](gost.I32(2))
gost.AssertEq(x.Err(), gost.None[error]())

y := gost.Err[gost.I32](errors.New("error"))
gost.AssertEq(y.Err(), gost.Some[error](errors.New("error")))

func (Result[T]) Expect

func (self Result[T]) Expect(message string) T

Returns the contained Ok value, consuming the self value. Because this function may panic, its use is generally discouraged. Instead, prefer to use pattern matching and handle the Err case explicitly, or call unwrap_or, unwrap_or_else, or unwrap_or_default.

x := gost.Ok[gost.I32](gost.I32(2))
gost.AssertEq(x.Expect("error"), gost.I32(2))

func (Result[T]) ExpectErr

func (self Result[T]) ExpectErr(message string) error

Returns the contained Err value, consuming the self value.

x := gost.Err[gost.I32](errors.New("error"))
gost.AssertEq(x.ExpectErr("error"), errors.New("error"))

func (Result[T]) IsErr

func (self Result[T]) IsErr() Bool

Returns true if the result is Err.

x := gost.Ok[gost.I32](gost.I32(2))
gost.Assert(!x.IsErr())

y := gost.Err[gost.I32](errors.New("error"))
gost.Assert(y.IsErr())

func (Result[T]) IsErrAnd

func (self Result[T]) IsErrAnd(predicate func(error) Bool) Bool

Returns true if the result is Err and the value inside of it matches a predicate.

x := gost.Err[gost.I32](errors.New("error"))
gost.Assert(x.IsErrAnd(func(err error) Bool { return err.Error() == "error" }))

y := gost.Err[gost.I32](errors.New("error"))
gost.Assert(!y.IsErrAnd(func(err error) Bool { return err.Error() == "error2" }))

func (Result[T]) IsOk

func (self Result[T]) IsOk() Bool

Returns true if the result is Ok.

x := gost.Ok[gost.I32](gost.I32(2))
gost.Assert(x.IsOk())

y := gost.Err[gost.I32](errors.New("error"))
gost.Assert(!y.IsOk())

func (Result[T]) IsOkAnd

func (self Result[T]) IsOkAnd(predicate func(T) Bool) Bool

Returns true if the result is Ok and the value inside of it matches a predicate.

x := gost.Ok[gost.I32](gost.I32(2))
gost.Assert(x.IsOkAnd(func(value Int) Bool { return value == 2 }))

y := gost.Ok[gost.I32](gost.I32(3))
gost.Assert(!y.IsOkAnd(func(value Int) Bool { return value == 2 }))

func (Result[T]) Map

func (self Result[T]) Map(f func(T) T) Result[T]

Maps a Result<T, E> to Result<U, E> by applying a function to a contained Ok value, leaving an Err value untouched. This function can be used to compose the results of two functions.

x := gost.Ok[gost.I32](gost.I32(2))
gost.AssertEq(x.Map(func(value Int) Int { return value + 1 }), gost.Ok[gost.I32](gost.I32(3)))

y := gost.Err[gost.I32](errors.New("error"))
gost.AssertEq(y.Map(func(value Int) Int { return value + 1 }), gost.Err[gost.I32](errors.New("error")))

func (Result[T]) MapErr

func (self Result[T]) MapErr(f func(error) error) Result[T]

Maps a Result<T, E> to Result<T, F> by applying a function to a contained Err value, leaving an Ok value untouched. This function can be used to pass through a successful result while handling an error.

x := gost.Ok[gost.I32](gost.I32(2))
gost.AssertEq(x.MapErr(func(err error) error { return errors.New("error2") }), gost.Ok[gost.I32](gost.I32(2)))

y := gost.Err[gost.I32](errors.New("error"))
gost.AssertEq(y.MapErr(func(err error) error { return errors.New("error2") }), gost.Err[gost.I32](errors.New("error2")))

func (Result[T]) MapOr

func (self Result[T]) MapOr(defaultValue T, f func(T) T) T

Returns the provided default (if Err), or applies a function to the contained value (if Ok), Arguments passed to map_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use map_or_else, which is lazily evaluated.

x := gost.Ok[gost.I32](gost.I32(2))
gost.AssertEq(x.MapOr(gost.I32(3), func(value Int) Int { return value + 1 }), gost.I32(3))

y := gost.Err[gost.I32](errors.New("error"))
gost.AssertEq(y.MapOr(gost.I32(3), func(value Int) Int { return value + 1 }), gost.I32(3))

func (Result[T]) MapOrElse

func (self Result[T]) MapOrElse(defaultValue func() T, f func(T) T) T

Maps a Result<T, E> to U by applying fallback function default to a contained Err value, or function f to a contained Ok value. This function can be used to unpack a successful result while handling an error.

x := gost.Ok[gost.I32](gost.I32(2))
gost.AssertEq(x.MapOrElse(func() Int { return gost.I32(3) }, func(value Int) Int { return value + 1 }), gost.I32(3))

y := gost.Err[gost.I32](errors.New("error"))
gost.AssertEq(y.MapOrElse(func() Int { return gost.I32(3) }, func(value Int) Int { return value + 1 }), gost.I32(3))

func (Result[T]) Ok

func (self Result[T]) Ok() Option[T]

Converts from Result<T, E> to Option<T>. Converts self into an Option<T>, consuming self, and discarding the error, if any.

x := gost.Ok[gost.I32](gost.I32(2))
gost.AssertEq(x.Ok(), gost.Some[gost.I32](gost.I32(2)))

y := gost.Err[gost.I32](errors.New("error"))
gost.AssertEq(y.Ok(), gost.None[gost.I32]())

func (Result[T]) Or

func (self Result[T]) Or(res Result[T]) Result[T]

Returns res if the result is Err, otherwise returns the Ok value of self. Arguments passed to or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use or_else, which is lazily evaluated.

x := gost.Ok[gost.I32](gost.I32(2))
gost.AssertEq(x.Or(gost.Ok[gost.I32](gost.I32(3))), gost.Ok[gost.I32](gost.I32(2)))

y := gost.Err[gost.I32](errors.New("error"))
gost.AssertEq(y.Or(gost.Ok[gost.I32](gost.I32(3))), gost.Ok[gost.I32](gost.I32(3)))

func (Result[T]) OrElse

func (self Result[T]) OrElse(op func(error) Result[T]) Result[T]

Calls op if the result is Err, otherwise returns the Ok value of self. This function can be used for control flow based on result values.

x := gost.Ok[gost.I32](gost.I32(2))
gost.AssertEq(x.OrElse(func(err error) Result[Int] { return gost.Ok[Int](gost.I32(3)) }), gost.Ok[gost.I32](gost.I32(2)))

y := gost.Err[gost.I32](errors.New("error"))
gost.AssertEq(y.OrElse(func(err error) Result[Int] { return gost.Ok[Int](gost.I32(3)) }), gost.Ok[gost.I32](gost.I32(3)))

func (Result[T]) Unwrap

func (self Result[T]) Unwrap() T

Returns the contained Ok value, consuming the self value. Because this function may panic, its use is generally discouraged. Instead, prefer to use pattern matching and handle the Err case explicitly, or call unwrap_or, unwrap_or_else, or unwrap_or_default.

x := gost.Ok[gost.I32](gost.I32(2))
gost.AssertEq(x.Unwrap(), gost.I32(2))

func (Result[T]) UnwrapErr

func (self Result[T]) UnwrapErr() error

Returns the contained Err value, consuming the self value.

x := gost.Err[gost.I32](errors.New("error"))
gost.AssertEq(x.UnwrapErr(), errors.New("error"))

func (Result[T]) UnwrapOr

func (self Result[T]) UnwrapOr(defaultValue T) T

Returns the contained Ok value or a provided default. Arguments passed to unwrap_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrap_or_else, which is lazily evaluated.

x := gost.Ok[gost.I32](gost.I32(2))
gost.AssertEq(x.UnwrapOr(gost.I32(3)), gost.I32(2))

y := gost.Err[gost.I32](errors.New("error"))
gost.AssertEq(y.UnwrapOr(gost.I32(3)), gost.I32(3))

func (Result[T]) UnwrapOrElse

func (self Result[T]) UnwrapOrElse(f func() T) T

Returns the contained Ok value or computes it from a closure.

x := gost.Ok[gost.I32](gost.I32(2))
gost.AssertEq(x.UnwrapOrElse(func() Int { return gost.I32(3) }), gost.I32(2))

y := gost.Err[gost.I32](errors.New("error"))
gost.AssertEq(y.UnwrapOrElse(func() Int { return gost.I32(3) }), gost.I32(3))

type Shl added in v0.11.0

type Shl[T any] interface {
	Shl(rhs T) T
}

type Shr added in v0.11.0

type Shr[T any] interface {
	Shr(rhs T) T
}

type Stdin

type Stdin struct {
	// contains filtered or unexported fields
}

func (*Stdin) Lock

func (self *Stdin) Lock() *sync.Mutex

Locks this handle to the standard input stream, returning a readable guard.

func (*Stdin) ReadLine

func (self *Stdin) ReadLine(buffer *String)

Locks this handle and reads a line of input, appending it to the specified buffer.

type String

type String string

func Format

func Format(format String, params ...any) String

func StringFromUTF8 added in v0.10.0

func StringFromUTF8(bytes Vec[U8]) String

Converts a vector of bytes to a String.

func (String) Add added in v0.6.0

func (self String) Add(rhs String) String

func (*String) AddAssign added in v0.6.0

func (self *String) AddAssign(rhs String)

func (String) AsRef added in v0.7.3

func (self String) AsRef() *String

func (String) Chars added in v0.10.0

func (self String) Chars() Vec[Char]

Returns an iterator over the chars of a string slice.

func (String) Clone

func (self String) Clone() String

func (String) Cmp

func (self String) Cmp(rhs String) Ordering

func (String) Contains added in v0.10.0

func (self String) Contains(str String) bool

Returns true if the given pattern matches a sub-slice of this string slice. Returns false if it does not. The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

func (String) Debug

func (self String) Debug() String

func (String) Display

func (self String) Display() String

func (String) Eq

func (self String) Eq(rhs String) Bool

func (String) Find added in v0.10.0

func (self String) Find(str String) Option[USize]

Returns the byte index of the first character of this string slice that matches the pattern. Returns None if the pattern doesn’t match. The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

func (String) IntoBytes added in v0.10.0

func (self String) IntoBytes() Vec[U8]

Converts a String into a byte vector. This consumes the String, so we do not need to copy its contents.

func (String) IsEmpty added in v0.10.0

func (self String) IsEmpty() bool

Returns true if this String has a length of zero, and false otherwise.

func (String) Len added in v0.10.0

func (self String) Len() USize

Returns the length of this String, in bytes, not chars or graphemes. In other words, it might not be what a human considers the length of the string.

func (String) ParseF64 added in v0.10.0

func (self String) ParseF64() Result[F64]

Parses this string slice into another type. (F64)

func (String) ParseI64 added in v0.10.0

func (self String) ParseI64() Result[I64]

Parses this string slice into another type. (I64)

func (String) ParseU64 added in v0.10.0

func (self String) ParseU64() Result[U64]

Parses this string slice into another type. (U64)

func (*String) Pop added in v0.10.0

func (self *String) Pop() Option[Char]

Removes the last character from the string buffer and returns it. Returns None if this String is empty.

func (*String) Push added in v0.10.0

func (self *String) Push(c Char) String

Appends the given char to the end of this String.

func (String) Repeat added in v0.10.0

func (self String) Repeat(n USize) String

Creates a new String by repeating a string n times.

func (String) Replace added in v0.10.0

func (self String) Replace(old String, new String) String

Replaces all matches of a pattern with another string. replace creates a new String, and copies the data from this string slice into it. While doing so, it attempts to find matches of a pattern. If it finds any, it replaces them with the replacement string slice.

func (String) Split added in v0.10.0

func (self String) Split(str String) Vec[String]

An iterator over substrings of this string slice, separated by characters matched by a string

func (String) ToLowercase added in v0.10.0

func (self String) ToLowercase() String

Returns the lowercase equivalent of this string slice, as a new String.

func (String) ToString

func (self String) ToString() String

func (String) ToUppercase added in v0.10.0

func (self String) ToUppercase() String

Returns the uppercase equivalent of this string slice, as a new String.

func (String) Trim added in v0.10.0

func (self String) Trim() String

Returns a string slice with leading and trailing whitespace removed. ‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property White_Space, which includes newlines.

type Sub

type Sub[T any] interface {
	Sub(rhs T) T
}

Sub is a trait for types that support subtraction.

type SubAssign

type SubAssign[T any] interface {
	SubAssign(rhs T)
}

The subtraction assignment operator -=.

type ToString

type ToString[T any] interface {
	ToString() String
}

A trait for converting a value to a String.

type TryLockError added in v0.7.3

type TryLockError struct{}

An error returned by TryLock.

func (TryLockError) Error added in v0.7.3

func (self TryLockError) Error() string

type U128 added in v0.11.0

type U128 struct {
	// contains filtered or unexported fields
}

func U128_FromU64 added in v0.11.0

func U128_FromU64(low U64) U128

func (U128) Add added in v0.11.0

func (self U128) Add(rhs U128) U128

func (*U128) AddAssign added in v0.11.0

func (self *U128) AddAssign(rhs U128)

func (U128) Cmp added in v0.11.0

func (self U128) Cmp(rhs U128) Ordering

func (U128) Debug added in v0.11.0

func (self U128) Debug() String

func (U128) Display added in v0.11.0

func (self U128) Display() String

func (U128) Div added in v0.11.0

func (lhs U128) Div(rhs U128) U128

func (*U128) DivAssign added in v0.11.0

func (self *U128) DivAssign(rhs U128)

func (U128) Eq added in v0.11.0

func (self U128) Eq(rhs U128) Bool

func (U128) Mul added in v0.11.0

func (self U128) Mul(rhs U128) U128

func (*U128) MulAssign added in v0.11.0

func (self *U128) MulAssign(rhs U128)

func (U128) Rem added in v0.11.0

func (lhs U128) Rem(rhs U128) U128

func (*U128) RemAssign added in v0.11.0

func (self *U128) RemAssign(rhs U128)

func (U128) Shl added in v0.11.0

func (lhs U128) Shl(rhs U128) U128

func (U128) Shr added in v0.11.0

func (lhs U128) Shr(rhs U128) U128

func (U128) Sub added in v0.11.0

func (self U128) Sub(rhs U128) U128

func (*U128) SubAssign added in v0.11.0

func (self *U128) SubAssign(rhs U128)

func (U128) ToString added in v0.11.0

func (self U128) ToString() String

type U16 added in v0.6.0

type U16 uint16

func (U16) AbsDiff added in v0.10.0

func (self U16) AbsDiff(other U16) U16

Computes the absolute difference between self and other. This function always returns the correct answer without overflow or panics by returning an unsigned integer.

func (U16) Add added in v0.6.0

func (self U16) Add(rhs U16) U16

func (*U16) AddAssign added in v0.6.0

func (self *U16) AddAssign(rhs U16)

func (U16) AsRef added in v0.7.3

func (self U16) AsRef() *U16

func (U16) CheckedAdd added in v0.9.0

func (self U16) CheckedAdd(rhs U16) Option[U16]

func (U16) CheckedDiv added in v0.9.0

func (self U16) CheckedDiv(rhs U16) Option[U16]

func (U16) CheckedMul added in v0.9.0

func (self U16) CheckedMul(rhs U16) Option[U16]

func (U16) CheckedRem added in v0.9.0

func (self U16) CheckedRem(rhs U16) Option[U16]

func (U16) CheckedSub added in v0.9.0

func (self U16) CheckedSub(rhs U16) Option[U16]

func (U16) Clone added in v0.6.0

func (self U16) Clone() U16

func (U16) Cmp added in v0.6.0

func (self U16) Cmp(rhs U16) Ordering

func (U16) Debug added in v0.6.0

func (self U16) Debug() String

func (U16) Display added in v0.6.0

func (self U16) Display() String

func (U16) Div added in v0.6.0

func (self U16) Div(rhs U16) U16

func (*U16) DivAssign added in v0.6.0

func (self *U16) DivAssign(rhs U16)

func (U16) Eq added in v0.6.0

func (self U16) Eq(rhs U16) Bool

func (U16) Mul added in v0.6.0

func (self U16) Mul(rhs U16) U16

func (*U16) MulAssign added in v0.6.0

func (self *U16) MulAssign(rhs U16)

func (U16) Pow added in v0.10.0

func (self U16) Pow(exp U32) U16

Raises self to the power of exp, using exponentiation by squaring.

func (U16) Rem added in v0.9.0

func (self U16) Rem(rhs U16) U16

func (*U16) RemAssign added in v0.9.0

func (self *U16) RemAssign(rhs U16)

func (U16) SaturatingAdd added in v0.10.0

func (self U16) SaturatingAdd(rhs U16) U16

func (U16) SaturatingDiv added in v0.10.0

func (self U16) SaturatingDiv(rhs U16) U16

func (U16) SaturatingMul added in v0.10.0

func (self U16) SaturatingMul(rhs U16) U16

func (U16) SaturatingSub added in v0.9.0

func (self U16) SaturatingSub(rhs U16) U16

func (U16) Shl added in v0.11.0

func (lhs U16) Shl(rhs U16) U16

func (U16) Shr added in v0.11.0

func (lhs U16) Shr(rhs U16) U16

func (U16) Sub added in v0.6.0

func (self U16) Sub(rhs U16) U16

func (*U16) SubAssign added in v0.6.0

func (self *U16) SubAssign(rhs U16)

func (U16) ToString added in v0.6.0

func (self U16) ToString() String

func (U16) WrappingAdd added in v0.8.0

func (self U16) WrappingAdd(rhs U16) U16

func (U16) WrappingDiv added in v0.9.0

func (self U16) WrappingDiv(rhs U16) U16

func (U16) WrappingMul added in v0.9.0

func (self U16) WrappingMul(rhs U16) U16

func (U16) WrappingSub added in v0.8.0

func (self U16) WrappingSub(rhs U16) U16

type U32 added in v0.6.0

type U32 uint32

func (U32) AbsDiff added in v0.10.0

func (self U32) AbsDiff(other U32) U32

Computes the absolute difference between self and other. This function always returns the correct answer without overflow or panics by returning an unsigned integer.

func (U32) Add added in v0.6.0

func (self U32) Add(rhs U32) U32

func (*U32) AddAssign added in v0.6.0

func (self *U32) AddAssign(rhs U32)

func (U32) AsRef added in v0.7.3

func (self U32) AsRef() *U32

func (U32) CheckedAdd added in v0.9.0

func (self U32) CheckedAdd(rhs U32) Option[U32]

func (U32) CheckedDiv added in v0.9.0

func (self U32) CheckedDiv(rhs U32) Option[U32]

func (U32) CheckedMul added in v0.9.0

func (self U32) CheckedMul(rhs U32) Option[U32]

func (U32) CheckedRem added in v0.9.0

func (self U32) CheckedRem(rhs U32) Option[U32]

func (U32) CheckedSub added in v0.9.0

func (self U32) CheckedSub(rhs U32) Option[U32]

func (U32) Clone added in v0.6.0

func (self U32) Clone() U32

func (U32) Cmp added in v0.6.0

func (self U32) Cmp(rhs U32) Ordering

func (U32) Debug added in v0.6.0

func (self U32) Debug() String

func (U32) Display added in v0.6.0

func (self U32) Display() String

func (U32) Div added in v0.6.0

func (self U32) Div(rhs U32) U32

func (*U32) DivAssign added in v0.6.0

func (self *U32) DivAssign(rhs U32)

func (U32) Eq added in v0.6.0

func (self U32) Eq(rhs U32) Bool

func (U32) Mul added in v0.6.0

func (self U32) Mul(rhs U32) U32

func (*U32) MulAssign added in v0.6.0

func (self *U32) MulAssign(rhs U32)

func (U32) Pow added in v0.10.0

func (self U32) Pow(exp U32) U32

Raises self to the power of exp, using exponentiation by squaring.

func (U32) Rem added in v0.9.0

func (self U32) Rem(rhs U32) U32

func (*U32) RemAssign added in v0.9.0

func (self *U32) RemAssign(rhs U32)

func (U32) SaturatingAdd added in v0.10.0

func (self U32) SaturatingAdd(rhs U32) U32

func (U32) SaturatingDiv added in v0.10.0

func (self U32) SaturatingDiv(rhs U32) U32

func (U32) SaturatingMul added in v0.10.0

func (self U32) SaturatingMul(rhs U32) U32

func (U32) SaturatingSub added in v0.9.0

func (self U32) SaturatingSub(rhs U32) U32

func (U32) Shl added in v0.11.0

func (lhs U32) Shl(rhs U32) U32

func (U32) Shr added in v0.11.0

func (lhs U32) Shr(rhs U32) U32

func (U32) Sub added in v0.6.0

func (self U32) Sub(rhs U32) U32

func (*U32) SubAssign added in v0.6.0

func (self *U32) SubAssign(rhs U32)

func (U32) ToString added in v0.6.0

func (self U32) ToString() String

func (U32) WrappingAdd added in v0.8.0

func (self U32) WrappingAdd(rhs U32) U32

func (U32) WrappingDiv added in v0.9.0

func (self U32) WrappingDiv(rhs U32) U32

func (U32) WrappingMul added in v0.9.0

func (self U32) WrappingMul(rhs U32) U32

func (U32) WrappingSub added in v0.8.0

func (self U32) WrappingSub(rhs U32) U32

type U64 added in v0.6.0

type U64 uint64

func (U64) AbsDiff added in v0.10.0

func (self U64) AbsDiff(other U64) U64

Computes the absolute difference between self and other. This function always returns the correct answer without overflow or panics by returning an unsigned integer.

func (U64) Add added in v0.6.0

func (self U64) Add(rhs U64) U64

func (*U64) AddAssign added in v0.6.0

func (self *U64) AddAssign(rhs U64)

func (U64) AsRef added in v0.7.3

func (self U64) AsRef() *U64

func (U64) CheckedAdd added in v0.9.0

func (self U64) CheckedAdd(rhs U64) Option[U64]

func (U64) CheckedDiv added in v0.9.0

func (self U64) CheckedDiv(rhs U64) Option[U64]

func (U64) CheckedMul added in v0.9.0

func (self U64) CheckedMul(rhs U64) Option[U64]

func (U64) CheckedRem added in v0.9.0

func (self U64) CheckedRem(rhs U64) Option[U64]

func (U64) CheckedSub added in v0.9.0

func (self U64) CheckedSub(rhs U64) Option[U64]

func (U64) Clone added in v0.6.0

func (self U64) Clone() U64

func (U64) Cmp added in v0.6.0

func (self U64) Cmp(rhs U64) Ordering

func (U64) Debug added in v0.6.0

func (self U64) Debug() String

func (U64) Display added in v0.6.0

func (self U64) Display() String

func (U64) Div added in v0.6.0

func (self U64) Div(rhs U64) U64

func (*U64) DivAssign added in v0.6.0

func (self *U64) DivAssign(rhs U64)

func (U64) Eq added in v0.6.0

func (self U64) Eq(rhs U64) Bool

func (U64) Mul added in v0.6.0

func (self U64) Mul(rhs U64) U64

func (*U64) MulAssign added in v0.6.0

func (self *U64) MulAssign(rhs U64)

func (U64) Pow added in v0.10.0

func (self U64) Pow(exp U32) U64

Raises self to the power of exp, using exponentiation by squaring.

func (U64) Rem added in v0.9.0

func (self U64) Rem(rhs U64) U64

func (*U64) RemAssign added in v0.9.0

func (self *U64) RemAssign(rhs U64)

func (U64) SaturatingAdd added in v0.10.0

func (self U64) SaturatingAdd(rhs U64) U64

func (U64) SaturatingDiv added in v0.10.0

func (self U64) SaturatingDiv(rhs U64) U64

func (U64) SaturatingMul added in v0.10.0

func (self U64) SaturatingMul(rhs U64) U64

func (U64) SaturatingSub added in v0.9.0

func (self U64) SaturatingSub(rhs U64) U64

func (U64) Shl added in v0.11.0

func (lhs U64) Shl(rhs U64) U64

func (U64) Shr added in v0.11.0

func (lhs U64) Shr(rhs U64) U64

func (U64) Sub added in v0.6.0

func (self U64) Sub(rhs U64) U64

func (*U64) SubAssign added in v0.6.0

func (self *U64) SubAssign(rhs U64)

func (U64) ToString added in v0.6.0

func (self U64) ToString() String

func (U64) WrappingAdd added in v0.8.0

func (self U64) WrappingAdd(rhs U64) U64

func (U64) WrappingDiv added in v0.9.0

func (self U64) WrappingDiv(rhs U64) U64

func (U64) WrappingMul added in v0.9.0

func (self U64) WrappingMul(rhs U64) U64

func (U64) WrappingSub added in v0.8.0

func (self U64) WrappingSub(rhs U64) U64

type U8 added in v0.6.0

type U8 uint8

func (U8) AbsDiff added in v0.10.0

func (self U8) AbsDiff(other U8) U8

Computes the absolute difference between self and other. This function always returns the correct answer without overflow or panics by returning an unsigned integer.

func (U8) Add added in v0.6.0

func (self U8) Add(rhs U8) U8

func (*U8) AddAssign added in v0.6.0

func (self *U8) AddAssign(rhs U8)

func (U8) AsRef added in v0.7.3

func (self U8) AsRef() *U8

func (U8) CheckedAdd added in v0.9.0

func (self U8) CheckedAdd(rhs U8) Option[U8]

func (U8) CheckedDiv added in v0.9.0

func (self U8) CheckedDiv(rhs U8) Option[U8]

func (U8) CheckedMul added in v0.9.0

func (self U8) CheckedMul(rhs U8) Option[U8]

func (U8) CheckedRem added in v0.9.0

func (self U8) CheckedRem(rhs U8) Option[U8]

func (U8) CheckedSub added in v0.9.0

func (self U8) CheckedSub(rhs U8) Option[U8]

func (U8) Clone added in v0.6.0

func (self U8) Clone() U8

func (U8) Cmp added in v0.6.0

func (self U8) Cmp(rhs U8) Ordering

func (U8) Debug added in v0.6.0

func (self U8) Debug() String

func (U8) Display added in v0.6.0

func (self U8) Display() String

func (U8) Div added in v0.6.0

func (self U8) Div(rhs U8) U8

func (*U8) DivAssign added in v0.6.0

func (self *U8) DivAssign(rhs U8)

func (U8) Eq added in v0.6.0

func (self U8) Eq(rhs U8) Bool

func (U8) Mul added in v0.6.0

func (self U8) Mul(rhs U8) U8

func (*U8) MulAssign added in v0.6.0

func (self *U8) MulAssign(rhs U8)

func (U8) Pow added in v0.10.0

func (self U8) Pow(exp U32) U8

Raises self to the power of exp, using exponentiation by squaring.

func (U8) Rem added in v0.9.0

func (self U8) Rem(rhs U8) U8

func (*U8) RemAssign added in v0.9.0

func (self *U8) RemAssign(rhs U8)

func (U8) SaturatingAdd added in v0.10.0

func (self U8) SaturatingAdd(rhs U8) U8

func (U8) SaturatingDiv added in v0.10.0

func (self U8) SaturatingDiv(rhs U8) U8

func (U8) SaturatingMul added in v0.10.0

func (self U8) SaturatingMul(rhs U8) U8

func (U8) SaturatingSub added in v0.9.0

func (self U8) SaturatingSub(rhs U8) U8

func (U8) Shl added in v0.11.0

func (lhs U8) Shl(rhs U8) U8

func (U8) Shr added in v0.11.0

func (lhs U8) Shr(rhs U8) U8

func (U8) Sub added in v0.6.0

func (self U8) Sub(rhs U8) U8

func (*U8) SubAssign added in v0.6.0

func (self *U8) SubAssign(rhs U8)

func (U8) ToString added in v0.6.0

func (self U8) ToString() String

func (U8) WrappingAdd added in v0.8.0

func (self U8) WrappingAdd(rhs U8) U8

func (U8) WrappingDiv added in v0.9.0

func (self U8) WrappingDiv(rhs U8) U8

func (U8) WrappingMul added in v0.9.0

func (self U8) WrappingMul(rhs U8) U8

func (U8) WrappingSub added in v0.8.0

func (self U8) WrappingSub(rhs U8) U8

type USize added in v0.6.0

type USize uint

func (USize) AbsDiff added in v0.10.0

func (self USize) AbsDiff(other USize) USize

Computes the absolute difference between self and other. This function always returns the correct answer without overflow or panics by returning an unsigned integer.

func (USize) Add added in v0.6.0

func (self USize) Add(rhs USize) USize

func (*USize) AddAssign added in v0.6.0

func (self *USize) AddAssign(rhs USize)

func (USize) AsRef added in v0.7.3

func (self USize) AsRef() *USize

func (USize) CheckedAdd added in v0.9.0

func (self USize) CheckedAdd(rhs USize) Option[USize]

func (USize) CheckedDiv added in v0.9.0

func (self USize) CheckedDiv(rhs USize) Option[USize]

func (USize) CheckedMul added in v0.9.0

func (self USize) CheckedMul(rhs USize) Option[USize]

func (USize) CheckedRem added in v0.9.0

func (self USize) CheckedRem(rhs USize) Option[USize]

func (USize) CheckedSub added in v0.9.0

func (self USize) CheckedSub(rhs USize) Option[USize]

func (USize) Clone added in v0.6.0

func (self USize) Clone() USize

func (USize) Cmp added in v0.6.0

func (self USize) Cmp(rhs USize) Ordering

func (USize) Debug added in v0.6.0

func (self USize) Debug() String

func (USize) Display added in v0.6.0

func (self USize) Display() String

func (USize) Div added in v0.6.0

func (self USize) Div(rhs USize) USize

func (*USize) DivAssign added in v0.6.0

func (self *USize) DivAssign(rhs USize)

func (USize) Eq added in v0.6.0

func (self USize) Eq(rhs USize) Bool

func (USize) Mul added in v0.6.0

func (self USize) Mul(rhs USize) USize

func (*USize) MulAssign added in v0.6.0

func (self *USize) MulAssign(rhs USize)

func (USize) Pow added in v0.10.0

func (self USize) Pow(exp U32) USize

Raises self to the power of exp, using exponentiation by squaring.

func (USize) Rem added in v0.9.0

func (self USize) Rem(rhs USize) USize

func (*USize) RemAssign added in v0.9.0

func (self *USize) RemAssign(rhs USize)

func (USize) SaturatingAdd added in v0.10.0

func (self USize) SaturatingAdd(rhs USize) USize

func (USize) SaturatingDiv added in v0.10.0

func (self USize) SaturatingDiv(rhs USize) USize

func (USize) SaturatingMul added in v0.10.0

func (self USize) SaturatingMul(rhs USize) USize

func (USize) SaturatingSub added in v0.9.0

func (self USize) SaturatingSub(rhs USize) USize

func (USize) Shl added in v0.11.0

func (lhs USize) Shl(rhs USize) USize

func (USize) Shr added in v0.11.0

func (lhs USize) Shr(rhs USize) USize

func (USize) Sub added in v0.6.0

func (self USize) Sub(rhs USize) USize

func (*USize) SubAssign added in v0.6.0

func (self *USize) SubAssign(rhs USize)

func (USize) ToString added in v0.6.0

func (self USize) ToString() String

func (USize) WrappingAdd added in v0.8.0

func (self USize) WrappingAdd(rhs USize) USize

func (USize) WrappingDiv added in v0.9.0

func (self USize) WrappingDiv(rhs USize) USize

func (USize) WrappingMul added in v0.9.0

func (self USize) WrappingMul(rhs USize) USize

func (USize) WrappingSub added in v0.8.0

func (self USize) WrappingSub(rhs USize) USize

type Unit added in v0.10.0

type Unit struct{}

type Vec

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

A contiguous growable array type with heap-allocated contents, written Vec<T>. Vectors have O(1) indexing, amortized O(1) push (to the end) and O(1) pop (from the end).

func VecNew

func VecNew[T any]() Vec[T]

Constructs a new, empty Vec<T>. The vector will not allocate until elements are pushed onto it.

func VecWithCapacity

func VecWithCapacity[T any](capacity USize) Vec[T]

Constructs a new, empty Vec<T> with at least the specified capacity.

func VecWithLen

func VecWithLen[T any](len USize) Vec[T]

Constructs a new, empty Vec<T> with at least the specified len.

func (*Vec[T]) Append

func (self *Vec[T]) Append(other *Vec[T])

Moves all the elements of other ISizeo self, leaving other empty.

vec1 := gost.VecNew[gost.I32]()
vec2 := gost.VecNew[gost.I32]()
vec1.Push(1)
vec2.Push(2)
vec1.Append(&vec2)
gost.AssertEq(vec1.Len(), gost.USize(2))

func (Vec[T]) AsRef added in v0.7.3

func (self Vec[T]) AsRef() *Vec[T]

impl AsRef for Vec

func (Vec[T]) AsSlice

func (self Vec[T]) AsSlice() []T

Extracts a slice containing the entire vector.

func (Vec[T]) BinarySearch

func (self Vec[T]) BinarySearch(value T) Option[USize]

Binary searches this slice for a given element. If the slice is not sorted, the returned result is unspecified and meaningless.

vec := gost.VecNew[gost.I32]()
vec.Push(1)
vec.Push(2)
vec.Push(3)
gost.Assert(vec.BinarySearch(2).IsSome())
gost.Assert(vec.BinarySearch(4).IsNone())

func (Vec[T]) BinarySearchBy

func (self Vec[T]) BinarySearchBy(f func(T) Ordering) Option[USize]

Binary searches this slice with a comparator function. The comparator function should return an order code that indicates whether its argument is Less, Equal or Greater the desired target. If the slice is not sorted or if the comparator function does not implement an order consistent with the sort order of the underlying slice, the returned result is unspecified and meaningless.

vec := gost.VecNew[gost.I32]()
vec.Push(1)
vec.Push(2)
vec.Push(3)
gost.Assert(vec.BinarySearchBy(func(e gost.I32) gost.Ordering {
	if e < 2 {
		return gost.OrderingLess
	} else if e > 2 {
		return gost.OrderingGreater
	} else {
		return gost.OrderingEqual
	}
}).IsSome())

func (Vec[T]) Capacity

func (self Vec[T]) Capacity() USize

Returns the total number of elements the vector can hold without reallocating.

vec := gost.VecNew[gost.I32]()
gost.AssertEq(vec.Capacity(), gost.USize(0))

vec.Reserve(10)
gost.AssertEq(vec.Capacity(), gost.USize(10))

func (*Vec[T]) Clear

func (self *Vec[T]) Clear()

Clears the vector, removing all values.

vec := gost.VecNew[gost.I32]()
vec.Push(1)
vec.Push(2)
vec.Clear()
gost.AssertEq(vec.Len(), gost.USize(0))

func (Vec[T]) Clone added in v0.7.3

func (self Vec[T]) Clone() Vec[T]

impl Clone for Vec

func (Vec[T]) Contains

func (self Vec[T]) Contains(value T) Bool

Returns true if the slice contains an element with the given value. This operation is O(n). Note that if you have a sorted slice, binary_search may be faster.

vec := gost.VecNew[gost.I32]()
vec.Push(1)
vec.Push(2)
vec.Push(3)
gost.Assert(vec.Contains(2))
gost.Assert(!vec.Contains(4))

func (Vec[T]) Debug

func (self Vec[T]) Debug() String

impl Debug for Vec

func (*Vec[T]) Dedup

func (self *Vec[T]) Dedup()

Removes consecutive repeated elements in the vector according to the PartialEq trait implementation. If the vector is sorted, this removes all duplicates.

vec := gost.VecNew[gost.I32]()
vec.Push(1)
vec.Push(2)
vec.Push(2)
vec.Push(3)
vec.Dedup()
gost.AssertEq(vec.Len(), gost.USize(3))

func (*Vec[T]) DedupByKey

func (self *Vec[T]) DedupByKey(key func(T) any)

Removes all but the first of consecutive elements in the vector that resolve to the same key. If the vector is sorted, this removes all duplicates.

vec := gost.VecNew[gost.I32]()
vec.Push(1)
vec.Push(2)
vec.Push(2)
vec.Push(3)
vec.DedupByKey(func(e gost.I32) gost.I32 {
	return e
}
gost.AssertEq(vec.Len(), gost.USize(3))

func (Vec[T]) Display

func (self Vec[T]) Display() String

impl Display for Vec

func (Vec[T]) Eq added in v0.7.3

func (self Vec[T]) Eq(other Vec[T]) Bool

impl Eq for Vec

func (*Vec[T]) Fill

func (self *Vec[T]) Fill(value T)

Fills self with elements by cloning value.

vec := gost.VecWithLen[gost.I32](gost.USize(5))
vec.Fill(gost.I32(1))
gost.AssertEq(vec.GetUnchecked(0), gost.I32(1))

func (*Vec[T]) FillWith

func (self *Vec[T]) FillWith(f func() T)

Fills self with elements returned by calling a closure repeatedly.

vec := gost.VecWithLen[gost.I32](gost.USize(5))
vec.FillWith(func() gost.I32 {
	return 1
})
gost.AssertEq(vec.GetUnchecked(0), gost.I32(1))

func (Vec[T]) Get

func (self Vec[T]) Get(index USize) Option[T]

Returns a reference to an element or subslice depending on the type of index. If given a position, returns a reference to the element at that position or None if out of bounds. If given a range, returns the subslice corresponding to that range, or None if out of bounds.

vec := gost.VecNew[gost.I32]()
vec.Push(1)
vec.Push(2)
vec.Push(3)
gost.AssertEq(vec.Get(0).Unwrap(), gost.I32(1))
gost.AssertEq(vec.Get(1).Unwrap(), gost.I32(2))

func (Vec[T]) GetUnchecked

func (self Vec[T]) GetUnchecked(index USize) T

Returns a reference to an element or subslice, without doing bounds checking. For a safe alternative see get.

vec := gost.VecNew[gost.I32]()
vec.Push(1)
vec.Push(2)
vec.Push(3)
gost.AssertEq(vec.GetUnchecked(0), gost.I32(1))

func (*Vec[T]) Insert

func (self *Vec[T]) Insert(index USize, value T)

Inserts an element at position index within the vector, shifting all elements after it to the right.

vec := gost.VecNew[gost.I32]()
vec.Push(1)
vec.Push(2)
vec.Insert(1, 3)
gost.AssertEq(vec.GetUnchecked(0), gost.I32(1))
gost.AssertEq(vec.GetUnchecked(1), gost.I32(3))

func (Vec[T]) IntoIter

func (self Vec[T]) IntoIter() Iterator[T]

into_iter

func (Vec[T]) IsEmpty

func (self Vec[T]) IsEmpty() Bool

Returns true if the vector contains no elements.

vec := gost.VecNew[gost.I32]()
gost.Assert(vec.IsEmpty())

vec.Push(1)
gost.Assert(!vec.IsEmpty())

func (Vec[T]) Len

func (self Vec[T]) Len() USize

Returns the number of elements in the vector, also referred to as its ‘length’.

vec := gost.VecNew[gost.I32]()
gost.AssertEq(vec.Len(), gost.USize(0))

vec.Push(1)
gost.AssertEq(vec.Len(), gost.USize(1))

func (*Vec[T]) Pop

func (self *Vec[T]) Pop() Option[T]

Removes the last element from a vector and returns it, or None if it is empty.

vec := gost.VecNew[gost.I32]()
gost.AssertEq(vec.Pop().IsNone(), true)

vec.Push(1)
gost.AssertEq(vec.Pop().IsSome(), true)

func (*Vec[T]) Push

func (self *Vec[T]) Push(value T)

Appends an element to the back of a collection.

vec := gost.VecNew[gost.I32]()
gost.AssertEq(vec.Len(), gost.USize(0))

vec.Push(1)
gost.AssertEq(vec.Len(), gost.USize(1))

func (*Vec[T]) Reserve

func (self *Vec[T]) Reserve(additional USize)

Reserves capacity for at least additional more elements to be inserted in the given Vec<T>. The collection may reserve more space to speculatively avoid frequent reallocations. After calling reserve, capacity will be greater than or equal to self.len() + additional. Does nothing if capacity is already sufficient.

vec := gost.VecNew[gost.I32]()
gost.AssertEq(vec.Capacity(), gost.USize(0))

vec.Reserve(10)
gost.AssertEq(vec.Capacity(), gost.USize(10))

func (*Vec[T]) Retain

func (self *Vec[T]) Retain(predicate func(T) Bool)

Retains only the elements specified by the predicate. In other words, remove all elements e such that f(e) returns false. This method operates in place and preserves the order of the retained elements.

vec := gost.VecNew[gost.I32]()
vec.Push(1)
vec.Push(2)
vec.Push(3)
vec.Retain(func(e gost.I32) gost.Bool {
	return e == 2
})
gost.AssertEq(vec.Len(), gost.USize(1))

func (*Vec[T]) Reverse

func (self *Vec[T]) Reverse()

Reverses the order of elements in the slice, in place.

vec := gost.VecNew[gost.I32]()
vec.Push(1)
vec.Push(2)
vec.Push(3)
vec.Reverse()
gost.AssertEq(vec.GetUnchecked(0), gost.I32(3))

func (*Vec[T]) Set added in v0.7.0

func (self *Vec[T]) Set(index USize, value T) Option[T]

Set value

vec := gost.VecNew[gost.I32]()
vec.Push(1)
vec.Push(2)
vec.Push(3)
vec.Set(0, 4)
gost.AssertEq(vec.GetUnchecked(0), gost.I32(4))

func (*Vec[T]) SetUnchecked added in v0.7.0

func (self *Vec[T]) SetUnchecked(index USize, value T)

Set unchecked

vec := gost.VecNew[gost.I32]()
vec.Push(1)
vec.Push(2)
vec.Push(3)
vec.SetUnchecked(0, 4)
gost.AssertEq(vec.GetUnchecked(0), gost.I32(4))

func (*Vec[T]) Sort

func (self *Vec[T]) Sort()

Sorts the slice. This sort is stable (i.e., does not reorder equal elements) and O(n * log(n)) worst-case. When applicable, unstable sorting is preferred because it is generally faster than stable sorting and it doesn’t allocate auxiliary memory. See sort_unstable.

vec := gost.VecNew[gost.I32]()
vec.Push(3)
vec.Push(2)
vec.Push(1)
vec.Sort()
gost.AssertEq(vec.GetUnchecked(0), gost.I32(1))

func (*Vec[T]) SortBy

func (self *Vec[T]) SortBy(compare func(T, T) Ordering)

Sorts the slice with a comparator function. This sort is stable (i.e., does not reorder equal elements) and O(n * log(n)) worst-case. The comparator function must define a total ordering for the elements in the slice. If the ordering is not total, the order of the elements is unspecified. An order is a total order if it is (for all a, b and c): - total and antisymmetric: exactly one of a < b, a == b or a > b is true, and - transitive, a < b and b < c implies a < c. The same must hold for both == and >.

vec := gost.VecNew[gost.I32]()
vec.Push(3)
vec.Push(2)
vec.Push(1)
vec.SortBy(func(lhs, rhs gost.I32) gost.Ordering {
	if lhs < rhs {
		return gost.OrderingLess
	} else if lhs > rhs {
		return gost.OrderingGreater
	} else {
		return gost.OrderingEqual
	}
})
gost.AssertEq(vec.GetUnchecked(0), gost.I32(1))

func (*Vec[T]) SortUnstable

func (self *Vec[T]) SortUnstable()

Sorts the slice, but might not preserve the order of equal elements. This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not allocate), and O(n * log(n)) worst-case.

vec := gost.VecNew[gost.I32]()
vec.Push(3)
vec.Push(2)
vec.Push(1)
vec.SortUnstable()
gost.AssertEq(vec.GetUnchecked(0), gost.I32(1))

func (*Vec[T]) SortUnstableBy

func (self *Vec[T]) SortUnstableBy(compare func(T, T) Ordering)

Sorts the slice with a comparator function, but might not preserve the order of equal elements. This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not allocate), and O(n * log(n)) worst-case. The comparator function must define a total ordering for the elements in the slice. If the ordering is not total, the order of the elements is unspecified. An order is a total order if it is (for all a, b and c): - total and antisymmetric: exactly one of a < b, a == b or a > b is true, and - transitive, a < b and b < c implies a < c. The same must hold for both == and >.

vec := gost.VecNew[gost.I32]()
vec.Push(3)
vec.Push(2)
vec.Push(1)
vec.SortUnstableBy(func(lhs, rhs gost.I32) gost.Ordering {
	if lhs < rhs {
		return gost.OrderingLess
	} else if lhs > rhs {
		return gost.OrderingGreater
	} else {
		return gost.OrderingEqual
	}
})
gost.AssertEq(vec.GetUnchecked(0), gost.I32(1))

func (*Vec[T]) Swap

func (self *Vec[T]) Swap(a, b USize)

Swaps two elements in the slice. If a equals to b, it’s guaranteed that elements won’t change value.

vec := gost.VecNew[gost.I32]()
vec.Push(1)
vec.Push(2)
vec.Push(3)
vec.Swap(0, 2)
gost.AssertEq(vec.GetUnchecked(0), gost.I32(3))
gost.AssertEq(vec.GetUnchecked(2), gost.I32(1))

type VecDeque added in v0.8.0

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

A double-ended queue implemented with a growable ring buffer.

func VecDequeNew added in v0.8.0

func VecDequeNew[T any]() VecDeque[T]

Creates an empty VecDeque.

func VecDequeWithCapacity added in v0.8.0

func VecDequeWithCapacity[T any](capacity USize) VecDeque[T]

Creates an empty VecDeque with at least the specified capacity.

func VecDequeWithLen added in v0.9.0

func VecDequeWithLen[T any](len USize) VecDeque[T]

Constructs a new, empty Vec<T> with at least the specified capacity.

func (*VecDeque[T]) Append added in v0.9.0

func (self *VecDeque[T]) Append(other *VecDeque[T])

Moves all the elements of other ISizeo self, leaving other empty.

	deque1 := gost.VecDequeNew[gost.I32]()
	deque2 := gost.VecDequeNew[gost.I32]()
	deque1.PushBack(1)
	deque2.PushBack(2)
	deque1.Append(&deque2)
	gost.AssertEq(deque1.Len(), gost.USize(2))
 gost.AssertEq(deque2.Len(), gost.USize(0))

func (VecDeque[T]) AsRef added in v0.8.0

func (self VecDeque[T]) AsRef() *VecDeque[T]

impl AsRef for VecDeque

func (VecDeque[T]) AsSlice added in v0.9.0

func (self VecDeque[T]) AsSlice() []T

Extracts a slice containing the entire vecdeque.

func (VecDeque[T]) Back added in v0.8.0

func (self VecDeque[T]) Back() Option[T]

Provides a reference to the back element, or None if the deque is empty.

deque := gost.VecDequeNew[gost.I32]()
deque.PushBack(gost.I32(3))
deque.PushBack(gost.I32(4))
gost.AssertEqual(deque.Back(), gost.Some[gost.I32](gost.I32(4)))

func (VecDeque[T]) BinarySearch added in v0.9.0

func (self VecDeque[T]) BinarySearch(value T) Option[USize]

Binary searches this slice for a given element. If the slice is not sorted, the returned result is unspecified and meaningless.

deque := gost.VecDequeNew[gost.I32]()
deque.Push(1)
deque.Push(2)
deque.Push(3)
gost.Assert(deque.BinarySearch(2).IsSome())
gost.Assert(deque.BinarySearch(4).IsNone())

func (VecDeque[T]) BinarySearchBy added in v0.9.0

func (self VecDeque[T]) BinarySearchBy(f func(T) Ordering) Option[USize]

Binary searches this slice with a comparator function. The comparator function should return an order code that indicates whether its argument is Less, Equal or Greater the desired target. If the slice is not sorted or if the comparator function does not implement an order consistent with the sort order of the underlying slice, the returned result is unspecified and meaningless.

deque := gost.VecDequeNew[gost.I32]()
deque.Push(1)
deque.Push(2)
deque.Push(3)
gost.Assert(deque.BinarySearchBy(func(e gost.I32) gost.Ordering {
	if e < 2 {
		return gost.OrderingLess
	} else if e > 2 {
		return gost.OrderingGreater
	} else {
		return gost.OrderingEqual
	}
}).IsSome())

func (VecDeque[T]) Capacity added in v0.8.0

func (self VecDeque[T]) Capacity() USize

Returns the number of elements the deque can hold without reallocating.

deque := gost.VecDequeNew[gost.I32]()
deque.PushBack(gost.I32(3))
deque.PushBack(gost.I32(4))
deque.Reserve(gost.USize(8))
gost.AssertEqual(deque.Capacity(), gost.USize(8))
gost.AssertEqual(deque.Len(), gost.USize(2))

func (*VecDeque[T]) Clear added in v0.8.0

func (self *VecDeque[T]) Clear()

Clears the deque, removing all values.

deque := gost.VecDequeNew[gost.I32]()
deque.PushBack(gost.I32(3))
deque.PushBack(gost.I32(4))
deque.Clear()
gost.AssertEqual(deque.Len(), gost.USize(0))

func (VecDeque[T]) Clone added in v0.8.0

func (self VecDeque[T]) Clone() *VecDeque[T]

impl Clone for VecDeque

func (VecDeque[T]) Contains added in v0.8.0

func (self VecDeque[T]) Contains(value T) Bool

Require `impl Eq[T] for T` Returns true if the deque contains an element equal to the given value. This operation is O(n). Note that if you have a sorted VecDeque, binary_search may be faster.

deque := gost.VecDequeNew[gost.I32]()
deque.PushBack(gost.I32(3))
deque.PushBack(gost.I32(4))
gost.AssertEqual(deque.Contains(gost.I32(3)), gost.Bool(true))
gost.AssertEqual(deque.Contains(gost.I32(4)), gost.Bool(true))
gost.AssertEqual(deque.Contains(gost.I32(5)), gost.Bool(false))

func (VecDeque[T]) Debug added in v0.8.0

func (self VecDeque[T]) Debug() String

impl Debug for VecDeque

func (*VecDeque[T]) Dedup added in v0.9.0

func (self *VecDeque[T]) Dedup(key func(T) any)

Removes consecutive repeated elements in the vector according to the PartialEq trait implementation. If the vecdeque is sorted, this removes all duplicates.

deque := gost.VecDequeNew[gost.I32]()
deque.Push(1)
deque.Push(2)
deque.Push(2)
deque.Push(3)
deque.Dedup()
gost.AssertEq(deque.Len(), gost.USize(3))

func (VecDeque[T]) Display added in v0.8.0

func (self VecDeque[T]) Display() String

impl Display for VecDeque

func (VecDeque[T]) Eq added in v0.8.0

func (self VecDeque[T]) Eq(other VecDeque[T]) Bool

impl Eq for Vec

func (*VecDeque[T]) Fill added in v0.9.0

func (self *VecDeque[T]) Fill(value T)

Fills self with elements by cloning value.

deque := gost.VecDequeWithLen[gost.I32](gost.USize(5))
deque.Fill(gost.I32(1))
gost.AssertEq(deque.GetUnchecked(0), gost.I32(1))
gost.AssertEq(deque.GetUnchecked(1), gost.I32(1))

func (*VecDeque[T]) FillWith added in v0.9.0

func (self *VecDeque[T]) FillWith(f func() T)

Fills self with elements returned by calling a closure repeatedly.

deque := gost.VecDequeWithLen[gost.I32](gost.USize(5))
deque.FillWith(func() gost.I32 {
	return 1
})
gost.AssertEq(deque.GetUnchecked(0), gost.I32(1))
gost.AssertEq(deque.GetUnchecked(1), gost.I32(1))

func (VecDeque[T]) Front added in v0.8.0

func (self VecDeque[T]) Front() Option[T]

Provides a reference to the front element, or None if the deque is empty.

deque := gost.VecDequeNew[gost.I32]()
deque.PushBack(gost.I32(3))
deque.PushBack(gost.I32(4))
gost.AssertEqual(deque.Front(), gost.Some[gost.I32](gost.I32(3)))

func (VecDeque[T]) Get added in v0.8.0

func (self VecDeque[T]) Get(index USize) Option[T]

Provides a reference to the element at the given index. Element at index 0 is the front of the queue.

deque := gost.VecDequeNew[gost.I32]()
deque.PushBack(gost.I32(3))
deque.PushBack(gost.I32(4))
gost.AssertEqual(deque.Get(gost.USize(0)), gost.Some[gost.I32](gost.I32(3)))

func (VecDeque[T]) GetUnchecked added in v0.9.0

func (self VecDeque[T]) GetUnchecked(index USize) T

Returns a reference to an element or subslice, without doing bounds checking. For a safe alternative see get.

	deque := gost.VecDequeNew[gost.I32]()
	deque.PushBack(gost.I32(3))
	deque.PushBack(gost.I32(4))
 gost.AssertEqual(deque.GetUnchecked(gost.USize(0)), gost.I32(3))

func (VecDeque[T]) IntoIter added in v0.8.0

func (self VecDeque[T]) IntoIter() Iterator[T]

into_iter

func (VecDeque[T]) IsEmpty added in v0.8.0

func (self VecDeque[T]) IsEmpty() Bool

Returns true if the deque is empty.

deque := gost.VecDequeNew[gost.I32]()
deque.PushBack(gost.I32(3))
deque.PushBack(gost.I32(4))
gost.AssertEqual(deque.IsEmpty(), gost.Bool(false))

func (VecDeque[T]) Len added in v0.8.0

func (self VecDeque[T]) Len() USize

Returns the number of elements in the vecdeque, also referred to as its ‘length’.

deque := gost.VecDequeNew[gost.I32]()
deque.PushBack(gost.I32(3))
deque.PushBack(gost.I32(4))
gost.AssertEqual(deque.Len(), gost.USize(2))

func (*VecDeque[T]) PopBack added in v0.8.0

func (self *VecDeque[T]) PopBack() Option[T]

Removes the last element from the deque and returns it, or `None` if it is empty.

deque := gost.VecDequeNew[gost.I32]()
deque.PushBack(gost.I32(3))
deque.PushBack(gost.I32(4))
gost.AssertEqual(deque.PopBack(), gost.Some[gost.I32](gost.I32(4)))
gost.AssertEqual(deque.PopBack(), gost.Some[gost.I32](gost.I32(3)))
gost.AssertEqual(deque.PopBack(), gost.None[gost.I32]())

func (*VecDeque[T]) PopFront added in v0.8.0

func (self *VecDeque[T]) PopFront() Option[T]

Removes the first element and returns it, or `None` if the deque is empty.

deque := gost.VecDequeNew[gost.I32]()
deque.PushBack(gost.I32(3))
deque.PushBack(gost.I32(4))
gost.AssertEqual(deque.PopFront(), gost.Some[gost.I32](gost.I32(3)))
gost.AssertEqual(deque.PopFront(), gost.Some[gost.I32](gost.I32(4)))
gost.AssertEqual(deque.PopFront(), gost.None[gost.I32]())

func (*VecDeque[T]) PushBack added in v0.8.0

func (self *VecDeque[T]) PushBack(value T)

Appends an element to the back of the deque.

deque := gost.VecDequeNew[gost.I32]()
deque.PushBack(gost.I32(3))
deque.PushBack(gost.I32(4))
gost.AssertEqual(deque.Len(), gost.USize(2))

func (*VecDeque[T]) PushFront added in v0.8.0

func (self *VecDeque[T]) PushFront(value T)

Prepends an element to the deque.

deque := gost.VecDequeNew[gost.I32]()
deque.PushFront(gost.I32(3))
deque.PushFront(gost.I32(4))
gost.AssertEqual(deque.Len(), gost.USize(2))

func (*VecDeque[T]) Reserve added in v0.8.0

func (self *VecDeque[T]) Reserve(additional USize)

Reserves capacity for at least additional more elements to be inserted in the given deque. The collection may reserve more space to speculatively avoid frequent reallocations.

deque := gost.VecDequeNew[gost.I32]()
deque.PushBack(gost.I32(3))
deque.PushBack(gost.I32(4))
deque.Reserve(gost.USize(8))
gost.AssertEqual(deque.Capacity(), gost.USize(8))

func (*VecDeque[T]) Retain added in v0.9.0

func (self *VecDeque[T]) Retain(f func(T) Bool)

Retains only the elements specified by the predicate. In other words, remove all elements e such that f(e) returns false. This method operates in place and preserves the order of the retained elements.

deque := gost.VecDequeNew[gost.I32]()
deque.Push(1)
deque.Push(2)
deque.Push(3)
deque.Retain(func(e gost.I32) gost.Bool {
	return e == 2
})

func (*VecDeque[T]) Set added in v0.9.0

func (self *VecDeque[T]) Set(index USize, value T) Option[T]

Set value at index.

deque := gost.VecDequeNew[gost.I32]()
deque.PushBack(gost.I32(3))
deque.Set(gost.USize(0), gost.I32(4))
gost.AssertEqual(deque.Get(gost.USize(0)), gost.Some[gost.I32](gost.I32(4)))

func (*VecDeque[T]) SetUnchecked added in v0.9.0

func (self *VecDeque[T]) SetUnchecked(index USize, value T)

Set value at index, without doing bounds checking.

deque := gost.VecDequeNew[gost.I32]()
deque.PushBack(gost.I32(3))
deque.SetUnchecked(gost.USize(0), gost.I32(4))
gost.AssertEqual(deque.Get(gost.USize(0)), gost.Some[gost.I32](gost.I32(4)))

func (*VecDeque[T]) Sort added in v0.9.0

func (self *VecDeque[T]) Sort()

Sorts the slice. This sort is stable (i.e., does not reorder equal elements) and O(n * log(n)) worst-case. When applicable, unstable sorting is preferred because it is generally faster than stable sorting and it doesn’t allocate auxiliary memory. See sort_unstable.

deque := gost.VecDequeNew[gost.I32]()
deque.Push(3)
deque.Push(2)
deque.Push(1)
deque.Sort()
gost.AssertEq(deque.GetUnchecked(0), gost.I32(1))
gost.AssertEq(deque.GetUnchecked(1), gost.I32(2))
gost.AssertEq(deque.GetUnchecked(2), gost.I32(3))

func (*VecDeque[T]) SortBy added in v0.9.0

func (self *VecDeque[T]) SortBy(f func(T, T) Ordering)

Sorts the slice with a comparator function. This sort is stable (i.e., does not reorder equal elements) and O(n * log(n)) worst-case. The comparator function must define a total ordering for the elements in the slice. If the ordering is not total, the order of the elements is unspecified. An order is a total order if it is (for all a, b and c): - total and antisymmetric: exactly one of a < b, a == b or a > b is true, and - transitive, a < b and b < c implies a < c. The same must hold for both == and >.

deque := gost.VecDequeNew[gost.I32]()
deque.Push(3)
deque.Push(2)
deque.Push(1)
deque.SortBy(func(lhs, rhs gost.I32) gost.Ordering {
	if lhs < rhs {
		return gost.OrderingLess
	} else if lhs > rhs {
		return gost.OrderingGreater
	} else {
		return gost.OrderingEqual
	}
})
gost.AssertEq(deque.GetUnchecked(0), gost.I32(1))

func (*VecDeque[T]) SortUnstable added in v0.9.0

func (self *VecDeque[T]) SortUnstable()

Sorts the slice, but might not preserve the order of equal elements. This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not allocate), and O(n * log(n)) worst-case.

deque := gost.VecDequeNew[gost.I32]()
deque.Push(3)
deque.Push(2)
deque.Push(1)
deque.SortUnstable()
gost.AssertEq(deque.GetUnchecked(0), gost.I32(1))

func (*VecDeque[T]) SortUnstableBy added in v0.9.0

func (self *VecDeque[T]) SortUnstableBy(f func(T, T) Ordering)

Sorts the slice with a comparator function, but might not preserve the order of equal elements. This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not allocate), and O(n * log(n)) worst-case. The comparator function must define a total ordering for the elements in the slice. If the ordering is not total, the order of the elements is unspecified. An order is a total order if it is (for all a, b and c): - total and antisymmetric: exactly one of a < b, a == b or a > b is true, and - transitive, a < b and b < c implies a < c. The same must hold for both == and >.

deque := gost.VecDequeNew[gost.I32]()
deque.Push(3)
deque.Push(2)
deque.Push(1)
deque.SortUnstableBy(func(lhs, rhs gost.I32) gost.Ordering {
	if lhs < rhs {
		return gost.OrderingLess
	} else if lhs > rhs {
		return gost.OrderingGreater
	} else {
		return gost.OrderingEqual
	}
})
gost.AssertEq(deque.GetUnchecked(0), gost.I32(1))

func (*VecDeque[T]) Swap added in v0.9.0

func (self *VecDeque[T]) Swap(a USize, b USize)

Swaps two elements in the slice. if a equals to b, it’s guaranteed that elements won’t change value.

deque := gost.VecDequeNew[gost.I32]()
deque.Push(1)
deque.Push(2)
deque.Push(3)
deque.Swap(0, 2)
gost.AssertEq(deque.GetUnchecked(0), gost.I32(3))
gost.AssertEq(deque.GetUnchecked(2), gost.I32(1))

type VecDequeIter added in v0.8.0

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

iterator for VecDeque

func (*VecDequeIter[T]) CollectToLinkedList added in v0.8.0

func (self *VecDequeIter[T]) CollectToLinkedList() LinkedList[T]

collect to LinkedList

func (*VecDequeIter[T]) CollectToVec added in v0.8.0

func (self *VecDequeIter[T]) CollectToVec() Vec[T]

collect to Vec

func (*VecDequeIter[T]) Filter added in v0.8.0

func (self *VecDequeIter[T]) Filter(f func(T) Bool) Iterator[T]

filter

func (*VecDequeIter[T]) Fold added in v0.8.0

func (self *VecDequeIter[T]) Fold(initial T, f func(T, T) T) T

fold

func (*VecDequeIter[T]) Map added in v0.8.0

func (self *VecDequeIter[T]) Map(f func(T) T) Iterator[T]

map

func (*VecDequeIter[T]) Next added in v0.8.0

func (self *VecDequeIter[T]) Next() Option[T]

next

func (*VecDequeIter[T]) Rev added in v0.8.0

func (self *VecDequeIter[T]) Rev() Iterator[T]

rev

type VecIter

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

iterator for Vec

func (VecIter[T]) CollectToLinkedList added in v0.6.0

func (self VecIter[T]) CollectToLinkedList() LinkedList[T]

collect to LinkedList

func (VecIter[T]) CollectToVec

func (self VecIter[T]) CollectToVec() Vec[T]

collect to Vec

func (VecIter[T]) Filter

func (self VecIter[T]) Filter(f func(T) Bool) Iterator[T]

filter

func (VecIter[T]) Fold

func (self VecIter[T]) Fold(init T, f func(T, T) T) T

fold

func (VecIter[T]) Map

func (self VecIter[T]) Map(f func(T) T) Iterator[T]

map

func (*VecIter[T]) Next

func (self *VecIter[T]) Next() Option[T]

next

func (VecIter[T]) Rev

func (self VecIter[T]) Rev() Iterator[T]

rev

type Void added in v0.10.0

type Void struct{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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