/
boolean.go
62 lines (56 loc) · 1.09 KB
/
boolean.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
62
package jsum
type Boolean struct {
dedBase
tNo, fNo int
}
func (a *Boolean) Accepts(v interface{}) bool { return JsonTypeOf(v) == JsonBoolean }
func (a *Boolean) Example(v interface{}) Deducer {
vjt := JsonTypeOf(v)
if vjt == JsonBoolean {
if v.(bool) {
a.tNo++
} else {
a.fNo++
}
return a
}
return &Union{
dedBase: dedBase{cfg: a.cfg},
variants: []Deducer{a, Deduce(a.cfg, v)},
}
}
func (a *Boolean) Hash(dh DedupHash) uint64 {
hash := a.dedBase.startHash(JsonBoolean)
if a.cfg.DedupBool&DedupBoolFalse != 0 {
if a.fNo > 0 {
hash.WriteByte(1)
} else {
hash.WriteByte(0)
}
}
if a.cfg.DedupBool&DedupBoolTrue != 0 {
if a.tNo > 0 {
hash.WriteByte(1)
} else {
hash.WriteByte(0)
}
}
res := hash.Sum64()
dh[res] = addNotEqual(dh[res], a)
return res
}
func (s *Boolean) Equal(d Deducer) bool {
b, ok := d.(*Boolean)
if !ok {
return false
}
if (s.fNo > 0) != (b.fNo > 0) {
return false
}
if (s.tNo > 0) != (b.tNo > 0) {
return false
}
res := s.dedBase.Equal(&b.dedBase)
return res
}
func (s *Boolean) super() *dedBase { return &s.dedBase }