www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Feature !request into std.algorithm

into std.algorithm they are countUntil that is a useful function buit
when you want the first index of many token is same sequence you need to
all many times countUntil and then loop many time in the same sequence.
This is a inefficiency way. i have wrote a function where loop at max
one time over the sequence.=20
for go to algorithm a template replace char[] by Range i think

 safe nothrow pure
sizediff_t[char[]] searchIndex( in char[] sequence, in char[][]
  assert(sequence !is null, "Error given sequence is null");
  bool   isComputing =3D true;
  size_t index       =3D 0;
  size_t flag        =3D 0;
  sizediff_t[char[]] result;

  foreach( tok; token)
    result[tok] =3D -1;

    if( index >=3D sequence.length )
      isComputing =3D false;
    else if( flag =3D=3D token.length )
      isComputing =3D false;
      foreach( tok; token){
        if( sequence.length - index >=3D tok.length ){
          const(char)[] currentToken =3D (tok.length > 1) ?
sequence[index .. index + tok.length] : [sequence[index]];
          if( currentToken in result && result[currentToken] =3D=3D -1 ){
            result[currentToken] =3D index;
  return result;
May 03 2012