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);
}
}
};
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);
}
}
};