需要一个有效的数据结构 [英] need an efficient data structure

查看:82
本文介绍了需要一个有效的数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i需要在数据结构中存储大量整数(比如10,000)。

约束条件是:

1.它应该很快。

2.应该进行排序或排序。

3.Insterting和删除应该很快。

4.没有。元素可以在运行时改变,因此它应该是动态的。

现在我正在使用SortedVector,但它非常慢。

所以,你能建议一个合适的数据结构。


i need to store a lot of integers(say 10,000) in a datastructure.
The constraints are:
1. It should be fast.
2. It should be orderded or sorted.
3.Insterting and deleting should be fast.
4. The no. of elements can change at runtime and hence it should be dynamic.
Right now i am using SortedVector , but it is very slow.
So, can u pls suggest a suitable Datastructure.

推荐答案



" Raghavendra Mahuli" < RA ************ @ in.bosch.com>在消息中写道

news:c9 ********** @ ns1.fe.internet.bosch.com ...

"Raghavendra Mahuli" <ra************@in.bosch.com> wrote in message
news:c9**********@ns1.fe.internet.bosch.com...

我需要在数据结构中存储大量整数(比如10,000)。
约束条件是:
1.它应该很快。
2.它应该被排序或排序。
3.Insterting和删除应该是快速的。
4.没有。元素可以在运行时更改,因此它应该是
dynamic。现在我正在使用SortedVector,但它非常慢。
所以,你能不能建议一个合适的数据结构。

i need to store a lot of integers(say 10,000) in a datastructure.
The constraints are:
1. It should be fast.
2. It should be orderded or sorted.
3.Insterting and deleting should be fast.
4. The no. of elements can change at runtime and hence it should be dynamic. Right now i am using SortedVector , but it is very slow.
So, can u pls suggest a suitable Datastructure.




std :: set或std: :multiset如果你想复制。


john



std::set or std::multiset if you want duplicates.

john


2004年5月27日星期四09:30:01 + 0100, ; John Harrison"

< jo ************* @ hotmail.com>写道:
On Thu, 27 May 2004 09:30:01 +0100, "John Harrison"
<jo*************@hotmail.com> wrote:

Raghavendra Mahuli < RA ************ @ in.bosch.com>在消息中写道
新闻:c9 ********** @ ns1.fe.internet.bosch.com ...

"Raghavendra Mahuli" <ra************@in.bosch.com> wrote in message
news:c9**********@ns1.fe.internet.bosch.com...

我需要存储一个数据结构中有很多整数(比如10,000)。
约束条件是:
1.应该很快。
2.应该对它进行排序或排序。
3.Insterting删除应该很快。
4.没有。元素可以在运行时更改,因此它应该

i need to store a lot of integers(say 10,000) in a datastructure.
The constraints are:
1. It should be fast.
2. It should be orderded or sorted.
3.Insterting and deleting should be fast.
4. The no. of elements can change at runtime and hence it should be


动态。

现在我正在使用SortedVector,但它非常慢。
所以,你能吗?请提示一个合适的数据结构。
Right now i am using SortedVector , but it is very slow.
So, can u pls suggest a suitable Datastructure.



std :: set或std :: multiset如果你想要重复。



std::set or std::multiset if you want duplicates.




并制作确定你有一个快速的内存分配器!如果你的std :: allocator还没有以这种方式在
中进行优化,那么池分配器将会在这里帮助很多。


Tom

-

C ++ FAQ: http://www.parashift.com/c++-faq-lite/

C常见问题: http://www.eskimo.com/~scs/C-faq/top.html


Raghavendra Mahuli写道:
Raghavendra Mahuli wrote:
我需要在数据结构中存储很多整数(比如10,000)。
约束条件是:
1.它应该很快。


将进行权衡。哪些操作应该最快?

2.应该对其进行排序或排序。


必须始终保持该属性,或者您是否计划在读取之间进行一堆插入或删除?我的意思是,如果你将
连续插入100个元素,那么这个集合真的需要在每次插入后重新排序吗?

3.Insterting和删除应该很快。


插入和删除在哪里?如果你需要在绝对每次插入后保持订单

,那么std :: set或std :: multiset可能是最好的,就像JohnH建议的那样。如果你只需要在插入所有

元素后对它进行排序,那么std :: vector在时间和空间上都可以通过

常量因子更有效。

4.没有。元素可以在运行时更改,因此它应该是动态的。
i need to store a lot of integers(say 10,000) in a datastructure.
The constraints are:
1. It should be fast.
There will be trade-offs. Which operations should be fastest?
2. It should be orderded or sorted.
Must that property be maintained at all times, or do you plan to do a
bunch of insertions or deletions between reads? What I mean is, if you
will insert 100 elements in a row, does the collection really need to
re-sort itself after each insertion?
3.Insterting and deleting should be fast.
Inserting and deleting where? If you need to maintain the ordering
after absolutely every insertion, a std::set or std::multiset may be
best, as JohnH suggested. If you only need it to be sorted once all
elements have been inserted, a std::vector may be more efficient by a
constant factor in both time and space.
4. The no. of elements can change at runtime and hence it should be dynamic.




标准库具有动态可增长的集合,几乎所有

您的包含需求。 :)



The standard library has dynamically growable collections for almost all
your containment needs. :)


这篇关于需要一个有效的数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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