在两个向量中创建元素之间的链接 [英] Create links between elements in two vectors

查看:161
本文介绍了在两个向量中创建元素之间的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算建立链接,用于识别两个向量的关联。假设我们有两个向量:

  vector1< seg1,seg2,seg3> 
vector2< pic1,pic2,pic3,pic4>

并且假设关联如下:



<$ p1 p> seg1->(pic1,pic2)seg2->(pic1,pic2)seg3-> pic3 // from vector1 side
pic1->(seg1,seg2 )pic2->(seg1,seg2)pic3-> seg3 pic4->无来自载体2侧的


$ b b

我想要的是知道哪个seg与pics的indexNums相关联,并且对于pics是相同的。我只关注两个向量中的位置数,我不在乎这两个向量的元素内容是什么。我做的是设计一个结构如:

  Struct 
{
int indexNum;
Bool类型; // seg或pic
addlink(indexNum); //添加一个链接到另一个Struct,类型应该是相反的。
removelink(indexNum); //从给定的indexNum中删除一个链接
getLinks(); //返回所有的链接,返回应该是vector< Struct *> ;?
}

我认为这不太好,是否有更好的方法为这两个向量建立链接?

解决方案

Boost.Bimap 旨在解决这类问题。


I am planning to make links for identifying the association of two vectors. Let's assume that we have two vectors:

vector1 <seg1, seg2, seg3>
vector2 <pic1, pic2, pic3,pic4>

And the association is assumed like:

seg1->(pic1, pic2) seg2->(pic1,pic2) seg3->pic3 //from vector1 side
pic1->(seg1, seg2) pic2->(seg1,seg2) pic3->seg3 pic4->nothing //from vector2 side

what I want is know which seg is associated with which indexNums of pics, and the same for pics. I only focus on the position number in the two vector, and I don't care what the element content of these two vectors is. What I did is to design a struct like:

Struct 
{
  int indexNum;
  Bool type; //seg or pic
  addlink(indexNum); //add a link to another Struct, and the type should be opposite.
  removelink(indexNum); //remove a link from a given indexNum
  getLinks();  //return all of links, the return should be vector<Struct*>? 
}

I think it is not good, and not clear for the association. Is there better way to make links for this two vectors?

解决方案

Boost.Bimap was designed to solve this kind problem.

这篇关于在两个向量中创建元素之间的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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