lib/wavelet_tree/algorithms.cpp
// TODO(diego): Optimization. Some overloads of count_symbols generate children
// nodes even when its respective ranges are empty.
Optimization. Some overloads of count_symbols generate children
nodes even when its respective ranges are empty.
Optimization . Some overloads of count_symbols generate children nodes even when its respective ranges are empty .
static size_type count_symbols(node_proxy node, const index_range range) {
  assert(begin(range) >= 0 && end(range) <= node.size());
  if (empty(range)) {
    return 0;
  }
  const auto children_ranges = make_lhs_and_rhs_ranges(range, node);
  const auto& lhs_range = get_left(children_ranges);
  const auto& rhs_range = get_right(children_ranges);
  if (!node.is_leaf()) {
    if (empty(lhs_range)) {
      return count_symbols(node.make_rhs(), rhs_range);
    }
    if (empty(rhs_range)) {
      return count_symbols(node.make_lhs(), lhs_range);
    }
    const auto children = node.make_lhs_and_rhs();
    return count_symbols(get_left(children), lhs_range) +
           count_symbols(get_right(children), rhs_range);
  }
  return size_type{empty(lhs_range) ? 0 : 1} +
         size_type{empty(rhs_range) ? 0 : 1};
}
static size_type count_symbols ( node_proxy node , const index_range range ) { assert ( begin ( range ) >= 0 && end ( range ) <= node . size ( ) ) ; if ( empty ( range ) ) { return 0 ; } const auto children_ranges = make_lhs_and_rhs_ranges ( range , node ) ; const auto & lhs_range = get_left ( children_ranges ) ; const auto & rhs_range = get_right ( children_ranges ) ; if ( ! node . is_leaf ( ) ) { if ( empty ( lhs_range ) ) { return count_symbols ( node . make_rhs ( ) , rhs_range ) ; } if ( empty ( rhs_range ) ) { return count_symbols ( node . make_lhs ( ) , lhs_range ) ; } const auto children = node . make_lhs_and_rhs ( ) ; return count_symbols ( get_left ( children ) , lhs_range ) + count_symbols ( get_right ( children ) , rhs_range ) ; } return size_type { empty ( lhs_range ) ? 0 : 1 } + size_type { empty ( rhs_range ) ? 0 : 1 } ; }
TODO(diego): Optimization.
TODO ( diego ) : Optimization .