当列表是最好的 [英] when list is best

查看:71
本文介绍了当列表是最好的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以给出一个任务的实际例子,列表

容器比vector或deque更好吗?


Paul Epstein

Can anyone give a realistic example of a task for which the list
container works better than vector or deque?

Paul Epstein

推荐答案

pauldepstein写道:
pauldepstein wrote:

任何人都可以给出一个真实的任务示例哪个列表

容器比vector或deque更好?
Can anyone give a realistic example of a task for which the list
container works better than vector or deque?



这是一个测验吗?当随机插入和删除时必须使用列表

常量(最小)时间。


如果尚未表征性能需求,请使用向量(和

如果你永远不会),因为它最常见的动作(推,弹,迭代),

几乎都是恒定的时间,内存占用最小。


-

Phlip
http://www.greencheese.us/ZeekLand < - 不是博客!!!

Is this for a quiz? Use list when random inserts and deletes must take
constant (minimal) time.

Use a vector if you have not yet characterized your performance needs (and
if you never will), because its most common actions (push, pop, iterate),
are all nearly constant time, with a minimal memory footprint.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!


pa ********** @ att.net 写道:
pa**********@att.net wrote:

任何人都可以给出一个任务的实际例子,列表

容器比vector或deque更好吗?
Can anyone give a realistic example of a task for which the list
container works better than vector or deque?



在填充容器之后,除了任何一端之外,还有频繁插入和删除的任何情况。假设

你有一个50个元素的容器。假设您要删除

第十二个元素并将其替换为19个新元素。假设您需要

重复执行此操作,并且容器在此生命周期内以这种方式更改

。 vector和deque都可能不适合这个任务,而list可以正常工作。


当然,唯一可以确定的方法将是你的代码简介

,看看它是否有所作为。


祝你好运,


汤姆

Any situation in which after the container is populated, there are
frequent insertions and deletions other than from either end. Suppose
you have a container of 50 elements. Suppose you want to delete the
twelfth element and replace it with 19 new elements. Suppose you want
to do this repeatedly, and the container changes in this manner
throughout its lifetime. vector and deque would both probably be
ill-suited to this task, whereas list would work fine.

Of course, the only way to know for sure would be to profile your code
and see whether it made a difference.

Best regards,

Tom


Thomas Tutone写道:
Thomas Tutone wrote:

当然,唯一明白的方法就是要分析你的代码

,看看它是否有所作为。
Of course, the only way to know for sure would be to profile your code
and see whether it made a difference.



一般来说,只有性能分析才能说明性能。


在处理大型算法的特定情况下批量元素,

你也可以计算O * n性能公式,其中O是每个操作的开销

,n是元素的数量。有些种类,例如,

是O log n。这意味着n个输入元素会导致log n操作,并且每个输入元素的开销都是O,所以O * log n是总开销。


STL模板有助于为各种操作提供有保证的O * n性能配置文件。


-

Phlip http://www.greencheese.us/ZeekLand < - NOT a博客!!!

In general, only profiling will have the last word on performance.

In the specific case of algorithms dealing with large batches of elements,
you can also calculate the O*n performance formula, where O is the overhead
of each operation, and n is the number of elements. Some sorts, for example,
are O log n. That means n input elements cause log n operations, and the
overhead of each one is O, so O * log n is the total Overhead.

The STL templates help by providing assured O*n performance profiles for
their various operations.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!


这篇关于当列表是最好的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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