2013-12-19 00:52:02 +01:00
|
|
|
/*
|
|
|
|
* Array of bits.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of bits used for scheduling work.
|
|
|
|
*/
|
2013-12-27 21:35:37 +01:00
|
|
|
class MinBitArray {
|
|
|
|
public:
|
2013-12-19 00:52:02 +01:00
|
|
|
MinBitArray() : bits_(0) {}
|
|
|
|
|
|
|
|
/** Sets an individual bit. */
|
|
|
|
void set(int index) { check(index); bits_ |= 1 << index; }
|
|
|
|
|
|
|
|
bool is_empty() const { return bits_ == 0; }
|
|
|
|
/** Finds the lowest set bit, clears it, and returns the index. */
|
|
|
|
int8_t pop();
|
|
|
|
|
2013-12-27 21:35:37 +01:00
|
|
|
private:
|
2013-12-19 00:52:02 +01:00
|
|
|
int count() const { return sizeof(bits_)*8; }
|
|
|
|
|
2013-12-27 21:35:37 +01:00
|
|
|
void check(int index) {
|
2013-12-19 00:52:02 +01:00
|
|
|
assert(index >= 0 && index < count());
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t bits_;
|
|
|
|
};
|