Skip to content

Commit f8b6e82

Browse files
committed
newDancer
1 parent 9e3e8cb commit f8b6e82

File tree

11 files changed

+12
-17
lines changed

11 files changed

+12
-17
lines changed

dance.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (m *MCC) untweak(c, x, unblock int) {
178178
}
179179

180180
// Dance generates all exact covers
181-
func (m *MCC) Dance(rd io.Reader) Result {
181+
func (m *MCC) Dance(rd io.Reader) *Result {
182182
if err := m.inputMatrix(rd); err != nil {
183183
panic(err)
184184
}
@@ -407,7 +407,7 @@ func (m *MCC) Dance(rd io.Reader) Result {
407407
}
408408
}()
409409

410-
return Result{
410+
return &Result{
411411
Solutions: solStream,
412412
Heartbeat: heartbeat,
413413
}

examples/filomino/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func main() {
4040
nr, _ := strconv.Atoi(dimen[0])
4141
nc, _ := strconv.Atoi(dimen[1])
4242

43-
xc := dlx.NewMCC()
43+
xc := dlx.NewDancer()
4444
res := xc.Dance(fd)
4545

4646
box := make([][]int, nr)

examples/langford/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func main() {
4444
}
4545
n, _ := strconv.Atoi(os.Args[1])
4646

47-
xc := dlx.NewMCC()
47+
xc := dlx.NewDancer()
4848
res := xc.Dance(langfordDLX(n))
4949

5050
s := make([]int, 2*n)

examples/partridge/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func main() {
8181
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Minute)
8282
defer cancel()
8383

84-
mcc := dlx.NewMCC()
84+
mcc := dlx.NewDancer()
8585
mcc.PulseInterval = 30 * time.Second
8686
mcc = mcc.WithContext(ctx)
8787
res := mcc.Dance(patridgeDLX(8))

examples/pentominoes/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func main() {
4646
nr, _ := strconv.Atoi(dimen[0])
4747
nc, _ := strconv.Atoi(dimen[1])
4848

49-
xc := dlx.NewMCC()
49+
xc := dlx.NewDancer()
5050
res := xc.Dance(fd)
5151

5252
box := make([][]string, nr)

examples/queen/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func main() {
7272
}
7373
n, _ := strconv.Atoi(os.Args[1])
7474

75-
xc := dlx.NewMCC()
75+
xc := dlx.NewDancer()
7676
res := xc.Dance(queenDLX(n))
7777

7878
i := 0

examples/sudoku/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func sudokuSolver(stream <-chan string) <-chan [][]byte {
110110
outCh := make(chan [][]byte)
111111
outChCh <- outCh
112112

113-
xc := dlx.NewMCC()
113+
xc := dlx.NewDancer()
114114
go func(line string) {
115115
res := xc.Dance(sudokuDLX(strings.NewReader(line)))
116116
ans := []byte(line)

examples/wordsearch/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func main() {
153153
log.Fatal(err)
154154
}
155155

156-
xcc := dlx.NewMCC()
156+
xcc := dlx.NewDancer()
157157
res := xcc.Dance(
158158
wordSearchDLX(strings.Fields(string(buf)), wd, ht))
159159

examples/zebra/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const xccInput = `
109109
`
110110

111111
func main() {
112-
xcc := dlx.NewMCC()
112+
xcc := dlx.NewDancer()
113113
res := xcc.Dance(strings.NewReader(xccInput))
114114

115115
answer := map[byte][]string{

mcc.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package dlx
22

33
import (
44
"context"
5-
"io"
65
"time"
76
)
87

@@ -26,10 +25,6 @@ type Result struct {
2625
Heartbeat <-chan string
2726
}
2827

29-
type Dancer interface {
30-
Dance(reader io.Reader) Result
31-
}
32-
3328
type node struct {
3429
up, down int // predecessor and successor in item list
3530
itm int // the item containing this node
@@ -59,7 +54,7 @@ type MCC struct {
5954
}
6055

6156
// NewMCC Wake me up before you Go Go
62-
func NewMCC() *MCC {
57+
func NewDancer() *MCC {
6358
return &MCC{
6459
nd: make([]node, chunkSize),
6560
cl: make([]item, chunkSize),

mcc_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func solve(matrix string) {
10-
d := NewMCC()
10+
d := NewDancer()
1111
d.Debug = true
1212
d = d.WithContext(context.TODO())
1313
res := d.Dance(strings.NewReader(matrix))

0 commit comments

Comments
 (0)