data-structures: github.com/timtadh/data-structures/set Index | Examples | Files

package set

import "github.com/timtadh/data-structures/set"

Code:

package main

import (
    "log"
)

import (
    "github.com/timtadh/data-structures/list"
    "github.com/timtadh/data-structures/set"
    "github.com/timtadh/data-structures/types"
)

func makeSet() *set.SortedSet {
    return set.FromSlice([]types.Hashable{types.Int(1), types.Int(-1), types.Int(3)})
}

func serialize(s *set.SortedSet) ([]byte, error) {
    marshal, unmarshal := types.IntMarshals()
    m := set.NewMSortedSet(s, marshal, unmarshal)
    return m.MarshalBinary()
}

func deserialize(bytes []byte) (*set.SortedSet, error) {
    marshal, unmarshal := types.IntMarshals()
    m := &set.MSortedSet{MSorted: list.MSorted{MList: list.MList{MarshalItem: marshal, UnmarshalItem: unmarshal}}}
    err := m.UnmarshalBinary(bytes)
    if err != nil {
        return nil, err
    }
    return m.SortedSet(), nil
}

func main() {
    a := makeSet()
    b := makeSet()
    if !a.Equals(b) {
        log.Panic("a was not equal to b")
    }
    bytes, err := serialize(a)
    if err != nil {
        log.Panic(err)
    }
    log.Println(bytes)
    c, err := deserialize(bytes)
    if err != nil {
        log.Panic(err)
    }
    if !c.Equals(b) {
        log.Panic("c was not equal to b")
    }
    log.Println("success")
}

Index

Examples

Package Files

mapset.go ops.go setmap.go sortedset.go

func Intersect Uses

func Intersect(a, b types.Set) (types.Set, error)

func ProperSubset Uses

func ProperSubset(a, b types.Set) bool

func ProperSuperset Uses

func ProperSuperset(a, b types.Set) bool

func Subset Uses

func Subset(a, b types.Set) bool

func Subtract Uses

func Subtract(a, b types.Set) (types.Set, error)

Unions s with o and returns a new Sorted Set

func Superset Uses

func Superset(a, b types.Set) bool

func Union Uses

func Union(a, b types.Set) (types.Set, error)

type MSortedSet Uses

type MSortedSet struct {
    list.MSorted
}

func NewMSortedSet Uses

func NewMSortedSet(s *SortedSet, marshal types.ItemMarshal, unmarshal types.ItemUnmarshal) *MSortedSet

func (*MSortedSet) SortedSet Uses

func (m *MSortedSet) SortedSet() *SortedSet

type MapSet Uses

type MapSet struct {
    Set types.Set
}

func NewMapSet Uses

func NewMapSet(set types.Set) *MapSet

func (*MapSet) Add Uses

func (m *MapSet) Add(item types.Hashable) (err error)

func (*MapSet) Delete Uses

func (m *MapSet) Delete(item types.Hashable) (err error)

func (*MapSet) Equals Uses

func (m *MapSet) Equals(b types.Equatable) bool

func (*MapSet) Extend Uses

func (m *MapSet) Extend(items types.KIterator) (err error)

func (*MapSet) Get Uses

func (m *MapSet) Get(key types.Hashable) (value interface{}, err error)

func (*MapSet) Has Uses

func (m *MapSet) Has(key types.Hashable) bool

func (*MapSet) Intersect Uses

func (m *MapSet) Intersect(b types.Set) (types.Set, error)

func (*MapSet) Item Uses

func (m *MapSet) Item(key types.Hashable) (me types.Hashable, err error)

func (*MapSet) Items Uses

func (m *MapSet) Items() types.KIterator

func (*MapSet) Iterate Uses

func (m *MapSet) Iterate() (kvit types.KVIterator)

func (*MapSet) Keys Uses

func (m *MapSet) Keys() types.KIterator

func (*MapSet) ProperSubset Uses

func (m *MapSet) ProperSubset(b types.Set) bool

func (*MapSet) ProperSuperset Uses

func (m *MapSet) ProperSuperset(b types.Set) bool

func (*MapSet) Put Uses

func (m *MapSet) Put(key types.Hashable, value interface{}) (err error)

func (*MapSet) Remove Uses

func (m *MapSet) Remove(key types.Hashable) (value interface{}, err error)

func (*MapSet) Size Uses

func (m *MapSet) Size() int

func (*MapSet) String Uses

func (m *MapSet) String() string

func (*MapSet) Subset Uses

func (m *MapSet) Subset(b types.Set) bool

func (*MapSet) Subtract Uses

func (m *MapSet) Subtract(b types.Set) (types.Set, error)

func (*MapSet) Superset Uses

func (m *MapSet) Superset(b types.Set) bool

func (*MapSet) Union Uses

func (m *MapSet) Union(b types.Set) (types.Set, error)

func (*MapSet) Values Uses

func (m *MapSet) Values() types.Iterator

type SetMap Uses

type SetMap struct {
    types.Map
}

func NewSetMap Uses

func NewSetMap(m types.Map) *SetMap

func (*SetMap) Add Uses

func (s *SetMap) Add(item types.Hashable) (err error)

func (*SetMap) Delete Uses

func (s *SetMap) Delete(item types.Hashable) (err error)

func (*SetMap) Equals Uses

func (s *SetMap) Equals(o types.Equatable) bool

unimplemented

func (*SetMap) Extend Uses

func (s *SetMap) Extend(items types.KIterator) (err error)

func (*SetMap) Intersect Uses

func (s *SetMap) Intersect(other types.Set) (types.Set, error)

Unions s with o and returns a new SetMap (with a LinearHash)

func (*SetMap) Item Uses

func (s *SetMap) Item(item types.Hashable) (types.Hashable, error)

unimplemented

func (*SetMap) Items Uses

func (s *SetMap) Items() types.KIterator

func (*SetMap) ProperSubset Uses

func (s *SetMap) ProperSubset(o types.Set) bool

Is s a proper subset of o?

func (*SetMap) ProperSuperset Uses

func (s *SetMap) ProperSuperset(o types.Set) bool

Is s a proper superset of o?

func (*SetMap) Subset Uses

func (s *SetMap) Subset(o types.Set) bool

Is s a subset of o?

func (*SetMap) Subtract Uses

func (s *SetMap) Subtract(other types.Set) (types.Set, error)

Unions s with o and returns a new SetMap (with a LinearHash)

func (*SetMap) Superset Uses

func (s *SetMap) Superset(o types.Set) bool

Is s a superset of o?

func (*SetMap) Union Uses

func (s *SetMap) Union(other types.Set) (types.Set, error)

Unions s with o and returns a new SetMap (with a LinearHash)

type SortedSet Uses

type SortedSet struct {
    list.Sorted
}

SortedSet is a list.Sorted and therefore has all of the methods that list.Sorted has. So although they do not show up in the generated docs you can just do this:

s := NewSortedSet(10)
s.Add(types.Int(5))
s2 = s.Union(FromSlice([]types.Hashable{types.Int(7)}))
fmt.Println(s2.Has(types.Int(7)))
fmt.Println(s.Has(types.Int(7)))

func FromSlice Uses

func FromSlice(items []types.Hashable) *SortedSet

func NewSortedSet Uses

func NewSortedSet(initialSize int) *SortedSet

func SortedFromSet Uses

func SortedFromSet(s types.Set) *SortedSet

func (*SortedSet) Copy Uses

func (s *SortedSet) Copy() *SortedSet

func (*SortedSet) Intersect Uses

func (s *SortedSet) Intersect(other types.Set) (types.Set, error)

Unions s with o and returns a new Sorted Set

func (*SortedSet) Overlap Uses

func (s *SortedSet) Overlap(o *SortedSet) bool

Are there any overlapping elements?

func (*SortedSet) ProperSubset Uses

func (s *SortedSet) ProperSubset(o types.Set) bool

Is s a proper subset of o?

func (*SortedSet) ProperSuperset Uses

func (s *SortedSet) ProperSuperset(o types.Set) bool

Is s a proper superset of o?

func (*SortedSet) Random Uses

func (s *SortedSet) Random() (item types.Hashable, err error)

func (*SortedSet) Subset Uses

func (s *SortedSet) Subset(o types.Set) bool

Is s a subset of o?

func (*SortedSet) Subtract Uses

func (s *SortedSet) Subtract(other types.Set) (types.Set, error)

Unions s with o and returns a new Sorted Set

func (*SortedSet) Superset Uses

func (s *SortedSet) Superset(o types.Set) bool

Is s a superset of o?

func (*SortedSet) Union Uses

func (s *SortedSet) Union(other types.Set) (types.Set, error)

Unions s with o and returns a new Sorted Set

Package set imports 9 packages (graph) and is imported by 4 packages. Updated 2016-09-03. Refresh now. Tools for package owners.