什么是最有效的方法来求xÿ连续值的数组? [英] What is the most efficient method to find x contiguous values of y in an array?

查看:159
本文介绍了什么是最有效的方法来求xÿ连续值的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行通过callgrind我的应用表明,这条线所绘一切由约10,000的一个因素。我可能会重新设计它周围,但它让我不知道;有没有更好的办法做到这一点?

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
);

它寻找desiredLength为0xffffffff值的第一个块的一个32位无符号整型数组的偏移量。

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.

推荐答案

您标记的c ++,所以我假定你有STL算法可供选择:

You tagged c++ so I assume you have STL algorithms available:

std::search_n(buffer, bufferEnd, desiredLength, 0xffffffff);

这篇关于什么是最有效的方法来求xÿ连续值的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆