1#ifndef BMTRANS__H__INCLUDED__
2#define BMTRANS__H__INCLUDED__
26#pragma warning( push )
27#pragma warning( disable : 4311 4312 4127)
39template<
typename T,
unsigned ROWS,
unsigned COLS>
67 return value[row_idx];
72 return value[row_idx];
81template<
typename T,
unsigned BPC>
85 unsigned get(
const T*,
unsigned)
95 unsigned get(
const unsigned* arr,
unsigned j)
97 return (((arr[0] >> j) & 1) << 0) |
98 (((arr[1] >> j) & 1) << 1) |
99 (((arr[2] >> j) & 1) << 2) |
100 (((arr[3] >> j) & 1) << 3) |
101 (((arr[4] >> j) & 1) << 4) |
102 (((arr[5] >> j) & 1) << 5) |
103 (((arr[6] >> j) & 1) << 6) |
104 (((arr[7] >> j) & 1) << 7) |
105 (((arr[8] >> j) & 1) << 8) |
106 (((arr[9] >> j) & 1) << 9) |
107 (((arr[10]>> j) & 1) << 10)|
108 (((arr[11]>> j) & 1) << 11)|
109 (((arr[12]>> j) & 1) << 12)|
110 (((arr[13]>> j) & 1) << 13)|
111 (((arr[14]>> j) & 1) << 14)|
112 (((arr[15]>> j) & 1) << 15)|
113 (((arr[16]>> j) & 1) << 16)|
114 (((arr[17]>> j) & 1) << 17)|
115 (((arr[18]>> j) & 1) << 18)|
116 (((arr[19]>> j) & 1) << 19)|
117 (((arr[20]>> j) & 1) << 20)|
118 (((arr[21]>> j) & 1) << 21)|
119 (((arr[22]>> j) & 1) << 22)|
120 (((arr[23]>> j) & 1) << 23)|
121 (((arr[24]>> j) & 1) << 24)|
122 (((arr[25]>> j) & 1) << 25)|
123 (((arr[26]>> j) & 1) << 26)|
124 (((arr[27]>> j) & 1) << 27)|
125 (((arr[28]>> j) & 1) << 28)|
126 (((arr[29]>> j) & 1) << 29)|
127 (((arr[30]>> j) & 1) << 30)|
128 (((arr[31]>> j) & 1) << 31);
136 unsigned get(
const unsigned short* arr,
unsigned j)
138 return (((arr[0] >> j) & 1u) << 0u) |
139 (((arr[1] >> j) & 1u) << 1u) |
140 (((arr[2] >> j) & 1u) << 2u) |
141 (((arr[3] >> j) & 1u) << 3u) |
142 (((arr[4] >> j) & 1u) << 4u) |
143 (((arr[5] >> j) & 1u) << 5u) |
144 (((arr[6] >> j) & 1u) << 6u) |
145 (((arr[7] >> j) & 1u) << 7u) |
146 (((arr[8] >> j) & 1u) << 8u) |
147 (((arr[9] >> j) & 1u) << 9u) |
148 (((arr[10]>> j) & 1u) << 10u)|
149 (((arr[11]>> j) & 1u) << 11u)|
150 (((arr[12]>> j) & 1u) << 12u)|
151 (((arr[13]>> j) & 1u) << 13u)|
152 (((arr[14]>> j) & 1u) << 14u)|
153 (((arr[15]>> j) & 1u) << 15u);
162 unsigned get(
const unsigned char* arr,
unsigned j)
165 (((arr[0] >> j) & 1) << 0) |
166 (((arr[1] >> j) & 1) << 1) |
167 (((arr[2] >> j) & 1) << 2) |
168 (((arr[3] >> j) & 1) << 3) |
169 (((arr[4] >> j) & 1) << 4) |
170 (((arr[5] >> j) & 1) << 5) |
171 (((arr[6] >> j) & 1) << 6) |
172 (((arr[7] >> j) & 1) << 7));
181template<
typename T,
unsigned BPC,
unsigned BPS>
195 (((
tmatrix[0][i] >> j) & 1) << 0) |
196 (((
tmatrix[1][i] >> j) & 1) << 1) |
197 (((
tmatrix[2][i] >> j) & 1) << 2) |
198 (((
tmatrix[3][i] >> j) & 1) << 3) |
199 (((
tmatrix[4][i] >> j) & 1) << 4) |
200 (((
tmatrix[5][i] >> j) & 1) << 5) |
201 (((
tmatrix[6][i] >> j) & 1) << 6) |
202 (((
tmatrix[7][i] >> j) & 1) << 7);
208 (((
tmatrix[8][i] >> j) & 1) << 8) |
209 (((
tmatrix[9][i] >> j) & 1) << 9) |
210 (((
tmatrix[10][i] >> j) & 1) << 10) |
211 (((
tmatrix[11][i] >> j) & 1) << 11) |
212 (((
tmatrix[12][i] >> j) & 1) << 12) |
213 (((
tmatrix[13][i] >> j) & 1) << 13) |
214 (((
tmatrix[14][i] >> j) & 1) << 14) |
215 (((
tmatrix[15][i] >> j) & 1) << 15);
222 (((
tmatrix[16][i] >> j) & 1) << 16) |
223 (((
tmatrix[17][i] >> j) & 1) << 17) |
224 (((
tmatrix[18][i] >> j) & 1) << 18) |
225 (((
tmatrix[19][i] >> j) & 1) << 19) |
226 (((
tmatrix[20][i] >> j) & 1) << 20) |
227 (((
tmatrix[21][i] >> j) & 1) << 21) |
228 (((
tmatrix[22][i] >> j) & 1) << 22) |
229 (((
tmatrix[23][i] >> j) & 1) << 23) |
230 (((
tmatrix[24][i] >> j) & 1) << 24) |
231 (((
tmatrix[25][i] >> j) & 1) << 25) |
232 (((
tmatrix[26][i] >> j) & 1) << 26) |
233 (((
tmatrix[27][i] >> j) & 1) << 27) |
234 (((
tmatrix[28][i] >> j) & 1) << 28) |
235 (((
tmatrix[29][i] >> j) & 1) << 29) |
236 (((
tmatrix[30][i] >> j) & 1) << 30) |
237 (((
tmatrix[31][i] >> j) & 1) << 31);
256template<
typename T,
unsigned BPC,
unsigned BPS>
264 for (
unsigned i = 0; i < arr_size;
268 for (
unsigned j = 0; j < BPC; ++j)
289template<
typename T,
unsigned BPC,
unsigned BPS>
294 for (
unsigned i = 0; i < BPS; ++i)
296 for (
unsigned j = 0; j < BPC; ++j, ++col)
314template<
typename T,
unsigned BPC,
unsigned BPS>
316 unsigned distance[BPC][BPC])
318 for (
unsigned i = 0; i < BPC; ++i)
324 for (
unsigned j = i + 1; j < BPC; ++j)
331 const T* r2_end = r2 + BPS;
340 }
while (r2 < r2_end);
342 distance[i][j] = count;
378template<
typename T,
unsigned BPC,
unsigned BPS>
380 const unsigned distance[BPC][BPC],
381 unsigned char* pc_vector)
385 for (
unsigned i = 0; i < BPC; ++i)
388 unsigned row_bitcount = distance[i][i];
390 const unsigned total_possible_max =
sizeof(T)*8*BPS;
391 switch (row_bitcount)
396 case total_possible_max:
404 if (row_bitcount > total_possible_max/2)
413 unsigned rmin_idx = 0;
414 for (
unsigned j = i + 1; j < BPC; ++j)
416 unsigned d = distance[i][j];
424 rmin = d; rmin_idx = j;
428 if ((pc == 0) && rmin_idx && (rmin < row_bitcount))
430 pc = (
unsigned char)(
ibpc_close | (rmin_idx << 3));
442 const unsigned char*
BMRESTRICT pc_vector_end,
450 unsigned ibpc = *pc_vector & 7;
451 ++(pc_vector_stat[ibpc]);
452 }
while (++pc_vector < pc_vector_end);
464 const unsigned char*
BMRESTRICT pc_vector_end,
471 unsigned ibpc = *pc_vector & 7;
472 unsigned n_row = *pc_vector >> 3;
478 const unsigned* r1 =
tmatrix[row];
479 unsigned* r_out = tmatrix_out[row];
494 const unsigned* r1 =
tmatrix[row];
495 const unsigned* r2 =
tmatrix[n_row];
496 unsigned* r_out = tmatrix_out[row];
499 r_out[i] = r1[i] ^ r2[i];
508 }
while (++pc_vector < pc_vector_end);
515template<
class TMatrix>
517 const unsigned char* pc_vector,
518 const unsigned effective_cols)
522 typedef typename TMatrix::value_type value_type;
524 const unsigned char* pc_vector_end = pc_vector +
tmatrix.
rows();
526 unsigned cols = effective_cols ? effective_cols :
tmatrix.
cols();
530 unsigned ibpc = *pc_vector & 7;
540 unsigned n_row = *pc_vector >> 3;
545 for (
unsigned i = 0; i < cols; ++i)
556 }
while (++pc_vector < pc_vector_end);
562template<
class TMatrix>
564 const unsigned char* pc_vector,
565 const unsigned effective_cols)
569 typedef typename TMatrix::value_type value_type;
571 unsigned cols = effective_cols ? effective_cols :
tmatrix.
cols();
574 unsigned ibpc = pc_vector[row] & 7u;
575 unsigned n_row = pc_vector[row] >> 3u;
584 for (
unsigned i = 0; i < cols; ++i)
588 for (
unsigned i = 0; i < cols; ++i)
589 r1[i] = (value_type)(~0);
595 for (
unsigned i = 0; i < cols; ++i)
603 for (
unsigned i = 0; i < cols; ++i)
624template<
typename GT,
typename BT>
629 GT* dgap_buf = (GT*) block;
630 BT* block_end = block + block_size;
632 GT* dgap_end = gap_2_dgap<GT>(gap_buf, dgap_buf,
false);
633 GT* block_end2 = (GT*) block_end;
636 for ( ;dgap_end < block_end2; ++dgap_end)
653template<
class TMatrix>
654void compute_tmatrix_rstat(
const TMatrix& tmatrix,
655 const unsigned char* pc_vector,
656 typename TMatrix::rstat* rstat,
657 unsigned effective_cols)
660 typedef typename TMatrix::value_type value_type;
662 unsigned cols = effective_cols ? effective_cols : tmatrix.cols();
664 unsigned rows = tmatrix.rows();
666 for (
unsigned i = 0; i < rows; ++i)
668 unsigned ibpc = pc_vector[i] & 7;
674 rstat[i].bit_count = rstat[i].gap_count = 0;
680 const value_type* r1 = tmatrix.row(i);
681 const value_type* r1_end = r1 + cols;
684 &rstat[i].bit_count, &rstat[i].gap_count);
686 const unsigned bitset_size = unsigned(
sizeof(value_type) * cols);
687 const unsigned total_possible_max_bits = unsigned(
sizeof(value_type)*8*cols);
691 total_possible_max_bits,
718 const typename TM::value_type* row =
tmatrix.value[i];
721 if (row[j] != 0 && j > col)
740template<
typename GT,
typename BT,
unsigned BLOCK_SIZE>
750 static_cast<unsigned>(((BLOCK_SIZE *
sizeof(unsigned)) / (
sizeof(GT)))
762 const unsigned arr_size = BLOCK_SIZE *
sizeof(unsigned) /
sizeof(GT);
771 vect_bit_transpose<GT, tmatrix_type::n_rows, tmatrix_type::n_columns>
772 ((GT*)tmp_block, arr_size,
tmatrix_.value);
787 ::memcpy(tmp_block, garr,
sizeof(GT)*garr_size);
789 const unsigned arr_size = BLOCK_SIZE *
sizeof(unsigned) /
sizeof(GT);
793 vect_bit_transpose<GT, tmatrix_type::n_rows, tmatrix_type::n_columns>
794 ((GT*)tmp_block, arr_size,
tmatrix_.value);
839 GT* gap_tmp = (GT*)tmp_block;
842 vect_bit_trestore<GT, tmatrix_type::n_rows, tmatrix_type::n_columns>(
tmatrix_.value, gap_tmp);
845 gap_tmp = (GT*)tmp_block;
846 dgap_2_gap<GT>(gap_tmp, gap_buf, gap_head);
864#pragma warning( pop )
Bit-plane splicing of a GAP block.
void compute_distance_matrix()
void transpose(const GT *BMRESTRICT garr, unsigned garr_size, BT *BMRESTRICT tmp_block)
Transpose array of shorts.
unsigned pc_vector_stat_[bm::ibpc_end]
tmatrix< GT, static_cast< unsigned >(sizeof(GT) *8), static_cast< unsigned >(((BLOCK_SIZE *sizeof(unsigned))/(sizeof(GT)))/(sizeof(GT) *8))> tmatrix_type
cryptic calculation of equivalent size for the transpose matrix based on BLOCK_SIZE and sizeof(GT)(16...
void trestore(GT gap_head, GT *BMRESTRICT gap_buf, BT *BMRESTRICT tmp_block)
Restore GAP block from the transposed matrix.
unsigned char pc_vector_[tmatrix_type::n_rows]
void transpose(const GT *BMRESTRICT gap_buf, BT *BMRESTRICT tmp_block)
Transpose GAP block through a temp.
tmatrix_type::rstat rstat_vector_[tmatrix_type::n_rows]
unsigned distance_[tmatrix_type::n_rows][tmatrix_type::n_rows]
BMFORCEINLINE bm::id_t word_bitcount(bm::id_t w) BMNOEXCEPT
bm::id_t bit_block_count(const bm::word_t *block) BMNOEXCEPT
Bitcount for bit block.
bm::set_representation best_representation(unsigned bit_count, unsigned total_possible_bitcount, unsigned gap_count, unsigned block_size) BMNOEXCEPT
Choose best representation for a bit-block.
void tmatrix_distance(const T tmatrix[BPC][BPS], unsigned distance[BPC][BPC])
Compute pairwise Row x Row Humming distances on planes(rows) of the transposed bit block.
void bit_block_set(bm::word_t *BMRESTRICT dst, bm::word_t value) BMNOEXCEPT
Bitblock memset operation.
void bit_iblock_make_pcv(const unsigned distance[BPC][BPC], unsigned char *pc_vector)
!< ibpc limiter
const unsigned set_block_plane_cnt
void gap_2_bitblock(const GT *BMRESTRICT gap_buf, BT *BMRESTRICT block, unsigned block_size)
Copy GAP block body to bit block with DGap transformation.
void tmatrix_reduce(TMatrix &tmatrix, const unsigned char *pc_vector, const unsigned effective_cols)
Transposed Matrix reduction based on transformation pc vector.
set_representation
set representation variants
@ set_bitset
Simple bitset.
unsigned find_effective_columns(const TM &tmatrix)
Compute effective right column border of the t-matrix.
const unsigned char ibpc_equiv
!< plane ALL ONE
void bit_iblock_reduce(const unsigned tmatrix[bm::set_block_plane_cnt][bm::set_block_plane_size], const unsigned char *BMRESTRICT pc_vector, const unsigned char *BMRESTRICT pc_vector_end, unsigned tmatrix_out[bm::set_block_plane_cnt][bm::set_block_plane_size])
Matrix reduction based on transformation pc vector.
void vect_bit_transpose(const T *arr, unsigned arr_size, T tmatrix[BPC][BPS])
Generic bit-array transposition function T - array type (any int) BPC - bit plane count BPS - bit pla...
void tmatrix_restore(TMatrix &tmatrix, const unsigned char *pc_vector, const unsigned effective_cols)
Transposed Matrix restore based on transformation pc vector.
void vect_bit_trestore(const T tmatrix[BPC][BPS], T *arr)
Restore bit array from the transposition matrix T - array type (any int) BPC - bit plane count BPS - ...
const unsigned char ibpc_close
!< plane is equal to plane M
const unsigned char ibpc_all_one
!< plane ALL ZERO
const unsigned char ibpc_all_zero
!< plane uncompressed
const unsigned set_block_plane_size
void bit_iblock_pcv_stat(const unsigned char *BMRESTRICT pc_vector, const unsigned char *BMRESTRICT pc_vector_end, unsigned *BMRESTRICT pc_vector_stat)
Compute number of ibpc codes in pc_vector.
const unsigned char ibpc_uncompr
const unsigned char ibpc_end
!< plane is close to plane M
static unsigned get(const unsigned *arr, unsigned j)
static unsigned get(const unsigned char *arr, unsigned j)
static unsigned get(const unsigned short *arr, unsigned j)
static unsigned get(const T *, unsigned)
static T get(const T tmatrix[BPC][BPS], unsigned i, unsigned j)
Row characteristics for transposed matrix.
bm::set_representation best_rep
Mini-matrix for bit transposition purposes.
static unsigned rows() BMNOEXCEPT
static unsigned cols() BMNOEXCEPT
T * row(unsigned row_idx) BMNOEXCEPT
T BM_VECT_ALIGN value[ROWS][COLS] BM_VECT_ALIGN_ATTR
const T * row(unsigned row_idx) const BMNOEXCEPT