Function noLZSS::detail::find_longest_rc_match

Function Documentation

inline RcMatchResult noLZSS::detail::find_longest_rc_match(const cst_t &cst, const sdsl::rmq_succinct_sct<> &rmqF, const sdsl::rmq_succinct_sct<> &rmqRcEnd, const sdsl::int_vector<64> &fwd_starts, const sdsl::int_vector<64> &rc_ends, uint64_t INF, const RangePredecessor *predF, const RangePredecessor *predR, RefPolicy ref_policy, cst_t::node_type lambda, size_t lambda_node_depth, size_t i)

Finds the longest non-overlapping previous occurrence (forward or reverse complement) of the suffix at position i.

Shared by nolzss_multiple_dna_w_rc() and ParallelFactorizer::factorize_dna_w_rc_thread() so that both paths select factors identically.

The walk goes from the shallowest non-root ancestor of the current leaf toward the leaf. At each node v (string depth ell) it inspects

  • the earliest forward start jF in v’s SA interval (via rmqF): usable if jF + ell - 1 < i, and

  • the earliest reverse-complement end endRC in v’s SA interval (via rmqRcEnd): usable if endRC < i. Both conditions are monotone along the path (min start / min end never decrease with depth), so the walk stops as soon as neither holds.

Forward “partial-edge” candidate: the first node c whose earliest start jF overlaps i (jF + ell - 1 >= i, jF < i) still provides a non-overlapping match of length i - jF, because every leaf of c shares at least ell > i - jF characters with the suffix at i. This is the case the base algorithm handles on the edge between the last fitting ancestor and c, and it can be longer than the deepest fully fitting node. Reverse-complement matches need no such treatment: their non-overlap test (endRC < i) does not depend on the match length, so the deepest usable node already yields the longest RC match.

Tie-breaking (RefPolicy::First): at equal length a forward match wins over an RC match, and an RC match must be strictly longer than a literal (length >= 2) to be used. Among forward candidates of equal length the earliest start wins; among RC candidates the earliest end wins.

RefPolicy::Last keeps the same lengths but reports the closest occurrence instead. The forward candidates of a node-aligned match (length == depth of the best forward node vF) are exactly the suffixes in vF’s interval, so the closest one is the largest start <= i - len in that interval (predF). The RC match length always equals the depth of the best RC node vR (its minimum-end leaf cannot lie in a deeper usable node), so the closest RC occurrence is the largest end <= i - 1 in vR’s interval (predR). A partial-edge forward candidate has a single valid reference and needs no query. At equal length the strand whose occurrence ends closest to i wins; if both end at the same position (an occurrence equal to its own reverse complement) the forward match wins.

Parameters:
  • cst – Compressed suffix tree over the prepared string S = T sentinel rc(T) sentinel

  • rmqF – RMQ over fwd_starts

  • rmqRcEnd – RMQ over rc_ends

  • fwd_starts – Per-SA-rank forward start in T (INF for suffixes outside T)

  • rc_ends – Per-SA-rank mapped end in T of RC suffixes (INF for suffixes outside the RC part)

  • INF – Marker used in fwd_starts / rc_ends

  • predF – Range-predecessor index over fwd_starts (nullptr unless ref_policy is Last)

  • predR – Range-predecessor index over rc_ends (nullptr unless ref_policy is Last)

  • ref_policy – Reference selection policy

  • lambda – Leaf of the suffix starting at S position i

  • lambda_node_depth – Node depth of lambda

  • i – Current position (0-based in T)

Returns:

The factor length and reference to emit at position i