rd5 delta progress
This commit is contained in:
parent
c4f3e7dadf
commit
19a7555483
4 changed files with 468 additions and 46 deletions
|
|
@ -366,4 +366,38 @@ public class MicroCache extends ByteDataWriter
|
|||
}
|
||||
}
|
||||
|
||||
public void addDelta( MicroCache mc1, MicroCache mc2, boolean keepEmptyNodes )
|
||||
{
|
||||
int idx1 = 0;
|
||||
int idx2 = 0;
|
||||
|
||||
while( idx1 < mc1.size || idx2 < mc2.size )
|
||||
{
|
||||
int id1 = idx1 < mc1.size ? mc1.faid[idx1] : Integer.MAX_VALUE;
|
||||
int id2 = idx2 < mc2.size ? mc2.faid[idx2] : Integer.MAX_VALUE;
|
||||
if ( id1 >= id2 ) // data from diff file wins
|
||||
{
|
||||
int start2 = idx2 > 0 ? mc2.fapos[idx2 - 1] : 0;
|
||||
int len2 = mc2.fapos[idx2++] - start2;
|
||||
if ( keepEmptyNodes || len2 > 0 )
|
||||
{
|
||||
write( mc2.ab, start2, len2 );
|
||||
fapos[size] = aboffset;
|
||||
faid[size++] = id2;
|
||||
}
|
||||
if ( id1 == id2 ) // // id exists in both caches
|
||||
{
|
||||
idx1++;
|
||||
}
|
||||
}
|
||||
else // use data from base file
|
||||
{
|
||||
int start1 = idx1 > 0 ? mc1.fapos[idx1 - 1] : 0;
|
||||
int len1 = mc1.fapos[idx1++] - start1;
|
||||
write( mc1.ab, start1, len1 );
|
||||
fapos[size] = aboffset;
|
||||
faid[size++] = id1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -266,6 +266,25 @@ public final class TagValueCoder
|
|||
return -1;
|
||||
if ( tvs1.frequency > tvs2.frequency )
|
||||
return 1;
|
||||
|
||||
// to avoid ordering instability, decide on the data
|
||||
// if frequency is equal
|
||||
int l1 = tvs1.data == null ? 0 : tvs1.data.length;
|
||||
int l2 = tvs2.data == null ? 0 : tvs2.data.length;
|
||||
|
||||
if ( l1 < l2 )
|
||||
return -1;
|
||||
if ( l1 > l2 )
|
||||
return 1;
|
||||
for( int i=0; i<l1; i++ )
|
||||
{
|
||||
byte b1 = tvs1.data[i];
|
||||
byte b2 = tvs2.data[i];
|
||||
if ( b1 < b2 )
|
||||
return -1;
|
||||
if ( b1 > b2 )
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue