4 ms·
Essentially a constraint that is true about the variables, which helps you reason about the code. A good example is: // Invariant: x[i-1] < target, x[j] >= ta
by dunham 3y ago
Essentially a constraint that is true about the variables, which helps you reason about the code.
A good example is:
// Invariant: x[i-1] < target, x[j] >= target.
In the golang implementation of binary search:
https://github.com/golang/go/blob/master/src/slices/sort.go#L124-L141 https://github.com/golang/go/blob/master/src/slices/sort.go#...
- rahimnathwani 3y agoI wish I could upvote this more than once. Not only because of the clear first line, and the inline example, but especially because you linked to a specific function in a real code base.