Skip to main content
Code Review

Return to Question

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I wrote this function to do unordered_set intersection using templates. I have seen this answer this answer but I thought that it was overkill. I would like the method to take in 2 sets and return a set.

class SetUtilites{
public:
 template<typename Type>
 static boost::unordered_set<Type> intersection(const boost::unordered_set<Type> &set1, const boost::unordered_set<Type> &set2){
 if(set1.size() < set2.size()){
 boost::unordered_set<Type> iSet;
 boost::unordered_set<Type>::iterator it;
 for(it = set1.begin(); it != set1.end();++it){
 if(set2.find(*it) != set2.end()){
 iSet.insert(*it);
 }
 }
 return iSet;
 }else{
 return intersection(set2,set1);
 }
 }
};

I wrote this function to do unordered_set intersection using templates. I have seen this answer but I thought that it was overkill. I would like the method to take in 2 sets and return a set.

class SetUtilites{
public:
 template<typename Type>
 static boost::unordered_set<Type> intersection(const boost::unordered_set<Type> &set1, const boost::unordered_set<Type> &set2){
 if(set1.size() < set2.size()){
 boost::unordered_set<Type> iSet;
 boost::unordered_set<Type>::iterator it;
 for(it = set1.begin(); it != set1.end();++it){
 if(set2.find(*it) != set2.end()){
 iSet.insert(*it);
 }
 }
 return iSet;
 }else{
 return intersection(set2,set1);
 }
 }
};

I wrote this function to do unordered_set intersection using templates. I have seen this answer but I thought that it was overkill. I would like the method to take in 2 sets and return a set.

class SetUtilites{
public:
 template<typename Type>
 static boost::unordered_set<Type> intersection(const boost::unordered_set<Type> &set1, const boost::unordered_set<Type> &set2){
 if(set1.size() < set2.size()){
 boost::unordered_set<Type> iSet;
 boost::unordered_set<Type>::iterator it;
 for(it = set1.begin(); it != set1.end();++it){
 if(set2.find(*it) != set2.end()){
 iSet.insert(*it);
 }
 }
 return iSet;
 }else{
 return intersection(set2,set1);
 }
 }
};
edited body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Simple and efficient boost::unordered_set intersection using templates

I wrote this function to do unordered_set intersection using templates. I have seen this answer but I thought that isit was overkill. I would like the method to take in 2 sets and return a set.

class SetUtilites{
public:
 template<typename Type>
 static boost::unordered_set<Type> intersection(const boost::unordered_set<Type> &set1, const boost::unordered_set<Type> &set2){
 if(set1.size() < set2.size()){
 boost::unordered_set<Type> iSet;
 boost::unordered_set<Type>::iterator it;
 for(it = set1.begin(); it != set1.end();++it){
 if(set2.find(*it) != set2.end()){
 iSet.insert(*it);
 }
 }
 return iSet;
 }else{
 return intersection(set2,set1);
 }
 }
};

Simple and efficient boost::unordered_set intersection

I wrote this function to do unordered_set intersection using templates. I have seen this answer but I thought that is was overkill. I would like the method to take in 2 sets and return a set.

class SetUtilites{
public:
 template<typename Type>
 static boost::unordered_set<Type> intersection(const boost::unordered_set<Type> &set1, const boost::unordered_set<Type> &set2){
 if(set1.size() < set2.size()){
 boost::unordered_set<Type> iSet;
 boost::unordered_set<Type>::iterator it;
 for(it = set1.begin(); it != set1.end();++it){
 if(set2.find(*it) != set2.end()){
 iSet.insert(*it);
 }
 }
 return iSet;
 }else{
 return intersection(set2,set1);
 }
 }
};

boost::unordered_set intersection using templates

I wrote this function to do unordered_set intersection using templates. I have seen this answer but I thought that it was overkill. I would like the method to take in 2 sets and return a set.

class SetUtilites{
public:
 template<typename Type>
 static boost::unordered_set<Type> intersection(const boost::unordered_set<Type> &set1, const boost::unordered_set<Type> &set2){
 if(set1.size() < set2.size()){
 boost::unordered_set<Type> iSet;
 boost::unordered_set<Type>::iterator it;
 for(it = set1.begin(); it != set1.end();++it){
 if(set2.find(*it) != set2.end()){
 iSet.insert(*it);
 }
 }
 return iSet;
 }else{
 return intersection(set2,set1);
 }
 }
};
edited tags; edited title
Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Simple and efficient boost unordered_set::unordered_set intersection

deleted 39 characters in body; edited tags
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
added 188 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
Source Link
pbible
  • 419
  • 1
  • 7
  • 17
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /