Feature !request into std.algorithm
bioinfornatics
bioinfornatics at fedoraproject.org
Thu May 3 10:28:22 PDT 2012
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.
for go to algorithm a template replace char[] by Range i think
---------------------------
@safe nothrow pure
sizediff_t[char[]] searchIndex( in char[] sequence, in char[][]
token...)
in{
assert(sequence !is null, "Error given sequence is null");
}
body{
bool isComputing = true;
size_t index = 0;
size_t flag = 0;
sizediff_t[char[]] result;
foreach( tok; token)
result[tok] = -1;
while(isComputing){
if( index >= sequence.length )
isComputing = false;
else if( flag == token.length )
isComputing = false;
else{
foreach( tok; token){
if( sequence.length - index >= tok.length ){
const(char)[] currentToken = (tok.length > 1) ?
sequence[index .. index + tok.length] : [sequence[index]];
if( currentToken in result && result[currentToken] == -1 ){
result[currentToken] = index;
flag++;
}
}
}
index++;
}
}
return result;
}
More information about the Digitalmars-d
mailing list