36 template <
typename pattern_type,
typename fm_index_type,
typename delegate_type>
40 const pattern_type pattern,
42 const fm_index_type f_index,
43 const fm_index_type r_index,
44 delegate_type& handler,
48 typedef typename fm_index_type::index_type coord_type;
49 typedef typename fm_index_type::range_type range_type;
51 uint4 right_mems[1024];
59 range_type f_range =
make_vector( coord_type(0u), f_index.length() );
60 range_type r_range =
make_vector( coord_type(0u), r_index.length() );
62 range_type prev_range = f_range;
65 for (i = x; i < pattern_len; ++i)
67 const uint8 c = pattern[i];
78 if (1u + f_range.y - f_range.x < min_intv)
82 if (f_range.y - f_range.x != prev_range.y - prev_range.x)
86 right_ranges.
push_back(
make_vector( prev_range.x, prev_range.y, coord_type(x), coord_type(i) ) );
92 if (right_ranges.
size() && (right_ranges.
back().y - right_ranges.
back().x) != (prev_range.y - prev_range.x))
93 right_ranges.
push_back(
make_vector( prev_range.x, prev_range.y, coord_type(x), coord_type(i) ) );
97 if (right_ranges.
size() == 0u)
101 const uint32 rightmost_base = right_ranges.
back().w;
115 uint32 leftmost_coordinate = x+1;
117 for (
int32 j = right_ranges.
size()-1; j >= 0; --j)
119 range_type f_range =
make_vector( right_ranges[j].x, right_ranges[j].y );
120 const uint32 r = right_ranges[j].w;
123 const fm_index_type& index = f_index;
127 for (l =
int32(x) - 1; l >= 0; --l)
129 const uint8 c = pattern[l];
134 const range_type c_rank =
rank(
140 index.L2(c) + c_rank.x + 1,
141 index.L2(c) + c_rank.y );
144 if (1u + new_range.y - new_range.x < min_intv)
152 if (
uint32(l+1) < leftmost_coordinate &&
uint32(l+1) < r)
155 const uint2 pattern_span = make_uint2(
uint32(l+1), r );
158 if (pattern_span.y - pattern_span.x >= min_span)
161 handler.output( f_range, pattern_span );
164 leftmost_coordinate =
uint32(l+1);
170 return rightmost_base;
177 template <
typename pattern_type,
typename fm_index_type,
typename delegate_type>
181 const pattern_type pattern,
183 const fm_index_type f_index,
184 const fm_index_type r_index,
185 delegate_type& handler,
189 typedef typename fm_index_type::index_type coord_type;
190 typedef typename fm_index_type::range_type range_type;
202 range_type f_range =
make_vector( coord_type(0u), f_index.length() );
203 range_type r_range =
make_vector( coord_type(0u), r_index.length() );
205 range_type prev_range = f_range;
208 for (i = x; i < pattern_len; ++i)
210 const uint8 c = pattern[i];
213 prev_range = f_range;
221 if (1u + f_range.y - f_range.x < min_intv)
225 if (f_range.y - f_range.x != prev_range.y - prev_range.x)
231 prev_range = f_range;
235 if (curr.
size() && (curr.
back().y - curr.
back().x) != (prev_range.y - prev_range.x))
245 if (prev.
size() == 0u)
257 const uint8 c = i < 0 ? 4u : pattern[i];
262 for (
int32 j = prev.
size()-1; j >= 0; --j)
264 const range_type f_range =
make_vector( prev[j].x, prev[j].y );
265 const uint32 r_span = prev[j].w;
268 const range_type c_rank = c < 4u ?
273 f_index.L2(c) + c_rank.x + 1,
274 f_index.L2(c) + c_rank.y );
277 if (c > 3u || c_rank.y - c_rank.x < min_intv)
280 if (curr.
size() == 0)
282 if (out_n == 0 || i+1 < out_i)
285 const uint2 pattern_span = make_uint2( i+1, r_span );
288 if (pattern_span.y - pattern_span.x >= min_span)
291 handler.output( f_range, pattern_span );
299 else if (curr.
size() == 0 || (new_range.y - new_range.x) != (curr.
back().y - curr.
back().x))
306 coord_type( r_span ) ) );
310 if (curr.
size() == 0)
320 return rightmost_base;
326 template <
typename rank_type>
337 template <
typename rank_type>
348 template <
typename rank_type>
357 return (range.w >> 16u) - (range.w & 0xFFu);
362 template <
typename coord_type>
385 if (1u + range.y - range.x <=
max_intv)
400 template <
typename index_type,
typename string_set_type>
410 const index_type _f_index,
411 const index_type _r_index,
412 const string_set_type _string_set,
439 for (
uint32 x = 0; x < pattern_len;)
463 output[i] = handler.
mems[ handler.
n_mems - i - 1u ];
481 template <
typename pattern_type,
typename fm_index_type,
typename output_vector>
485 const pattern_type pattern,
488 const fm_index_type f_index,
489 const fm_index_type r_index,
490 output_vector& output,
493 typedef typename fm_index_type::index_type coord_type;
494 typedef typename fm_index_type::range_type range_type;
505 range_type f_range =
make_vector( coord_type(0u), f_index.length() );
506 range_type r_range =
make_vector( coord_type(0u), r_index.length() );
508 range_type prev_range = f_range;
511 for (i = x; i < pattern_len; ++i)
513 const uint8 c = pattern[i];
516 prev_range = f_range;
524 if (1u + f_range.y - f_range.x < min_intv)
528 if (f_range.y - f_range.x != prev_range.y - prev_range.x)
532 mems_vec.
push_back( mem_type( prev_range, string_id, x, i ) );
534 prev_range = f_range;
538 if (mems_vec.
size() && (mems_vec.
back().range().y - mems_vec.
back().range().x) != (prev_range.y - prev_range.x))
539 mems_vec.
push_back( mem_type( prev_range, string_id, x, i ) );
542 if (mems_vec.
size() == 0u)
548 mem_type mem = mems_vec[ mems_vec.
size() - i - 1u ];
552 mem.set_group_flag();
558 return mems_vec.
back().span().y;
561 template <
typename index_type,
typename string_set_type>
571 const index_type _f_index,
572 const index_type _r_index,
573 const string_set_type _string_set,
601 for (
uint32 x = 0; x < pattern_len;)
623 output[i] = mems_vec[i];
637 template <
typename index_type,
typename string_set_type>
647 const index_type _f_index,
648 const index_type _r_index,
649 const string_set_type _string_set,
651 const uint32 _split_width,
687 for (
uint32 group_begin = 0; group_begin < n_mems;)
694 for (group_end = group_begin; group_end < n_mems; ++group_end)
696 const mem_type mem = in_mems[ group_end ];
698 if (max <= mem.
span().y - mem.
span().x)
703 if (group_end > group_begin && mem.
group_flag())
708 for (
uint32 i = group_begin; i < group_end; ++i)
733 group_begin = group_end;
736 for (
uint32 i = 0; i < n_mems; ++i)
765 output[i] = mems_vec[i];
784 template <
typename index_type,
typename string_set_type>
798 const index_type _f_index,
799 const index_type _r_index,
800 const string_set_type _string_set,
824 const index_type& index =
f_index;
828 for (l =
int32(x) - 1; l >= 0; --l)
830 const uint8 c = pattern[l];
841 index.L2(c) + c_rank.x + 1,
842 index.L2(c) + c_rank.y );
845 if (1u + new_range.y - new_range.x <
min_intv)
855 make_uint2( l+1, r ),
867 template <
typename coord_type>
899 const uint64 base_slot = slot ?
slots[ slot-1 ] : 0u;
900 const uint32 local_index = output_index - base_slot;
905 coord_type( range.
range().x + local_index ),
917 template <
typename index_type>
948 template <
typename index_type>
979 template <
typename rank_type>
988 const uint32 i = threadIdx.x + blockIdx.x * blockDim.x;
994 rank_type* vec = ranges[i];
1002 for (
uint32 j = 0; j < vec_size; ++j)
1004 rank_type
rank = vec[j];
1007 if (rank.group_flag())
1012 for (
uint32 k = 0; k < (n_output - group_begin)/2; ++k)
1014 const rank_type tmp = vec[ group_begin + k ];
1015 vec[ group_begin + k ] = vec[ n_output - k - 1u ];
1016 vec[ n_output - k - 1u ] = tmp;
1021 leftmost_coordinate =
uint32(-1);
1024 group_begin = n_output;
1027 const uint2 range = rank.range();
1028 const uint2 span = rank.span();
1031 if (span.x < leftmost_coordinate &&
1032 span.y - span.x >= min_span &&
1033 1u + range.y - range.x <= max_intv)
1036 if (leftmost_coordinate ==
uint32(-1))
1037 rank.set_group_flag();
1040 vec[ n_output++ ] =
rank;
1043 leftmost_coordinate = span.x;
1052 template <
typename rank_type>
1061 const uint32 block_dim = 128;
1064 discard_ranges_kernel<<<n_blocks,block_dim>>>(
1073 thrust::device_vector<uint8> d_temp_storage;
1081 thrust::plus<uint32>(),
1085 ranges.
m_pool[0] = n_ranges;
1090 template <
typename rank_type>
1098 const uint32 slot = slots[i];
1101 const rank_type* src = in_ranges[i];
1102 rank_type* dst = out_ranges + slot;
1104 for (
uint32 j = 0; j < n_src; ++j)
1109 template <
typename rank_type>
1117 const uint32 i = threadIdx.x + blockIdx.x * blockDim.x;
1125 template <
typename rank_type>
1133 const uint32 block_dim = 128;
1136 reorder_ranges_kernel<<<n_blocks,block_dim>>>(
1143 template <
typename rank_type>
1151 #pragma omp parallel for
1152 for (
int i = 0; i < int( n_items ); ++i)
1166 template <
typename fm_index_type>
1167 template <
typename string_set_type>
1169 const fm_index_type& f_index,
1170 const fm_index_type& r_index,
1171 const string_set_type& string_set,
1176 const uint32 split_width)
1179 m_n_queries = string_set.size();
1180 m_f_index = f_index;
1181 m_r_index = r_index;
1182 m_n_occurrences = 0;
1184 const uint32 max_string_length = 256;
1186 m_mem_ranges.resize( m_n_queries, max_string_length * m_n_queries );
1190 thrust::make_counting_iterator<uint32>(0u),
1191 thrust::make_counting_iterator<uint32>(0u) + m_n_queries,
1203 const uint32 n_ranges = m_mem_ranges.allocated_size();
1206 m_slots.resize( n_ranges );
1211 thrust::host_vector<rank_type> arena( n_ranges );
1212 thrust::host_vector<uint32> slots( m_n_queries );
1216 m_mem_ranges.m_sizes.begin(),
1217 m_mem_ranges.m_sizes.begin() + m_n_queries,
1229 m_mem_ranges.m_index.swap( slots );
1230 m_mem_ranges.m_arena.swap( arena );
1239 m_n_occurrences = m_slots[ n_ranges - 1u ];
1241 return m_n_occurrences;
1246 template <
typename fm_index_type>
1250 if (string_id >= m_n_queries)
1251 return m_n_occurrences;
1256 return first_rank ? m_slots[ first_rank-1u ] : 0u;
1266 template <
typename fm_index_type>
1267 template <
typename mems_iterator>
1276 const uint32 n_ranges = m_mem_ranges.allocated_size();
1280 thrust::make_counting_iterator<uint64>(0u) + begin,
1281 thrust::make_counting_iterator<uint64>(0u) + end,
1310 template <
typename fm_index_type>
1311 template <
typename string_set_type>
1313 const fm_index_type& f_index,
1314 const fm_index_type& r_index,
1315 const string_set_type& string_set,
1320 const uint32 split_width)
1323 m_n_queries = string_set.size();
1324 m_f_index = f_index;
1325 m_r_index = r_index;
1326 m_n_occurrences = 0;
1328 const uint32 max_string_length = 256;
1330 m_mem_ranges.resize( m_n_queries, max_string_length * m_n_queries );
1335 thrust::make_counting_iterator<uint32>(0u),
1336 thrust::make_counting_iterator<uint32>(0u) + m_n_queries,
1348 const uint32 n_ranges = m_mem_ranges.allocated_size();
1352 m_mem_ranges.m_arena.begin(),
1353 m_mem_ranges.m_arena.begin() + n_ranges,
1354 m_mem_ranges.m_arena.begin(),
1364 const bool do_split = split_len <
uint32(-1);
1373 do_split ?
false :
true );
1380 m_mem_ranges.
swap( unsplit_mem_ranges );
1381 m_mem_ranges.
resize( m_n_queries, max_string_length * m_n_queries );
1384 thrust::make_counting_iterator<uint32>(0u),
1385 thrust::make_counting_iterator<uint32>(0u) + m_n_queries,
1400 const uint32 n_ranges = m_mem_ranges.allocated_size();
1404 m_mem_ranges.m_arena.begin(),
1405 m_mem_ranges.m_arena.begin() + n_ranges,
1406 m_mem_ranges.m_arena.begin(),
1428 const uint32 n_ranges = m_mem_ranges.allocated_size();
1431 m_slots.resize( n_ranges );
1436 thrust::device_vector<rank_type> arena( n_ranges );
1437 thrust::device_vector<uint32> slots( m_n_queries );
1442 m_mem_ranges.m_sizes.begin(),
1444 thrust::plus<uint32>(),
1457 m_mem_ranges.m_index.swap( slots );
1458 m_mem_ranges.m_arena.swap( arena );
1465 thrust::plus<uint64>(),
1469 m_n_occurrences = m_slots[ n_ranges - 1u ];
1471 return m_n_occurrences;
1476 template <
typename fm_index_type>
1480 if (string_id >= m_n_queries)
1481 return m_n_occurrences;
1486 return first_rank ? m_slots[ first_rank-1u ] : 0u;
1497 template <
typename fm_index_type>
1498 template <
typename mems_iterator>
1507 const uint32 n_ranges = m_mem_ranges.allocated_size();
1511 thrust::make_counting_iterator<uint64>(0u) + begin,
1512 thrust::make_counting_iterator<uint64>(0u) + end,
1536 template <
typename system_tag,
typename fm_index_type>
1540 thrust::make_permutation_iterator(
1541 filter.m_slots.begin(),
1542 filter.m_mem_ranges.m_index.begin() ),
1543 thrust::make_permutation_iterator(
1544 filter.m_slots.begin(),
1545 filter.m_mem_ranges.m_index.begin() ) + filter.m_n_queries,
1546 mem_count ) - thrust::make_permutation_iterator(
1547 filter.m_slots.begin(),
1548 filter.m_mem_ranges.m_index.begin() ) );