哪个更有效:STL:Set还是array? [英] Which is more efficient:STL:Set or array?

查看:67
本文介绍了哪个更有效:STL:Set还是array?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的问题详情:

我有几个项目(简单的值或对象)要放入一个数组和

我通过一个集合实现它而不仅仅是一个一系列的项目。这个

是因为每次我得到一个新项目时我都要查看Set

是否存在。取决于它是否存在我

必须做出不同的响应。

因为很容易搜索到一个Set而不是一些if

语句将比较数组中的每个元素与

给定的新项目我选择Set但​​是担心效率

比较它们。


谢谢,

CodeCracker

Problem details below:
I have few items(simple values or objects) to be put into an array and
I implement it through a set rather than just an array of items. This
is because every time I get a new item I have to look into the Set
whether it is there or not. Depending on whether it is there or not I
have to respond differntly.
Since it is easy to search into a Set rather than a number of if
statement which will compare each of the element in the array with the
given new item I chose Set but worrying about the efficiency
comparision of them.

Thanks,
CodeCracker

推荐答案

CodeCracker写道:
CodeCracker wrote:
下面的问题详情:
我将几个项目(简单的值或对象)放入数组中,并且我通过集合实现它而不仅仅是一个项目数组。这是因为每次我得到一个新项目时我都要查看Set
是否存在。取决于它是否存在我不得不做出不同的响应。
因为很容易搜索到一个Set而不是一些if
语句,它将比较每个元素带有
给出新项目的数组我选择Set但​​是担心效率比较它们。

谢谢,
CodeCracker
Problem details below:
I have few items(simple values or objects) to be put into an array and
I implement it through a set rather than just an array of items. This
is because every time I get a new item I have to look into the Set
whether it is there or not. Depending on whether it is there or not I
have to respond differntly.
Since it is easy to search into a Set rather than a number of if
statement which will compare each of the element in the array with the
given new item I chose Set but worrying about the efficiency
comparision of them.

Thanks,
CodeCracker




别担心。


-

反垃圾邮件地址,更改每个''X'' to''。''直接回复。



Don''t worry about it.

--
Anti-spam address, change each ''X'' to ''.'' to reply directly.


Larry I Smith写道:
Larry I Smith wrote:
别担心。




我喜欢你的回答。我可以引用你吗?



I like your answer. May I quote you?


Rapscallion写道:
Rapscallion wrote:
Larry I Smith写道:
Larry I Smith wrote:
Don'不用担心。



我喜欢你的回答。我可以引用你吗?



I like your answer. May I quote you?




当然。我被指责了很多...(:


Lary


-

反垃圾邮件地址,将每个''X''更改为''。''直接回复。



Sure. I get blamed for a lot... (:

Lary

--
Anti-spam address, change each ''X'' to ''.'' to reply directly.


这篇关于哪个更有效:STL:Set还是array?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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