Documentation
¶
Index ¶
- func IsProperSubset[T comparable](s1 Set[T], s2 Set[T]) bool
- func IsSubset[T comparable](s1 Set[T], s2 Set[T]) bool
- type Backer
- type BinaryTree
- type Collection
- type Deleter
- type Deque
- type Eacher
- type Fronter
- type Haser
- type Heap
- type ImplicitTreap
- func (it *ImplicitTreap[T]) Append(item T)
- func (it *ImplicitTreap[T]) At(key int) T
- func (it *ImplicitTreap[T]) DeleteAt(pos int)
- func (l *ImplicitTreap[T]) Merge(r *ImplicitTreap[T])
- func (it *ImplicitTreap[T]) Split(key int) (l *ImplicitTreap[T], r *ImplicitTreap[T])
- func (n *ImplicitTreap[T]) String() string
- type ImplicitTreapNode
- func (n *ImplicitTreapNode[T]) At(key int) T
- func (p *ImplicitTreapNode[T]) DeleteAt(pos int) *ImplicitTreapNode[T]
- func (l *ImplicitTreapNode[T]) Merge(r *ImplicitTreapNode[T]) (p *ImplicitTreapNode[T])
- func (p *ImplicitTreapNode[T]) Split(key, offset int) (l *ImplicitTreapNode[T], r *ImplicitTreapNode[T])
- func (n *ImplicitTreapNode[T]) String() string
- type Inserter
- type Set
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsProperSubset ¶
func IsProperSubset[T comparable](s1 Set[T], s2 Set[T]) bool
Example ¶
package main
import (
"fmt"
"github.com/go-generics/collections"
)
func main() {
a := collections.NewSet(1.2)
b := collections.NewSet(1.2, 3.4)
fmt.Println(!collections.IsProperSubset(a, a))
fmt.Println(collections.IsProperSubset(a, b))
fmt.Println(!collections.IsProperSubset(b, a))
}
Output: true true true
func IsSubset ¶
func IsSubset[T comparable](s1 Set[T], s2 Set[T]) bool
Example ¶
package main
import (
"fmt"
"github.com/go-generics/collections"
)
func main() {
a := collections.NewSet(1.2)
b := collections.NewSet(1.2, 3.4)
fmt.Println(collections.IsSubset(a, a))
fmt.Println(collections.IsSubset(a, b))
fmt.Println(!collections.IsSubset(b, a))
}
Output: true true true
Types ¶
type BinaryTree ¶
type BinaryTree[T ordered] interface {
fmt.Stringer
Collection
Deleter[T]
Eacher[T]
Inserter[T]
ToDeque() Deque[T]
Levels()
}
func NewBinaryTree ¶
func NewBinaryTree[T ordered]() BinaryTree[T]
type Collection ¶
type Collection interface {
Len() int
}
type Haser ¶
type Haser[T comparable] interface { Has(item T) bool }
type Heap ¶
type Heap[T ordered] interface {
fmt.Stringer
Collection
Fronter[T]
}
Example ¶
package main
import (
"fmt"
"github.com/go-generics/collections"
)
func main() {
h := collections.NewHeap(2, 1, 5)
h.PushFront(3)
fmt.Printf("minimum: %d\n", h.Front())
for h.Len() > 0 {
fmt.Print(h.PopFront(), " ")
}
}
Output: minimum: 1 1 2 3 5
type ImplicitTreap ¶
type ImplicitTreap[T comparable] struct { Root *ImplicitTreapNode[T] }
Example ¶
package main
import (
"fmt"
"github.com/go-generics/collections"
)
func main() {
t := collections.NewImplicitTreap(3, 1, 4, 1, 5, 4, 9, 2)
fmt.Println(t)
}
Output: 3 1 4 1 5 4 9 2
func NewImplicitTreap ¶
func NewImplicitTreap[T comparable](values ...T) *ImplicitTreap[T]
func (*ImplicitTreap[T]) Append ¶
func (it *ImplicitTreap[T]) Append(item T)
func (*ImplicitTreap[T]) At ¶
func (it *ImplicitTreap[T]) At(key int) T
func (*ImplicitTreap[T]) DeleteAt ¶
func (it *ImplicitTreap[T]) DeleteAt(pos int)
func (*ImplicitTreap[T]) Merge ¶
func (l *ImplicitTreap[T]) Merge(r *ImplicitTreap[T])
func (*ImplicitTreap[T]) Split ¶
func (it *ImplicitTreap[T]) Split(key int) (l *ImplicitTreap[T], r *ImplicitTreap[T])
func (*ImplicitTreap[T]) String ¶
func (n *ImplicitTreap[T]) String() string
type ImplicitTreapNode ¶
type ImplicitTreapNode[T comparable] struct { Left *ImplicitTreapNode[T] Right *ImplicitTreapNode[T] Value T Size int Priority float64 }
func NewImplicitTreapNode ¶
func NewImplicitTreapNode[T comparable](value T) *ImplicitTreapNode[T]
func NewImplicitTreapRoot ¶
func NewImplicitTreapRoot[T comparable](values ...T) *ImplicitTreapNode[T]
func (*ImplicitTreapNode[T]) At ¶
func (n *ImplicitTreapNode[T]) At(key int) T
func (*ImplicitTreapNode[T]) DeleteAt ¶
func (p *ImplicitTreapNode[T]) DeleteAt(pos int) *ImplicitTreapNode[T]
func (*ImplicitTreapNode[T]) Merge ¶
func (l *ImplicitTreapNode[T]) Merge(r *ImplicitTreapNode[T]) (p *ImplicitTreapNode[T])
func (*ImplicitTreapNode[T]) Split ¶
func (p *ImplicitTreapNode[T]) Split(key, offset int) (l *ImplicitTreapNode[T], r *ImplicitTreapNode[T])
func (*ImplicitTreapNode[T]) String ¶
func (n *ImplicitTreapNode[T]) String() string
type Set ¶
type Set[T comparable] interface { fmt.Stringer Collection Deleter[T] Eacher[T] Inserter[T] Haser[T] }
func Difference ¶
func Difference[T comparable](s1 Set[T], s2 Set[T]) Set[T]
Example ¶
package main
import (
"fmt"
"github.com/go-generics/collections"
)
func main() {
ab := collections.NewSet("A", "B")
bc := collections.NewSet("B", "C")
fmt.Println(collections.Difference(ab, bc))
fmt.Println(collections.Difference(bc, ab))
}
Output: [A] [C]
func Intersection ¶
func Intersection[T comparable](s1 Set[T], s2 Set[T]) Set[T]
Example ¶
package main
import (
"fmt"
"github.com/go-generics/collections"
)
func main() {
ab := collections.NewSet("A", "B")
bc := collections.NewSet("B", "C")
intersection := collections.Intersection(ab, bc)
fmt.Println(intersection.String())
// Output
// [B]
}
func NewSet ¶
func NewSet[T comparable](items ...T) Set[T]
Example ¶
package main
import (
"fmt"
"github.com/go-generics/collections"
)
func main() {
set := collections.NewSet(0, 1)
fmt.Println(set.Has(0))
fmt.Println(set.Has(1))
fmt.Println(!set.Has(2))
}
Output: true true true
func Union ¶
func Union[T comparable](s1 Set[T], s2 Set[T]) Set[T]
Example ¶
package main
import (
"fmt"
"github.com/go-generics/collections"
)
func main() {
ab := collections.NewSet("A", "B")
bc := collections.NewSet("B", "C")
union := collections.Union(ab, bc)
fmt.Println(union.Has("A"))
fmt.Println(union.Has("B"))
fmt.Println(union.Has("C"))
fmt.Println(union.Len())
}
Output: true true true 3
Click to show internal directories.
Click to hide internal directories.