Performance optimization for minElement and maxElement

Ali Çehreli acehreli at yahoo.com
Mon Sep 12 02:40:35 UTC 2022


Since the minimum and maximum values of fundamental types are known, can 
minElement and maxElement shortcut and return that value immediately?

I think such an optimization may break existing code because it may not 
consume ranges in old code, which may be surprised by it. (?)

I ask because the documentation says "O(n) Exactly n - 1 comparisons are 
needed."

Ali

P.S. I decided to use my own function instead of minElement; I return 0 
immediately on a range of size_t elements.


More information about the Digitalmars-d mailing list