File: multiless.go

package info (click to toggle)
golang-github-anacrolix-missinggo 2.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 836 kB
  • sloc: makefile: 4
file content (47 lines) | stat: -rw-r--r-- 695 bytes parent folder | download
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
package missinggo

type (
	SameLessFunc func() (same, less bool)
	MultiLess    struct {
		ok   bool
		less bool
	}
)

func (me *MultiLess) Less() bool {
	return me.ok && me.less
}

func (me *MultiLess) Final() bool {
	if !me.ok {
		panic("undetermined")
	}
	return me.less
}

func (me *MultiLess) FinalOk() (left, ok bool) {
	return me.less, me.ok
}

func (me *MultiLess) Next(f SameLessFunc) {
	if me.ok {
		return
	}
	same, less := f()
	if same {
		return
	}
	me.ok = true
	me.less = less
}

func (me *MultiLess) StrictNext(same, less bool) {
	if me.ok {
		return
	}
	me.Next(func() (bool, bool) { return same, less })
}

func (me *MultiLess) NextBool(l, r bool) {
	me.StrictNext(l == r, l)
}