Mercurial > dedupe
view BitArray.cpp @ 115:404795616b1e default tip
Added a lot of common files to ignore
| author | Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no> |
|---|---|
| date | Sat, 25 Mar 2017 17:43:57 +0100 |
| parents | bc55cbd827bf |
| children |
line wrap: on
line source
#include "BitArray.hpp" #include <cstring> BitArray::~BitArray() { delete bits; } BitArray::BitArray(const BitArray& other) : size_(other.size()), bits(new uchar[NUMCHARS(size_)]) { std::memcpy(bits, other.bits, NUMCHARS(size_)); } BitArray& BitArray::operator=(const BitArray& other) { if (NUMCHARS(size_) != NUMCHARS(other.size_)) { delete bits; bits = new uchar[NUMCHARS(other.size_)]; } size_ = other.size_; memcpy(bits, other.bits, NUMCHARS(size_)); return *this; } bool BitArray::operator==(const BitArray& rhs) const { if (size() != rhs.size()) return false; for(size_t i = 0; i < size(); ++i) { if (testBit(i) != rhs.testBit(i)) return false; } return true; } std::ostream& operator<<(std::ostream& out, const BitArray& rhs) { for (size_t i = 0; i < rhs.size(); ++i) { out << (rhs.testBit(i) ? "1" : "0"); } return out; }
