Documentation ¶
Overview ¶
Example (Serialize) ¶
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") }
Output:
Index ¶
- func Intersect(a, b types.Set) (types.Set, error)
- func ProperSubset(a, b types.Set) bool
- func ProperSuperset(a, b types.Set) bool
- func Subset(a, b types.Set) bool
- func Subtract(a, b types.Set) (types.Set, error)
- func Superset(a, b types.Set) bool
- func Union(a, b types.Set) (types.Set, error)
- type MSortedSet
- type MapSet
- func (m *MapSet) Add(item types.Hashable) (err error)
- func (m *MapSet) Delete(item types.Hashable) (err error)
- func (m *MapSet) Equals(b types.Equatable) bool
- func (m *MapSet) Extend(items types.KIterator) (err error)
- func (m *MapSet) Get(key types.Hashable) (value interface{}, err error)
- func (m *MapSet) Has(key types.Hashable) bool
- func (m *MapSet) Intersect(b types.Set) (types.Set, error)
- func (m *MapSet) Item(key types.Hashable) (me types.Hashable, err error)
- func (m *MapSet) Items() types.KIterator
- func (m *MapSet) Iterate() (kvit types.KVIterator)
- func (m *MapSet) Keys() types.KIterator
- func (m *MapSet) ProperSubset(b types.Set) bool
- func (m *MapSet) ProperSuperset(b types.Set) bool
- func (m *MapSet) Put(key types.Hashable, value interface{}) (err error)
- func (m *MapSet) Remove(key types.Hashable) (value interface{}, err error)
- func (m *MapSet) Size() int
- func (m *MapSet) Subset(b types.Set) bool
- func (m *MapSet) Subtract(b types.Set) (types.Set, error)
- func (m *MapSet) Superset(b types.Set) bool
- func (m *MapSet) Union(b types.Set) (types.Set, error)
- func (m *MapSet) Values() types.Iterator
- type SortedSet
- func (s *SortedSet) Intersect(other types.Set) (types.Set, error)
- func (s *SortedSet) Overlap(o *SortedSet) bool
- func (s *SortedSet) ProperSubset(o types.Set) bool
- func (s *SortedSet) ProperSuperset(o types.Set) bool
- func (s *SortedSet) Random() (item types.Hashable, err error)
- func (s *SortedSet) Subset(o types.Set) bool
- func (s *SortedSet) Subtract(other types.Set) (types.Set, error)
- func (s *SortedSet) Superset(o types.Set) bool
- func (s *SortedSet) Union(other types.Set) (types.Set, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ProperSubset ¶
func ProperSuperset ¶
Types ¶
type MSortedSet ¶
func NewMSortedSet ¶
func NewMSortedSet(s *SortedSet, marshal types.ItemMarshal, unmarshal types.ItemUnmarshal) *MSortedSet
func (*MSortedSet) SortedSet ¶
func (m *MSortedSet) SortedSet() *SortedSet
type SortedSet ¶
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 NewSortedSet ¶
func (*SortedSet) ProperSubset ¶
Is s a proper subset of o?
func (*SortedSet) ProperSuperset ¶
Is s a proper superset of o?
Click to show internal directories.
Click to hide internal directories.