排序的矢量而不是设置 [英] sorted vector instead of set

查看:92
本文介绍了排序的矢量而不是设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有经过充分测试的分类矢量容器实现

库来替换集合容器?

我只需要一些非常基本的东西:

使用lower_bound和insert添加一个新元素,如果它还没有。


使用binary_search和erase删除元素。


我希望二进制搜索的执行速度比set :: count快。


Nandor

Is there a well tested implementation of a sorted vector container
library to replace set containers?
I need only something very basic:

Use lower_bound and insert to add a new element if it''s not there yet.

Use binary_search and erase to remove an element.

I am hoping that binary search performs faster than set::count.

Nandor

推荐答案



" na *********** @ gmail.com D'μà£o

"

"na***********@gmail.com D′μà£o
"

是否有经过充分测试的有序矢量容器实现

库来替换集合容器?

I只需要一些非常基本的东西:


使用lower_bound和insert添加一个新元素,如果它还没有。


使用binary_search并删除一个元素。


我希望二进制搜索的执行速度比set :: count快。


Nandor
Is there a well tested implementation of a sorted vector container
library to replace set containers?
I need only something very basic:

Use lower_bound and insert to add a new element if it''s not there yet.

Use binary_search and erase to remove an element.

I am hoping that binary search performs faster than set::count.

Nandor



我认为你可以使用标准的矢量和算法。如果你小心地维护向量中元素的顺序,你可以使用

std :: binary_search和std :: lower_bound。

I think you can use the standard vector and algorithms. If you
carefully maintain the order of the elements in the vector, you can use
std::binary_search and std::lower_bound with it.


这就是我现在正在做的但是实现有点棘手。

特别是使用lower_bound和insert。我有很多意想不到的b
bug,我仍然不完全相信我的实现。当我尝试插入极端值为
值的元素或插入第一个元素时,会出现

意外问题。我想使用

一些写得很好且经过充分测试的东西。
This is what I am doing now but the implementation is a little tricky.
Especially the use of lower_bound and insert. I had a lot of unexpected
bugs and I still don''t fully trust my implementation. There are
unexpected issues when I try to insert elements which are extreme
values or when I insert the very first element. I''d like to use
something that''s well written and fully tested.

我认为你可以使用标准向量和算法。如果你小心地维护向量中元素的顺序,你可以使用

std :: binary_search和std :: lower_bound。
I think you can use the standard vector and algorithms. If you
carefully maintain the order of the elements in the vector, you can use
std::binary_search and std::lower_bound with it.


12月11日凌晨4:46,nandor.sie ... @ gmail.com写道:
On Dec 11, 4:46 am, nandor.sie...@gmail.com wrote:

是否有经过充分测试的分类矢量容器实现

库来替换集合容器?

我只需要一些非常基本的东西:


使用lower_bound和insert添加一个新元素,如果它还没有。


使用binary_search和erase删除元素。


我希望二进制搜索的执行速度比set :: count快。
Is there a well tested implementation of a sorted vector container
library to replace set containers?
I need only something very basic:

Use lower_bound and insert to add a new element if it''s not there yet.

Use binary_search and erase to remove an element.

I am hoping that binary search performs faster than set::count.



也许你想要一个std :: priority_queue,它是一个可能是

使用deque作为容器的适配器。插入可能比

集慢,但我不确定binary_search是否比

set :: count更快,它们应该是logaritmic其中只有

基准测试可以肯定,并且它可能是

依赖于实现。


-

Erik Wikstr?m

Perhaps you want a std::priority_queue, it''s an adaptor wich probably
uses a deque as container. Inserts can probably be slower than in a
set, but I''m not sure that binary_search will be faster than
set::count, they ought to be logaritmic both of them, but only
benchmarking can tell for sure, and it might be
implementation-dependent.

--
Erik Wikstr?m


这篇关于排序的矢量而不是设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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