Skip to content

Commit bc24566

Browse files
authored
Add LCP check to fix toString in SuffixArray (#421)
When toString() was invoked just after creating the Suffix Array data structure, it gave null pointer exception when accessing actual array data member (sa) as the Suffix array and LCP array were not yet constructed. Added a check to see if LCP was constructed before printing out the data members and construct them if needed.
1 parent 1b17e3a commit bc24566

File tree

1 file changed

+1
-0
lines changed
  • src/main/java/com/williamfiset/algorithms/datastructures/suffixarray

1 file changed

+1
-0
lines changed

src/main/java/com/williamfiset/algorithms/datastructures/suffixarray/SuffixArray.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ private void kasai() {
8888

8989
@Override
9090
public String toString() {
91+
if (!constructedLcpArray) buildLcpArray();
9192
StringBuilder sb = new StringBuilder();
9293
sb.append("-----i-----SA-----LCP---Suffix\n");
9394

0 commit comments

Comments
 (0)