File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 44package gen
55
66import (
7- "github.com/irifrance/gini/z"
87 "math/rand"
8+
9+ "github.com/irifrance/gini/z"
910)
1011
1112type RandCuber interface {
@@ -16,13 +17,15 @@ func NewRandCuber(maxSize int, maxVar z.Var) RandCuber {
1617 return & cubes {
1718 minSize : 1 ,
1819 maxSize : maxSize ,
19- maxVar : maxVar }
20+ maxVar : maxVar ,
21+ uniq : make (map [z.Var ]struct {}, maxSize )}
2022}
2123
2224type cubes struct {
2325 minSize int
2426 maxSize int
2527 maxVar z.Var
28+ uniq map [z.Var ]struct {}
2629}
2730
2831func (c * cubes ) SetMinSize (s int ) {
@@ -36,9 +39,16 @@ func (c *cubes) SetMaxSize(s int) {
3639func (c * cubes ) RandCube (dst []z.Lit ) []z.Lit {
3740 dst = dst [:0 ]
3841 sz := c .minSize + rand .Intn (c .maxSize - c .minSize + 1 )
42+ for k := range c .uniq {
43+ delete (c .uniq , k )
44+ }
3945 for i := 0 ; i < sz ; i ++ {
4046 m := z .Lit ((rand .Intn (int (c .maxVar ))+ 1 )* 2 + rand .Intn (2 ))
47+ if _ , ok := c .uniq [m .Var ()]; ok {
48+ continue
49+ }
4150 dst = append (dst , m )
51+ c .uniq [m .Var ()] = struct {}{}
4252 }
4353 return dst
4454}
You can’t perform that action at this time.
0 commit comments