Skip to content

Commit

Permalink
Tweaks to LCPArray::depth()
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouni Siren committed Mar 16, 2016
1 parent 7ef2c1f commit b433cc2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,19 @@ LCPArray::depth(const LCPArray::node_type& node) const
return this->depth(node.range());
}

size_type
LCPArray::depth(LCPArray::node_type& node) const
{
if(node.lcp() == node_type::UNKNOWN) { node.node_lcp = this->depth(node.range()); }
return node.lcp();
}

size_type
LCPArray::depth(range_type range) const
{
if(Range::length(range) <= 1 || this->root() == range) { return 0; }
return this->rmq(range.first + 1, range.second).second;
if(Range::length(range) <= 1) { return node_type::UNKNOWN; }
range_type res = this->rmq(range.first + 1, range.second);
return (res == this->notFound() ? node_type::UNKNOWN : res.second);
}

//------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions lcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class LCPArray
// String depth of the node; the length of the longest pattern matching the range.
// Not supported for leaf nodes / ranges of length 1.
size_type depth(const node_type& node) const;
size_type depth(node_type& node) const;
size_type depth(range_type range) const;

//------------------------------------------------------------------------------
Expand Down

0 comments on commit b433cc2

Please sign in to comment.