blob: f88fdf250f4cb79d2dd53eb5f95ad31d667a340d (
about) (
plain) (
blame)
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
63
64
65
66
67
|
package commitquery
// Marks returns the mark bits of one internal node.
func (ctx *Context) Marks(idx NodeIndex) markBits {
return ctx.nodes[idx].marks
}
// HasAnyMarks reports whether one internal node has any requested bit.
func (ctx *Context) HasAnyMarks(idx NodeIndex, bits markBits) bool {
return ctx.nodes[idx].marks&bits != 0
}
// HasAllMarks reports whether one internal node already has all requested bits.
func (ctx *Context) HasAllMarks(idx NodeIndex, bits markBits) bool {
return ctx.nodes[idx].marks&bits == bits
}
// SetMarks ORs one set of mark bits into one internal node.
func (ctx *Context) SetMarks(idx NodeIndex, bits markBits) {
newBits := bits &^ ctx.nodes[idx].marks
if newBits == 0 {
return
}
ctx.trackTouched(idx)
ctx.nodes[idx].marks |= bits
}
// ClearMarks removes one set of mark bits from one internal node.
func (ctx *Context) ClearMarks(idx NodeIndex, bits markBits) {
if ctx.nodes[idx].marks&bits == 0 {
return
}
ctx.trackTouched(idx)
ctx.nodes[idx].marks &^= bits
}
// BeginMarkPhase starts one tracked mark-mutation phase.
func (ctx *Context) BeginMarkPhase() {
ctx.markPhase++
if ctx.markPhase == 0 {
ctx.markPhase++
for i := range ctx.nodes {
ctx.nodes[i].touchedPhase = 0
}
}
ctx.touched = ctx.touched[:0]
}
// ClearTouchedMarks clears the provided bits from all nodes touched in the
// current mark phase.
func (ctx *Context) ClearTouchedMarks(bits markBits) {
for _, idx := range ctx.touched {
ctx.nodes[idx].marks &^= bits
}
}
func (ctx *Context) trackTouched(idx NodeIndex) {
if ctx.nodes[idx].touchedPhase == ctx.markPhase {
return
}
ctx.nodes[idx].touchedPhase = ctx.markPhase
ctx.touched = append(ctx.touched, idx)
}
|