0

I have a multi set Bimap that looks like:

6 <--> 71
6 <--> 71
6 <--> 71
8 <--> 71
8 <--> 71
10 <--> 71
10 <--> 74

element = left key + right key, or a row in the above block

I would like to remove the elements where the lines are equivalent to another line, for example, I would like to remove two lots of the 6 <--> 71. Essentially, every bimap element must be unique. The left and right keys must be multi sets for my use-case. I would also like to do this post creating the bimap. Is there an inbuilt function that requires every element to be unique? If this isn't the case, does anyone know a good way to do this?

The minimal code I am using is as follows:

  typedef boost::bimap<boost::bimaps::multiset_of<int>,
                       boost::bimaps::multiset_of<int>> bimap;
  bimap bm;
//fill with elements from two vectors
//vectors have the same size by definition
  for(int j = 0; j < matching1.size(); j++){
    bm.insert({matching1[j],matching2[j]});
  }

1 Answers1

0

Yes. You can use the third parameter of bimap to constrain the whole collection.

typedef boost::bimap<boost::bimaps::multiset_of<int>,
                     boost::bimaps::multiset_of<int>,
                     boost::bimaps::set_of_relation<>
                    > bimap;

If you want to first construct a bimap with duplicate pairs, then use your original definition. You can initialise the second bimap from the first, e.g.

typedef boost::bimap<boost::bimaps::multiset_of<int>,
                     boost::bimaps::multiset_of<int>
                    > bimap;

typedef boost::bimap<boost::bimaps::multiset_of<int>,
                     boost::bimaps::multiset_of<int>,
                     boost::bimaps::set_of_relation<>
                    > unique_bimap;

bimap data = { ... };
unique_bimap uniqued_data { data.begin(), data.end() };
Caleth
  • 52,200
  • 2
  • 44
  • 75