comparison base/ResizeableBitset.h @ 183:146eb9e35baa

* Improve output from Profiler class and make it incur less (no) overhead in release builds with NO_TIMING defined * Fix a lock contention issue in spectrogram * Marginal optimisations elsewhere
author Chris Cannam
date Tue, 10 Oct 2006 14:51:17 +0000
parents 4ab844784152
children 95391b480e17
comparison
equal deleted inserted replaced
182:f75f8a1cd7b1 183:146eb9e35baa
23 23
24 public: 24 public:
25 ResizeableBitset() : m_bits(0) { 25 ResizeableBitset() : m_bits(0) {
26 } 26 }
27 ResizeableBitset(size_t size) : m_bits(new std::vector<uint8_t>) { 27 ResizeableBitset(size_t size) : m_bits(new std::vector<uint8_t>) {
28 m_bits->assign(size / 8 + 1, 0); 28 m_bits->assign((size >> 3) + 1, 0);
29 } 29 }
30 ResizeableBitset(const ResizeableBitset &b) { 30 ResizeableBitset(const ResizeableBitset &b) {
31 m_bits = new std::vector<uint8_t>(*b.m_bits); 31 m_bits = new std::vector<uint8_t>(*b.m_bits);
32 } 32 }
33 ResizeableBitset &operator=(const ResizeableBitset &b) { 33 ResizeableBitset &operator=(const ResizeableBitset &b) {
43 void resize(size_t bits) { // losing all data 43 void resize(size_t bits) { // losing all data
44 if (!m_bits || bits < m_bits->size()) { 44 if (!m_bits || bits < m_bits->size()) {
45 delete m_bits; 45 delete m_bits;
46 m_bits = new std::vector<uint8_t>; 46 m_bits = new std::vector<uint8_t>;
47 } 47 }
48 m_bits->assign(bits / 8 + 1, 0); 48 m_bits->assign((bits >> 3) + 1, 0);
49 } 49 }
50 50
51 bool get(size_t column) const { 51 bool get(size_t column) const {
52 return ((*m_bits)[column / 8]) & (1u << (column % 8)); 52 return ((*m_bits)[column >> 3]) & (1u << (column & 0x07));
53 } 53 }
54 54
55 void set(size_t column) { 55 void set(size_t column) {
56 ((*m_bits)[column / 8]) |= (uint8_t(1) << (column % 8)); 56 ((*m_bits)[column >> 3]) |= (uint8_t(1) << (column & 0x07));
57 } 57 }
58 58
59 void reset(size_t column) { 59 void reset(size_t column) {
60 ((*m_bits)[column / 8]) &= ~(uint8_t(1) << (column % 8)); 60 ((*m_bits)[column >> 3]) &= ~(uint8_t(1) << (column & 0x07));
61 } 61 }
62 62
63 void copy(size_t source, size_t dest) { 63 void copy(size_t source, size_t dest) {
64 get(source) ? set(dest) : reset(dest); 64 get(source) ? set(dest) : reset(dest);
65 } 65 }