4 ms·
> I never use three way string comparison, and so I wondered when other programmers use it. Three-way comparisons show up naturally when doing a binary search
by rbehrends 4y ago
> I never use three way string comparison, and so I wondered when other programmers use it.
Three-way comparisons show up naturally when doing a binary search or implementing binary trees.
Interestingly, the binary search implementation in the Go stdlib doesn't need it, but that's because it's only doing part of what you'd normally expect a binary search function to do and shifts the responsibility for the actual equality check to the caller [1].
[1] https://go.dev/src/sort/search.go https://go.dev/src/sort/search.go