What happened to the monotonicity test in SortedRange?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.com
Mon Jul 13 18:23:27 UTC 2020


For a while we've had in Phobos a really nice monotnonicity test in 
SortedRange: in debug mode, sortedness was checked in O(n) time but not 
always (because that would ruin complexity), but instead at random with 
1/n probability. That means on average the complexity was constant, yet 
we did get some checking.

 From there, things have gotten progressively... different. Various 
changes to the approach caused 
https://issues.dlang.org/show_bug.cgi?id=15230. The solution to that was 
https://github.com/dlang/phobos/pull/7205, which I don't think it's very 
good because it is deterministic (i.e. liable to systematic errors) and 
defaults to no checking at all regardless of debug vs. release mode.

As an aside, that PR has documentation issues (e.g. disfluencies, too 
many commas) that should have been corrected in review.

What I think we should do is this: use a probabilistic monotonicity 
testing as described in 
http://www.cse.psu.edu/~sxr48/pubs/TestingSortednessEncyclopedia.pdf or 
one of the referenced papers, or just get back to what we used to do - 
make the O(n) test with 1/n probability.


More information about the Digitalmars-d mailing list