forked from go-air/gini
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlit.go
More file actions
62 lines (51 loc) · 1.13 KB
/
Copy pathlit.go
File metadata and controls
62 lines (51 loc) · 1.13 KB
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
62
// Copyright 2016 The Gini Authors. All rights reserved. Use of this source
// code is governed by a license that can be found in the License file.
package z
import "fmt"
type Lit uint32
// LitNull is the constant 0, used in various places to indicate
// a meaningless literal.
const LitNull Lit = 0
// Dimacs2Lit takes a dimacs-coded literal and returns a Lit.
// A Dimacs coded literal for a variable v is
//
// -v for not(v)
// v for v
func Dimacs2Lit(m int) Lit {
if m < 0 {
return Lit(-2*m + 1)
}
return Lit(2 * m)
}
// Dimacs returns the dimacs coding of the Lit m.
func (m Lit) Dimacs() int {
if m&1 != 0 {
return -int((m >> 1))
}
return int(m >> 1)
}
func (m Lit) String() string {
return fmt.Sprintf("%d", m.Dimacs())
}
// Var returns the Var associated with m.
func (m Lit) Var() Var {
return Var(m >> 1)
}
// Not returns the negation of m.
func (m Lit) Not() Lit {
return Lit(m ^ 1)
}
// Sign returns
//
// 1 if m is a variable
// -1 if m is a negated variable
func (m Lit) Sign() int8 {
if m&1 == 0 {
return 1
}
return -1
}
// IsPos returns true if m is a variable.
func (m Lit) IsPos() bool {
return m&1 == 0
}