#ifndef BITID_H #define BITID_H #include #include template class CustomBitset : public std::bitset { public: CustomBitset() : std::bitset() {} CustomBitset(const std::bitset& b) : std::bitset(b) {} // assert val < n and then set the val bit, this is different from std::bitset CustomBitset(unsigned long long val) : std::bitset(0) { assert(val < N); this->set(val); } // don't print leading zeros std::string to_string() const { std::string str = std::bitset::to_string(); size_t first_one = str.find('1'); return first_one == std::string::npos ? "0" : str.substr(first_one); } }; template std::ostream& operator<<(std::ostream& os, const CustomBitset& b) { os << b.to_string(); return os; } namespace std { template struct hash> { size_t operator()(const CustomBitset& b) const { return std::hash()(b.to_string()); } }; } typedef CustomBitset<128> BitId; #endif /* BITID_H */