Skip to content

Commit

Permalink
Renames for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
jzebedee committed Oct 17, 2014
1 parent 84ece2f commit 8806a01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
31 changes: 15 additions & 16 deletions deltaq/BsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ namespace deltaq
{
public static class BsPatch
{
public delegate Stream OpenDiffStream(long offset, long length);
public delegate Stream OpenPatchStream(long offset, long length);

public static void Apply(byte[] input, byte[] diff, Stream output)
{
OpenDiffStream openDiffStream = (uOffset, uLength) =>
OpenPatchStream openPatchStream = (uOffset, uLength) =>
{
//shaving down to int because we assume we're using 32bit indices
var offset = (int)uOffset;
var length = (int)uLength;
return new MemoryStream(diff, offset,
Expand All @@ -21,35 +20,35 @@ public static void Apply(byte[] input, byte[] diff, Stream output)
};

Stream controlStream, diffStream, extraStream;
var newSize = CreatePatchStreams(openDiffStream, out controlStream, out diffStream, out extraStream);
var newSize = CreatePatchStreams(openPatchStream, out controlStream, out diffStream, out extraStream);

// prepare to read three parts of the patch in parallel
ApplyInternal(newSize, new MemoryStream(input), controlStream, diffStream, extraStream, output);
}

public static void Apply(Stream input, OpenDiffStream openDiffStream, Stream output)
public static void Apply(Stream input, OpenPatchStream openPatchStream, Stream output)
{
Stream controlStream, diffStream, extraStream;
var newSize = CreatePatchStreams(openDiffStream, out controlStream, out diffStream, out extraStream);
var newSize = CreatePatchStreams(openPatchStream, out controlStream, out diffStream, out extraStream);

// prepare to read three parts of the patch in parallel
ApplyInternal(newSize, input, controlStream, diffStream, extraStream, output);
}

private static long CreatePatchStreams(OpenDiffStream openDiffStream, out Stream ctrl, out Stream diff, out Stream extra)
private static long CreatePatchStreams(OpenPatchStream openPatchStream, out Stream ctrl, out Stream diff, out Stream extra)
{
// read header
long controlLength, diffLength, newSize;
using (var diffStream = openDiffStream(0, BsDiff.HeaderSize))
using (var patchStream = openPatchStream(0, BsDiff.HeaderSize))
{
// check patch stream capabilities
if (!diffStream.CanRead)
throw new ArgumentException("Patch stream must be readable", "openDiffStream");
if (!diffStream.CanSeek)
throw new ArgumentException("Patch stream must be seekable", "openDiffStream");
if (!patchStream.CanRead)
throw new ArgumentException("Patch stream must be readable", "openPatchStream");
if (!patchStream.CanSeek)
throw new ArgumentException("Patch stream must be seekable", "openPatchStream");

var header = new byte[BsDiff.HeaderSize];
diffStream.Read(header, 0, BsDiff.HeaderSize);
patchStream.Read(header, 0, BsDiff.HeaderSize);

// check for appropriate magic
var signature = header.ReadLong();
Expand All @@ -67,9 +66,9 @@ private static long CreatePatchStreams(OpenDiffStream openDiffStream, out Stream

// prepare to read three parts of the patch in parallel
Stream
compressedControlStream = openDiffStream(BsDiff.HeaderSize, controlLength),
compressedDiffStream = openDiffStream(BsDiff.HeaderSize + controlLength, diffLength),
compressedExtraStream = openDiffStream(BsDiff.HeaderSize + controlLength + diffLength, -1);
compressedControlStream = openPatchStream(BsDiff.HeaderSize, controlLength),
compressedDiffStream = openPatchStream(BsDiff.HeaderSize + controlLength, diffLength),
compressedExtraStream = openPatchStream(BsDiff.HeaderSize + controlLength + diffLength, -1);

// decompress each part (to read it)
ctrl = BsDiff.GetEncodingStream(compressedControlStream, false);
Expand Down
9 changes: 4 additions & 5 deletions deltaq/SAIS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private static void GetBuckets(IList<int> c, IList<int> b, int k, bool end)
}

/* sort all type LMS suffixes */
private static void LMSsort(IList<int> T, int[] sa, IList<int> c, IList<int> B, int n, int k)
private static void LMS_sort(IList<int> T, int[] sa, IList<int> c, IList<int> B, int n, int k)
{
int b, i, j;
int c0, c1;
Expand Down Expand Up @@ -207,7 +207,7 @@ private static void LMSsort(IList<int> T, int[] sa, IList<int> c, IList<int> B,
}
}

private static int LMSpostproc(IList<int> T, int[] sa, int n, int m)
private static int LMS_post_proc(IList<int> T, int[] sa, int n, int m)
{
int i, j, p, q, plen, qlen, name;
int c0, c1;
Expand Down Expand Up @@ -432,8 +432,8 @@ sort all the LMS-substrings */
}
if (1 < m)
{
LMSsort(T, sa, c, B, n, k);
name = LMSpostproc(T, sa, n, m);
LMS_sort(T, sa, c, B, n, k);
name = LMS_post_proc(T, sa, n, m);
}
else if (m == 1)
{
Expand Down Expand Up @@ -480,7 +480,6 @@ sort all the LMS-substrings */

RA = new ArraySegment<int>(sa, m + newfs, sa.Length - (m + newfs));
sais_main(RA, sa, newfs, m, name);
RA = null;

i = n - 1;
j = m * 2 - 1;
Expand Down

0 comments on commit 8806a01

Please sign in to comment.