www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12752] New: std.algorithm.isPermutation

https://issues.dlang.org/show_bug.cgi?id=12752

          Issue ID: 12752
           Summary: std.algorithm.isPermutation
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs eml.cc

This C++ algorithm is useful in post-conditions and unittests to verify the
correctness of sorting, and in other situations:
http://www.cplusplus.com/reference/algorithm/is_permutation/

The Phobos algorithm could be named "isPermutation(x, y)", that returns a
boolean.

----------

A related algorithm could return an array of indexes that represent the mapping
from the first to the second array.

I am also thinking about a related range that could be named
"assumePermutationOf(x, y)" that returns a range like std.range.assumeSorted,
but it's not easy to use it well.

--
May 16 2014