Skip to content

Commit

Permalink
Fix matchfinder limitation
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuel-marty authored Jun 25, 2019
1 parent efdeab3 commit 6f80894
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/lz4ultra.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#define OPT_INDEP_BLOCKS 8
#define OPT_LEGACY_FRAMES 16

#define TOOL_VERSION "1.2.1"
#define TOOL_VERSION "1.2.2"

/*---------------------------------------------------------------------------*/

Expand Down
20 changes: 7 additions & 13 deletions src/matchfinder.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,33 +197,27 @@ static int lz4ultra_find_matches_at(lz4ultra_compressor *pCompressor, const int
/* Ascend until we reach a visited interval, the root, or a child of the
* root. Link unvisited intervals to the current suffix as we go. */
while ((super_ref = intervals[ref & POS_MASK]) & LCP_MASK) {
intervals[ref & POS_MASK] = nOffset;
intervals[ref & POS_MASK] = nOffset | VISITED_FLAG;
ref = super_ref;
}

if (super_ref == 0) {
/* In this case, the current interval may be any of:
* (1) the root;
* (2) an unvisited child of the root;
* (3) an interval last visited by suffix 0
*
* We could avoid the ambiguity with (3) by using an lcp
* placeholder value other than 0 to represent "visited", but
* it's fastest to use 0. So we just don't allow matches with
* position 0. */
* (2) an unvisited child of the root */

if (ref != 0) /* Not the root? */
intervals[ref & POS_MASK] = nOffset;
intervals[ref & POS_MASK] = nOffset | VISITED_FLAG;
return 0;
}

/* Ascend indirectly via pos_data[] links. */
match_pos = super_ref;
match_pos = super_ref & EXCL_VISITED_MASK;
matchptr = pMatches;
for (;;) {
while ((super_ref = pos_data[match_pos]) > ref)
match_pos = intervals[super_ref & POS_MASK];
intervals[ref & POS_MASK] = nOffset;
match_pos = intervals[super_ref & POS_MASK] & EXCL_VISITED_MASK;
intervals[ref & POS_MASK] = nOffset | VISITED_FLAG;
pos_data[match_pos] = (unsigned long long)ref;

if ((matchptr - pMatches) < nMaxMatches) {
Expand All @@ -239,7 +233,7 @@ static int lz4ultra_find_matches_at(lz4ultra_compressor *pCompressor, const int
if (super_ref == 0)
break;
ref = super_ref;
match_pos = intervals[ref & POS_MASK];
match_pos = intervals[ref & POS_MASK] & EXCL_VISITED_MASK;
}

return (int)(matchptr - pMatches);
Expand Down
2 changes: 2 additions & 0 deletions src/shrink_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#define LCP_SHIFT (39-LCP_BITS)
#define LCP_MASK (((1ULL<<LCP_BITS) - 1) << LCP_SHIFT)
#define POS_MASK ((1ULL<<LCP_SHIFT) - 1)
#define VISITED_FLAG 0x8000000000ULL
#define EXCL_VISITED_MASK 0x7fffffffffULL

#define NMATCHES_PER_OFFSET 8
#define MATCHES_PER_OFFSET_SHIFT 3
Expand Down

0 comments on commit 6f80894

Please sign in to comment.