Verctor /列出什么对我的设计最好? [英] Verctor/List what is best for my design?

查看:44
本文介绍了Verctor /列出什么对我的设计最好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我知道这有点OT但是在我可以进入编程部分之前我想要确保我有结构我有一张2D地图,我的列表/矢量中的项目将成为地图上的行,并在地图中显示

的起点和终点,所以一个项目将有一个开始pos

S(x,y)和一个结束位置E(x,y)。


所以我的结构会类似


struct _POS {

int x;

int y;

};


struct _ITEMLOC {

_POS pos_start;

_POS pos_end;

};


因此实际上它将是从一个点到另一个点的直线。


如果我有一个包含数百个项目的向量我想要检索所有物品

属于某个广场。


类似搜索(上,左,下,右)。这将返回所有

线条在该广场内的项目(部分或全部)。


有谁知道我怎么能实现这一目标?


非常感谢提前。

Sims

Hi,

I know this is slightly OT but before i can get to the programming part i
want to make sure that i have the structure covered.

I have a 2D map and items in my list/vector will be lines on the map, with a
start and finish point within the map, so an item would have a start pos
S(x,y) and an end pos E(x,y).

so my structure would be something like

struct _POS{
int x;
int y;
};

struct _ITEMLOC{
_POS pos_start;
_POS pos_end;
};

So in effect it would be a straight line going from one point to another.

If i have a vector with hundreds of items i want to retrieve all the items
that fall within a certain square.

something like Search( top, left, bottom, right). And that would return all
the items whose line are within that square, (either partially or totally).

Does anybody know how i could achieve that?

Many thanks in advance.
Sims

推荐答案


模拟人生 < SI ********* @ hotmail.com> skrev i en meddelelse

news:bu ************ @ ID-162430.news.uni-berlin.de ...

"Sims" <si*********@hotmail.com> skrev i en meddelelse
news:bu************@ID-162430.news.uni-berlin.de...


我知道这有点OT但是在我进入编程部分之前我想确保我的结构已经覆盖。

我有一个2D地图,我的列表/向量中的项目将是地图上的行,在地图中有
a开始和结束点,所以一个项目将有一个开始位置
S(x,y)和结束pos E(x,y)。

所以我的结构会像

struct _POS {


这是不可移植的名称。使用更好的名字。

int x;
int y;
};

struct _ITEMLOC {


这是这样的。原因是:所有标识符包含两个连续的

下划线或以一个下划线和一个大写字母开头的

保留用于实现(编译器)。

_POS pos_start;
_POS pos_end;
};

因此实际上它将是从一个点到另一个点的直线。

如果我有一个包含数百个项目的向量,我想要检索属于某个方格的所有项目。

像搜索(顶部,左侧,底部,右侧)。这将返回
所有线条在该广场内的项目(部分或全部
)。
有人知道我是如何实现的吗?

非常感谢提前。
模拟人生
Hi,

I know this is slightly OT but before i can get to the programming part i
want to make sure that i have the structure covered.

I have a 2D map and items in my list/vector will be lines on the map, with a start and finish point within the map, so an item would have a start pos
S(x,y) and an end pos E(x,y).

so my structure would be something like

struct _POS{
This is a nonportable name. Use a better name.
int x;
int y;
};

struct _ITEMLOC{
And so is this. The reason: all identifiers containing two consecutive
underscores or beginning with one underscore and an uppercase letter are
reserved for the implementation (the compiler).
_POS pos_start;
_POS pos_end;
};

So in effect it would be a straight line going from one point to another.

If i have a vector with hundreds of items i want to retrieve all the items
that fall within a certain square.

something like Search( top, left, bottom, right). And that would return all the items whose line are within that square, (either partially or totally).
Does anybody know how i could achieve that?

Many thanks in advance.
Sims




这里的列表和矢量确实没什么大不同,但
在这种情况下,
向量会更快。您只需查看entiere

解决方案即可确定需要哪些操作。但是如果你坚持使用

std :: containers和迭代器,那么更换

容器并尝试两种替代方案应该不成问题。

亲切的问候

彼得



There really is no big difference between a list and a vector here, but the
vector would be faster in this case. You just have to look at the entiere
solution to determine what operations are needed. But if you stick to
std::containers and iterators, it should not be a problem to replace the
container and try both alternatives.

Kind regards
Peter




" Peter Koch Larsen" < pk*@mailme.dk>在消息中写道

news:40 ********************* @ dread14.news.tele.dk。 ..

[SNIP]

"Peter Koch Larsen" <pk*@mailme.dk> wrote in message
news:40*********************@dread14.news.tele.dk. ..
[SNIP]

这里列表和向量之间确实没有太大的区别,但是

There really is no big difference between a list and a vector here, but



在这种情况下向量会更快。


the vector would be faster in this case.




恕我直言,这在很大程度上取决于用户更常做的事情 - 插入/删除

或搜索元素。但是,你当然可以轻松交换两个容器

。因此,除非针对实际案例进行测试,否则此讨论可能不会真正导致




[SNIP]


Chris



IMHO this depends very much on what the user does more often - insert/delete
or search for elements. However, you''re of course right that both containers
are easily exchangeable. Thus this discussion might not really lead to
something unless it is tested for the actual case.

[SNIP]

Chris




" Sims" < SI ********* @ hotmail.com>在留言中写道

news:bu ************ @ ID-162430.news.uni-berlin.de ...

"Sims" <si*********@hotmail.com> wrote in message
news:bu************@ID-162430.news.uni-berlin.de...
你好,

[SNI]类似搜索(上,左,下,右)。这将返回
所有线条在该方格内的项目(部分或全部
)。
Hi,
[SNI] something like Search( top, left, bottom, right). And that would return all the items whose line are within that square, (either partially or totally).




在您的情况下,您可能会还考虑使用集合<>容器,

通常是根据平衡二叉树实现的。提供

适当的排序标准可能会缩短您的搜索时间,比较向量或列表。


问候

Chris



In your case you might also consider the use of a set<> container, which
usually is implemented in terms of a balanced binary tree. Supplying an
appropriate sorting criterion might reduce your search times in comparison
to a vector or a list.

Regards
Chris


这篇关于Verctor /列出什么对我的设计最好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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