On 01/09/2013 04:14 PM, Charles Hixson wrote:
Would the following code:
for (int i = 1; i < di.count; i++)
{ assert (node.di.entry[i - 1].key < node.di.entry[i].key); }

be optimized away if compiled under -release?

It looks like you can use std.algorithm.isSorted instead:

  http://dlang.org/phobos/std_algorithm.html#isSorted

    assert(isSorted(di));

Or perhaps:

    assert(isSorted(node.di.entry[0 .. di.count]));

That code will disappear in release mode.

Additionally, if the O(N) complexity of that check is not acceptable even in non-release mode there is std.range.assumeSorted:

  http://dlang.org/phobos/std_range.html#.assumeSorted

assumeSorted makes very few comparisons so it may miss occasional sort issues. Also, it is not really for checking but more for range algorithms that require or work better with a sorted range.

Ali

Reply via email to