What is the most efficient method to find x contiguous values of y in an array?

Posted by Alec on Stack Overflow See other posts from Stack Overflow or by Alec
Published on 2012-10-18T21:56:55Z Indexed on 2012/10/18 23:01 UTC
Read the original article Hit count: 145

Filed under:
|
|
|
|

Running my app through callgrind revealed that this line dwarfed everything else by a factor of about 10,000. I'm probably going to redesign around it, but it got me wondering; Is there a better way to do it?

Here's what I'm doing at the moment:

int i = 1;
while
(
    (
        (*(buffer++) == 0xffffffff && ++i) || 
        (i = 1)
    )
    &&
    i < desiredLength + 1
    &&
    buffer < bufferEnd
);

It's looking for the offset of the first chunk of desiredLength 0xffffffff values in a 32 bit unsigned int array.

It's significantly faster than any implementations I could come up with involving an inner loop. But it's still too damn slow.

© Stack Overflow or respective owner

Related posts about c++

Related posts about c