Last active
March 8, 2017 01:27
-
-
Save miguelAlessandro/faddfe099e4bf3720a2ee077cbaf3f23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Bitset | |
#include <iostream> | |
using namespace std; | |
struct Bitset{ | |
long long m; | |
Bitset(int x = 0){m = x;} | |
const static long long empty_set = 0; | |
bool Find(int in){return m&(1LL<<in);} | |
void Erase(int in){ m &= ~in;} | |
void Insert(int in){m |= in;} | |
int cardinal(){return __builtin_popcount(m) + __builtin_popcount(m>>32);} | |
bool operator==(const Bitset& X){return m == X.m;} | |
bool operator==(const long long& X){return m == X;} | |
friend Bitset Union(const Bitset& X, const Bitset& Y){return X.m|Y.m;} | |
friend Bitset Intersect(const Bitset& X, const Bitset& Y){return X.m&Y.m;} | |
friend Bitset Xor(const Bitset& X, const Bitset& Y){return X.m^Y.m;} | |
}; | |
int main(){ | |
Bitset A, B, C; | |
A.Insert(1); | |
A.Insert(2); | |
A.Insert(5); | |
B.Insert(4); | |
B.Insert(5); | |
B.Insert(3); | |
C.Insert(1); | |
C.Insert(2); | |
C.Insert(3); | |
C.Insert(4); | |
C.Insert(5); | |
if(C == Union(A, B)) cout << "A U B = C" << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment