From b733b798e85dbb7e85e1715d3f2fbe287b56cc0a Mon Sep 17 00:00:00 2001 From: Evan Cordell Date: Tue, 24 Aug 2021 17:30:15 -0400 Subject: [PATCH 1/2] add small go benchmark for sodoku --- sudoku_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sudoku_test.go b/sudoku_test.go index a260390..2e08bbe 100644 --- a/sudoku_test.go +++ b/sudoku_test.go @@ -2,11 +2,18 @@ package gini_test import ( "fmt" + "testing" "github.com/go-air/gini" "github.com/go-air/gini/z" ) +func BenchmarkSudoku(b *testing.B) { + for i := 0; i < b.N; i++ { + Example_sudoku() + } +} + func Example_sudoku() { g := gini.New() // 9 rows, 9 cols, 9 boxes, 9 numbers From 0cf6f83b2e3fa61a029c8c0f2de69e3e73dac76b Mon Sep 17 00:00:00 2001 From: Evan Cordell Date: Tue, 24 Aug 2021 16:54:44 -0400 Subject: [PATCH 2/2] strash index was always calculated at 0, leading to 100% collisions offset by 1 avoids the problem and distributes keys nicely --- logic/c.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/logic/c.go b/logic/c.go index d08091e..e60f5a1 100644 --- a/logic/c.go +++ b/logic/c.go @@ -266,7 +266,7 @@ func (p *C) And(a, b z.Lit) z.Lit { return b } c := strashCode(a, b) - l := uint32(cap(p.nodes)) + l := uint32(cap(p.nodes) - 1) i := c % l si := p.strash[i] for { @@ -282,7 +282,7 @@ func (p *C) And(a, b z.Lit) z.Lit { m, j := p.newNode() m.a = a m.b = b - k := c % uint32(cap(p.nodes)) + k := c % uint32(cap(p.nodes) - 1) m.n = p.strash[k] p.strash[k] = j return z.Var(j).Pos() @@ -367,7 +367,7 @@ func (p *C) grow() { continue } c := strashCode(n.a, n.b) - j := c % ucap + j := c % (ucap - 1) n.n = strash[j] strash[j] = uint32(i) }