Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nice to see that the Go gets it right:

        func Search(n int, f func(int) bool) int {
                // Define f(-1) == false and f(n) == true.
                // Invariant: f(i-1) == false, f(j) == true.
                i, j := 0, n
                for i < j {
                        h := i + (j-i)/2 // avoid overflow when computing h
                        // i ≤ h < j
                        if !f(h) {
                                i = h + 1 // preserves f(i-1) == false
                        } else {
                                j = h // preserves f(j) == true
                        }
                }
                // i == j, f(i-1) == false, and f(j) (= f(i)) == true  =>  answer is i.
                return i
        }
http://code.google.com/p/go/source/browse/src/pkg/sort/searc...


I expect at least one of the Go authors was well aware of this very incident (the Java breakage), it was fairly well publicized before Go ever saw the light of day.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: