-
Notifications
You must be signed in to change notification settings - Fork 0
/
candidates.go
61 lines (50 loc) · 1.73 KB
/
candidates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package sudogo
// A set of possible values for a cell. This is similar to a Bitset but is 1 based.
type Candidates struct {
Bitset
}
// Returns whether the candidate exists in the set.
func (cand *Candidates) Has(i int) bool {
return cand.Bitset.Has(i - 1)
}
// Adds or removes the candidate from the set and returns true if the set has changed as a result of this call.
func (cand *Candidates) Set(i int, on bool) bool {
return cand.Bitset.Set(i-1, on)
}
// Creates a slice of all candidates in this set.
func (cand *Candidates) ToSlice() []int {
slice := cand.Bitset.ToSlice()
n := len(slice)
for i := 0; i < n; i++ {
slice[i]++
}
return slice
}
// The smallest candidate in the set or 64 if the set is empty
func (cand *Candidates) First() int {
return cand.Bitset.First() + 1
}
// The largest candidate in the set or 0 if the set is empty
func (cand *Candidates) Last() int {
return cand.Bitset.Last() + 1
}
// Removes all candidates in the given set from this set.
func (cand *Candidates) Remove(remove Candidates) int {
return cand.Bitset.Remove(remove.Bitset)
}
// Adds all candidates in the given set to this set (union).
func (cand *Candidates) Or(or Candidates) int {
return cand.Bitset.Or(or.Bitset)
}
// Removes any candidates from this set that also don't exist in the given set (intersection).
func (cand *Candidates) And(and Candidates) int {
return cand.Bitset.And(and.Bitset)
}
// Returns whether this set and the other share any candidates.
func (cand *Candidates) Overlaps(other Candidates) bool {
return cand.Bitset.Overlaps(other.Bitset)
}
// Returns whether this set and the other don't share one or more candidates.
func (cand *Candidates) Differences(other Candidates) bool {
return cand.Bitset.Differences(other.Bitset)
}