1 #ifndef OST_MOL_ALG_ADJACENCY_BITMAP_HH
2 #define OST_MOL_ALG_ADJACENCY_BITMAP_HH
5 #include <boost/shared_ptr.hpp>
15 namespace ost {
namespace mol {
namespace alg {
31 num_vertices_(n_vertices),
32 storage_size_(StorageSize(n_vertices))
35 end_ = data_+storage_size_*num_vertices_;
43 num_vertices_(
end-start),
44 storage_size_(StorageSize(
end-start)),
46 end_(data_+storage_size_*num_vertices_) {
48 for (
int i = start; i <
end; ++i) {
49 this->
set(i-start, i-start,
false,
false);
50 for (
int j = i+1; j <
end; ++j) {
53 bool defined = da>=0 && db>=0 && (db < radius || da < radius);
56 agree = std::abs(da-db)<threshold;
65 num_vertices_(sim.GetSize()),
66 storage_size_(StorageSize(sim.GetSize())),
68 end_(data_+storage_size_*num_vertices_) {
70 for (
int i = 0; i < sim.
GetSize(); ++i) {
71 this->
set(i, i,
false,
false);
72 for (
int j = i+1; j < sim.
GetSize(); ++j) {
73 this->
set(i, j, sim.
Get(i, j)>threshold, sim.
Get(i, j)>=0.0);
74 this->
set(j, i, sim.
Get(i, j)>threshold, sim.
Get(i, j)>=0.0);
80 num_vertices_(rhs.num_vertices_),
81 storage_size_(rhs.storage_size_),
83 end_(data_+storage_size_*num_vertices_) {
84 memcpy(data_, rhs.data_, this->num_bytes());
96 void set(
size_t i,
size_t j,
bool val,
bool defined=
true) {
97 size_t byte_index = i*storage_size_ + j/(4*
sizeof(
uint64_t));
99 size_t bit_index = (2*j) % BITS;
104 assert(bit_index <
sizeof(
uint64_t)*8);
107 data_[byte_index] |= (one << bit_index);
109 data_[byte_index] &= ~(one << bit_index);
113 data_[byte_index] |= (two << bit_index);
115 data_[byte_index] &= ~(two << bit_index);
119 bool get(
size_t i,
size_t j)
const {
121 size_t byte_index = i*storage_size_ + j/(4*
sizeof(
uint64_t));
122 assert(byte_index < storage_size_*num_vertices_);
123 size_t bit_index = (2*j) % BITS;
124 assert(bit_index <
sizeof(
uint64_t)*8);
125 return data_[byte_index] & (one << bit_index);
130 size_t byte_index = i*storage_size_ + j/(4*
sizeof(
uint64_t));
131 assert(byte_index < storage_size_*num_vertices_);
132 size_t bit_index = (2*j) % BITS;
133 assert(bit_index <
sizeof(
uint64_t)*8);
134 return data_[byte_index] & (two << bit_index);
138 return num_vertices_;
142 return storage_size_*num_vertices_*
sizeof(
uint64_t);
150 const static size_t BITS=
sizeof(
uint64_t)*8;
151 size_t num_vertices_;
152 size_t storage_size_;
156 static const uint8_t NUMBER_OF_BITS_SET[];
157 static const uint8_t NUMBER_OF_EDGES_SET[];
158 static size_t StorageSize(
size_t verts) {
const T & Get(int i, int j) const
bool defined(size_t i, size_t j) const
AdjacencyBitmap(const DistanceMatrix &dmat_a, const DistanceMatrix &dmat_b, Real threshold, Real radius, int start, int end)
void set(size_t i, size_t j, bool val, bool defined=true)
bool get(size_t i, size_t j) const
AdjacencyBitmap(size_t n_vertices)
OverlapResult Overlap(size_t vert_i, size_t vert_j) const
AdjacencyBitmap(const SimilarityMatrix &sim, Real threshold)
AdjacencyBitmap(const AdjacencyBitmap &rhs)
pointer_it< T > end(const std::vector< T > &values)
unsigned __int64 uint64_t
OverlapResult(uint16_t nom, uint16_t denom, uint16_t def)