bitset

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2018 License: MIT Imports: 4 Imported by: 1

README

bitset

Build Status Go Report Card

Package bitset provides Set, a compact and fast representation for a dense set of positive integer values.

Documentation

Overview

Package bitset provides Set, a compact and fast representation for a dense set of positive integer values.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

Set represents a set of positive integers. Memory usage is proportional to the largest integer in the Set.

func (*Set) Add

func (s *Set) Add(i int)

Add adds the integer i to s. Add panics if i is less than zero.

func (*Set) AddRange

func (s *Set) AddRange(low, hi int)

AddRange adds integers in the interval [low, hi) to the set. AddRange panics if low is less than zero.

func (*Set) Bytes

func (s *Set) Bytes() []byte

Bytes returns the set as a bitarray. The most significant bit in each byte represents the smallest-index number.

Example
s := new(Set)
s.Add(0)
s.Add(3)
s.Add(8)
s.Add(10)
b := s.Bytes()
fmt.Printf("%b %b", b[0], b[1])
Output:

10010000 10100000

func (*Set) Cardinality

func (s *Set) Cardinality() int

Cardinality returns the number of integers in s.

func (*Set) Copy

func (s *Set) Copy() *Set

Copy returns a copy of s.

func (*Set) Equal

func (s *Set) Equal(ss *Set) bool

Equal returns true if s and ss contain the same integers

func (*Set) FromBytes

func (s *Set) FromBytes(data []byte)

FromBytes sets s to the value of data interpreted as a bitarray in the same format as produced by Bytes..

func (*Set) Intersect

func (s *Set) Intersect(ss *Set)

Intersect removes integers in s which are not also in ss.

func (*Set) Max

func (s *Set) Max() int

Max returns the value of the maximum integer in s, or -1 if s is empty.

func (*Set) NextAfter

func (s *Set) NextAfter(i int) int

NextAfter returns the smallest integer in s greater than or equal to i or -1 if no such integer exists.

Example

NextAfter can be used to iterate over the elements of the set.

s := new(Set)
s.Add(2)
s.Add(42)
s.Add(13)
for i := s.NextAfter(0); i >= 0; i = s.NextAfter(i + 1) {
	fmt.Println(i)
}
Output:

2
13
42

func (*Set) Remove

func (s *Set) Remove(i int)

Remove removes the integer i from s, or does nothing if i is not already in s.

func (*Set) RemoveRange

func (s *Set) RemoveRange(low, hi int)

RemoveRange removes integers in the interval [low, hi) from the set.

func (*Set) String

func (s *Set) String() string

String returns a string representation of s.

Example
s := new(Set)
s.Add(2)
s.Add(42)
s.Add(13)
fmt.Println(s)
Output:

[2 13 42]

func (*Set) Subtract

func (s *Set) Subtract(ss *Set)

Subtract removes integers from s which are also in ss.

func (*Set) SymmetricDifference

func (s *Set) SymmetricDifference(ss *Set)

SymmetricDifference adds integers to s which are in ss but not in s, and removes integers in s that are also in ss.

func (*Set) Test

func (s *Set) Test(i int) bool

Test returns true if i is in s, false otherwise.

func (*Set) Union

func (s *Set) Union(ss *Set)

Union adds integers to s which are in ss.

Jump to

Keyboard shortcuts

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