Program Listing for File factorizer_helpers.hpp

Return to documentation for file (src/cpp/factorizer_helpers.hpp)

#pragma once
#include <sdsl/suffix_trees.hpp>

namespace noLZSS {

using cst_t = sdsl::cst_sada<>;

inline size_t lcp(const cst_t& cst, size_t i, size_t j) {
    if (i == j) return cst.csa.size() - cst.csa[i];
    auto lca = cst.lca(cst.select_leaf(cst.csa.isa[i]+1), cst.select_leaf(cst.csa.isa[j]+1));
    return cst.depth(lca);
}

inline cst_t::node_type next_leaf(const cst_t& cst, cst_t::node_type lambda, size_t iterations = 1) {
    auto lambda_rank = cst.lb(lambda);
    for (size_t i = 0; i < iterations; i++) {
        lambda_rank = cst.csa.psi[lambda_rank];
    }
    return cst.select_leaf(lambda_rank + 1);
}

} // namespace noLZSS