2018-06-16 15:04:12 +08:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
func strictCmp(same, less bool) cmper {
|
|
|
|
return func() (bool, bool) { return same, less }
|
|
|
|
}
|
|
|
|
|
|
|
|
type (
|
|
|
|
cmper func() (same, less bool)
|
|
|
|
multiLess struct {
|
|
|
|
ok bool
|
|
|
|
less bool
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
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 cmper) {
|
2018-06-17 19:11:01 +08:00
|
|
|
if me.ok {
|
|
|
|
return
|
|
|
|
}
|
2018-07-15 10:57:52 +08:00
|
|
|
same, less := f()
|
2018-06-16 15:04:12 +08:00
|
|
|
if same {
|
|
|
|
return
|
|
|
|
}
|
2018-07-15 10:57:52 +08:00
|
|
|
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 })
|
2018-06-16 15:04:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (me *multiLess) NextBool(l, r bool) {
|
|
|
|
me.StrictNext(l == r, l)
|
|
|
|
}
|