Documentation ¶
Overview ¶
Package intsets provides Sparse, a compact and fast representation for sparse sets of int values.
The time complexity of the operations Len, Insert, Remove and Has is in O(n) but in practice those methods are faster and more space-efficient than equivalent operations on sets based on the Go map type. The IsEmpty, Min, Max, Clear and TakeMin operations require constant time.
Index ¶
- Constants
- type Sparse
- func (s *Sparse) AppendTo(slice []int) []int
- func (s *Sparse) BitString() string
- func (s *Sparse) Clear()
- func (s *Sparse) Copy(x *Sparse)
- func (s *Sparse) Difference(x, y *Sparse)
- func (s *Sparse) DifferenceWith(x *Sparse)
- func (s *Sparse) Equals(t *Sparse) bool
- func (s *Sparse) GoString() string
- func (s *Sparse) Has(x int) bool
- func (s *Sparse) Insert(x int) bool
- func (s *Sparse) Intersection(x, y *Sparse)
- func (s *Sparse) IntersectionWith(x *Sparse)
- func (s *Sparse) IsEmpty() bool
- func (s *Sparse) Len() int
- func (s *Sparse) Max() int
- func (s *Sparse) Min() int
- func (s *Sparse) Remove(x int) bool
- func (s *Sparse) String() string
- func (s *Sparse) TakeMin(p *int) bool
- func (s *Sparse) Union(x, y *Sparse)
- func (s *Sparse) UnionWith(x *Sparse) bool
Constants ¶
const ( MaxInt = int(^uint(0) >> 1) MinInt = -MaxInt - 1 )
Limit values of implementation-specific int type.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Sparse ¶
type Sparse struct {
// contains filtered or unexported fields
}
A Sparse is a set of int values. Sparse operations (even queries) are not concurrency-safe.
The zero value for Sparse is a valid empty set.
Sparse sets must be copied using the Copy method, not by assigning a Sparse value.
func (*Sparse) AppendTo ¶
AppendTo returns the result of appending the elements of s to slice in order.
func (*Sparse) BitString ¶
BitString returns the set as a string of 1s and 0s denoting the sum of the i'th powers of 2, for each i in s. A radix point, always preceded by a digit, appears if the sum is non-integral.
Examples:
{}.BitString() = "0" {4,5}.BitString() = "110000" {-3}.BitString() = "0.001" {-3,0,4,5}.BitString() = "110001.001"
func (*Sparse) Difference ¶
Difference sets s to the difference x ∖ y.
func (*Sparse) DifferenceWith ¶
DifferenceWith sets s to the difference s ∖ x.
func (*Sparse) GoString ¶
GoString returns a string showing the internal representation of the set s.
func (*Sparse) Intersection ¶
Intersection sets s to the intersection x ∩ y.
func (*Sparse) IntersectionWith ¶
IntersectionWith sets s to the intersection s ∩ x.
func (*Sparse) TakeMin ¶
If set s is non-empty, TakeMin sets *p to the minimum element of the set s, removes that element from the set and returns true. Otherwise, it returns false and *p is undefined.
This method may be used for iteration over a worklist like so:
var x int for worklist.TakeMin(&x) { use(x) }