可搜索的环形缓冲区

时间:2013-03-27 19:47:59

标签: c++ boost data-structures stl std

我想知道是否有人可以建议一个既具有环形缓冲区功能的c ++数据结构(保证有限存储),又同时允许对指定数据的环形缓冲区进行有效的线程安全搜索?

1 个答案:

答案 0 :(得分:2)

Intel TBB containers对于这类问题非常有用。

concurrent_unordered_map应该根据你的情况做出契约,但如果你真的想要一些戒指结构,你可以使用concurrent_bounded_queue并自己动手来模仿戒指行为(见下文)。但是,您将获得此结构的线性搜索复杂性,而不是地图中的对数。

template<class T>
struct concurrent_ring : tbb::concurrent_bounded_queue<T>
{
    void push(const T& t) 
    {
        while(!tbb::concurrent_bounded_queue<T>::try_push(t)) 
           pop();
    }
}
相关问题