mirror of
https://github.com/golang/go
synced 2024-11-18 19:54:44 -07:00
all: calculate the median uniformly
Like sort.Search, use "h := int(uint(i+j) >> 1)" style code to calculate the median.
This commit is contained in:
parent
3466e57354
commit
e2213b7388
@ -247,7 +247,7 @@ func (i *Inst) MatchRunePos(r rune) int {
|
||||
lo := 0
|
||||
hi := len(rune) / 2
|
||||
for lo < hi {
|
||||
m := lo + (hi-lo)/2
|
||||
m := int(uint(lo+hi) >> 1)
|
||||
if c := rune[2*m]; c <= r {
|
||||
if r <= rune[2*m+1] {
|
||||
return m
|
||||
|
@ -184,7 +184,7 @@ func (l *Location) lookup(sec int64) (name string, offset int, start, end int64,
|
||||
lo := 0
|
||||
hi := len(tx)
|
||||
for hi-lo > 1 {
|
||||
m := lo + (hi-lo)/2
|
||||
m := int(uint(lo+hi) >> 1)
|
||||
lim := tx[m].when
|
||||
if sec < lim {
|
||||
end = lim
|
||||
|
@ -106,7 +106,7 @@ func is16(ranges []Range16, r uint16) bool {
|
||||
lo := 0
|
||||
hi := len(ranges)
|
||||
for lo < hi {
|
||||
m := lo + (hi-lo)/2
|
||||
m := int(uint(lo+hi) >> 1)
|
||||
range_ := &ranges[m]
|
||||
if range_.Lo <= r && r <= range_.Hi {
|
||||
return range_.Stride == 1 || (r-range_.Lo)%range_.Stride == 0
|
||||
@ -139,7 +139,7 @@ func is32(ranges []Range32, r uint32) bool {
|
||||
lo := 0
|
||||
hi := len(ranges)
|
||||
for lo < hi {
|
||||
m := lo + (hi-lo)/2
|
||||
m := int(uint(lo+hi) >> 1)
|
||||
range_ := ranges[m]
|
||||
if range_.Lo <= r && r <= range_.Hi {
|
||||
return range_.Stride == 1 || (r-range_.Lo)%range_.Stride == 0
|
||||
@ -216,7 +216,7 @@ func to(_case int, r rune, caseRange []CaseRange) (mappedRune rune, foundMapping
|
||||
lo := 0
|
||||
hi := len(caseRange)
|
||||
for lo < hi {
|
||||
m := lo + (hi-lo)/2
|
||||
m := int(uint(lo+hi) >> 1)
|
||||
cr := caseRange[m]
|
||||
if rune(cr.Lo) <= r && r <= rune(cr.Hi) {
|
||||
delta := cr.Delta[_case]
|
||||
@ -350,7 +350,7 @@ func SimpleFold(r rune) rune {
|
||||
lo := 0
|
||||
hi := len(caseOrbit)
|
||||
for lo < hi {
|
||||
m := lo + (hi-lo)/2
|
||||
m := int(uint(lo+hi) >> 1)
|
||||
if rune(caseOrbit[m].From) < r {
|
||||
lo = m + 1
|
||||
} else {
|
||||
|
@ -518,7 +518,7 @@ func binary(ranges []Range16, r uint16) bool {
|
||||
lo := 0
|
||||
hi := len(ranges)
|
||||
for lo < hi {
|
||||
m := lo + (hi-lo)/2
|
||||
m := int(uint(lo+hi) >> 1)
|
||||
range_ := &ranges[m]
|
||||
if range_.Lo <= r && r <= range_.Hi {
|
||||
return (r-range_.Lo)%range_.Stride == 0
|
||||
|
Loading…
Reference in New Issue
Block a user