/usr/include/mathic/BitTriangle.h is in libmathic-dev 1.0~git20130827-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | #ifndef MATHIC_BIT_TRIANGLE_GUARD
#define MATHIC_BIT_TRIANGLE_GUARD
#include "stdinc.h"
#include <vector>
#include <memory>
namespace mathic {
// Object that stores a triangular 2-dimensional array of bits. For example:
//
// row
// 3|
// 2| 1
// 1| 0 1
// 0| 0 0 0
// -------
// 0 1 2 3 column
//
// A bit is addressed by a pair (column, row) where the column goes first.
// All valid address pairs have 0 <= row < column < columnCount().
// Columns can be added dynamically.
class BitTriangle {
public:
// Returns how many columns the triangle has
size_t columnCount() const {return mColumns.size();}
// Returns true if there are no columns in the triangle
bool empty() const {return mColumns.empty();}
// Adds a new column of the triangle. This increases columnCount() by
// one, and the index of the new column is the previous value of
// columnCount(). The new bits are all set to false initially.
void addColumn() {
size_t const oldSize = mColumns.size();
mColumns.resize(oldSize + 1);
mColumns[oldSize].resize(oldSize);
}
// Returns the bit in the given column and row. As this is a triangle it
// must be true that row < column.
MATHIC_INLINE bool bit(size_t column, size_t row) const {
MATHIC_ASSERT(column < columnCount());
MATHIC_ASSERT(row < column);
return mColumns[column][row];
}
// As bit(), but uses max(x,y) as the column and min(x,y) as the
// row.
bool bitUnordered(size_t x, size_t y) const {
MATHIC_ASSERT(x < columnCount());
MATHIC_ASSERT(y < columnCount());
MATHIC_ASSERT(x != y);
if (x < y)
std::swap(x, y);
return bit(x, y);
}
// Sets the bit in the given column and row. As this is a triangle
// it must be true that column >= row.
MATHIC_INLINE void setBit(size_t column, size_t row, bool value) {
MATHIC_ASSERT(column < columnCount());
MATHIC_ASSERT(row < column);
mColumns[column][row] = value;
}
// As setBit, but uses max(x,y) as the column and min(x,y) as the
// row.
void setBitUnordered(size_t x, size_t y, bool value) {
MATHIC_ASSERT(x < columnCount());
MATHIC_ASSERT(y < columnCount());
MATHIC_ASSERT(x != y);
if (x < y)
std::swap(x, y);
setBit(x, y, value);
}
size_t getMemoryUse() const;
private:
// @todo: use one big array instead of an array of arrays.
std::vector<std::vector<bool> > mColumns;
};
}
#endif
|