Skip to content

Commit c12ab19

Browse files
committed
Tweaks.
1 parent 31b84c7 commit c12ab19

File tree

7 files changed

+61
-60
lines changed

7 files changed

+61
-60
lines changed

src/main/java/com/dannemann/stringcompressor/BaseBinarySearch.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
public abstract class BaseBinarySearch {
44

5-
protected final byte[][] compressedMass;
5+
protected final byte[][] compressedData;
66
protected final boolean prefixSearch;
77
protected final byte[] charset;
88

9-
public BaseBinarySearch(byte[][] compressedMass, boolean prefixSearch, byte[] charset) {
10-
this.compressedMass = compressedMass;
9+
public BaseBinarySearch(byte[][] compressedData, boolean prefixSearch, byte[] charset) {
10+
this.compressedData = compressedData;
1111
this.prefixSearch = prefixSearch;
1212
this.charset = charset;
1313
}
1414

1515
public abstract int search(final byte[] key);
1616

17-
public byte[][] getCompressedMass() {
18-
return compressedMass;
17+
public byte[][] getCompressedData() {
18+
return compressedData;
1919
}
2020

2121
public boolean isPrefixSearch() {

src/main/java/com/dannemann/stringcompressor/FiveBitBinarySearch.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,25 @@ public final class FiveBitBinarySearch extends BaseBinarySearch {
1919

2020
/**
2121
* Creates a binary search object for data compressed with the default character set {@link FiveBitAsciiCompressor#DEFAULT_5BIT_CHARSET}.
22-
* @param compressedMass The mass of compressed strings to search through.
22+
* @param compressedData The mass of compressed strings to search through.
2323
* @param prefixSearch If {@code true}, searches for elements starting with the provided key prefix (must be unique).
2424
* @author Jean Dannemann Carone
2525
* @see FiveBitBinarySearch#FiveBitBinarySearch(byte[][], boolean, byte[])
2626
*/
27-
public FiveBitBinarySearch(byte[][] compressedMass, boolean prefixSearch) {
28-
super(compressedMass, prefixSearch, DEFAULT_5BIT_CHARSET);
27+
public FiveBitBinarySearch(byte[][] compressedData, boolean prefixSearch) {
28+
super(compressedData, prefixSearch, DEFAULT_5BIT_CHARSET);
2929
}
3030

3131
/**
3232
* Creates a binary search object.
33-
* @param compressedMass The mass of compressed strings to search through.
33+
* @param compressedData The mass of compressed strings to search through.
3434
* @param prefixSearch If {@code true}, searches for elements starting with the provided key prefix (must be unique).
35-
* @param charset Character set used to compress {@code compressedMass}.
35+
* @param charset Character set used to compress {@code compressedData}.
3636
* @author Jean Dannemann Carone
3737
*/
38-
public FiveBitBinarySearch(byte[][] compressedMass, boolean prefixSearch, byte[] charset) {
39-
super(compressedMass, prefixSearch, charset);
38+
// TODO: WHAT IF COMPRESSED MASS IS BIGGER THAN THE NUMBER OF ELEMENTS? TREAT THIS.
39+
public FiveBitBinarySearch(byte[][] compressedData, boolean prefixSearch, byte[] charset) {
40+
super(compressedData, prefixSearch, charset);
4041
}
4142

4243
/**
@@ -52,18 +53,18 @@ public FiveBitBinarySearch(byte[][] compressedMass, boolean prefixSearch, byte[]
5253
*/
5354
@Override
5455
public int search(final byte[] key) {
55-
final int massLength = compressedMass.length;
56+
final int dataLength = compressedData.length;
5657

57-
if (massLength == 0)
58+
if (dataLength == 0)
5859
return -1;
5960

6061
final int keyLen = key.length;
6162
int low = 0;
62-
int high = massLength - 1;
63+
int high = dataLength - 1;
6364

6465
while (low <= high) {
6566
final int mid = low + high >>> 1;
66-
final byte[] compStr = compressedMass[mid];
67+
final byte[] compStr = compressedData[mid];
6768
final int cLenMinus = compStr.length - 1;
6869
int buffer = 0;
6970
int bits = 0;

src/main/java/com/dannemann/stringcompressor/FourBitBinarySearch.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ public final class FourBitBinarySearch extends BaseBinarySearch {
1919

2020
/**
2121
* Creates a binary search object for data compressed with the default character set {@link FourBitAsciiCompressor#DEFAULT_4BIT_CHARSET}.
22-
* @param compressedMass The mass of compressed strings to search through.
22+
* @param compressedData The mass of compressed strings to search through.
2323
* @param prefixSearch If {@code true}, searches for elements starting with the provided key prefix (must be unique).
2424
* @author Jean Dannemann Carone
2525
* @see FourBitBinarySearch#FourBitBinarySearch(byte[][], boolean, byte[])
2626
*/
27-
public FourBitBinarySearch(byte[][] compressedMass, boolean prefixSearch) {
28-
super(compressedMass, prefixSearch, DEFAULT_4BIT_CHARSET);
27+
public FourBitBinarySearch(byte[][] compressedData, boolean prefixSearch) {
28+
super(compressedData, prefixSearch, DEFAULT_4BIT_CHARSET);
2929
}
3030

3131
/**
3232
* Creates a binary search object.
33-
* @param compressedMass The mass of compressed strings to search through.
33+
* @param compressedData The mass of compressed strings to search through.
3434
* @param prefixSearch If {@code true}, searches for elements starting with the provided key prefix (must be unique).
35-
* @param charset Character set used to compress {@code compressedMass}.
35+
* @param charset Character set used to compress {@code compressedData}.
3636
* @author Jean Dannemann Carone
3737
*/
38-
public FourBitBinarySearch(byte[][] compressedMass, boolean prefixSearch, byte[] charset) {
39-
super(compressedMass, prefixSearch, charset);
38+
public FourBitBinarySearch(byte[][] compressedData, boolean prefixSearch, byte[] charset) {
39+
super(compressedData, prefixSearch, charset);
4040
}
4141

4242
/**
@@ -52,18 +52,18 @@ public FourBitBinarySearch(byte[][] compressedMass, boolean prefixSearch, byte[]
5252
*/
5353
@Override
5454
public int search(final byte[] key) {
55-
final int massLength = compressedMass.length;
55+
final int dataLength = compressedData.length;
5656

57-
if (massLength == 0)
57+
if (dataLength == 0)
5858
return -1;
5959

6060
final int keyLen = key.length;
6161
int low = 0;
62-
int high = massLength - 1;
62+
int high = dataLength - 1;
6363

6464
while (low <= high) {
6565
final int mid = low + high >>> 1;
66-
final byte[] compStr = compressedMass[mid];
66+
final byte[] compStr = compressedData[mid];
6767
final int odd;
6868
final int dLen;
6969
int cLenMinus = compStr.length - 1;

src/main/java/com/dannemann/stringcompressor/SixBitBinarySearch.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ public final class SixBitBinarySearch extends BaseBinarySearch {
1919

2020
/**
2121
* Creates a binary search object for data compressed with the default character set {@link SixBitAsciiCompressor#DEFAULT_6BIT_CHARSET}.
22-
* @param compressedMass The mass of compressed strings to search through.
22+
* @param compressedData The mass of compressed strings to search through.
2323
* @param prefixSearch If {@code true}, searches for elements starting with the provided key prefix (must be unique).
2424
* @author Jean Dannemann Carone
2525
* @see SixBitBinarySearch#SixBitBinarySearch(byte[][], boolean, byte[])
2626
*/
27-
public SixBitBinarySearch(byte[][] compressedMass, boolean prefixSearch) {
28-
super(compressedMass, prefixSearch, DEFAULT_6BIT_CHARSET);
27+
public SixBitBinarySearch(byte[][] compressedData, boolean prefixSearch) {
28+
super(compressedData, prefixSearch, DEFAULT_6BIT_CHARSET);
2929
}
3030

3131
/**
3232
* Creates a binary search object.
33-
* @param compressedMass The mass of compressed strings to search through.
33+
* @param compressedData The mass of compressed strings to search through.
3434
* @param prefixSearch If {@code true}, searches for elements starting with the provided key prefix (must be unique).
35-
* @param charset Character set used to compress {@code compressedMass}.
35+
* @param charset Character set used to compress {@code compressedData}.
3636
* @author Jean Dannemann Carone
3737
*/
38-
public SixBitBinarySearch(byte[][] compressedMass, boolean prefixSearch, byte[] charset) {
39-
super(compressedMass, prefixSearch, charset);
38+
public SixBitBinarySearch(byte[][] compressedData, boolean prefixSearch, byte[] charset) {
39+
super(compressedData, prefixSearch, charset);
4040
}
4141

4242
/**
@@ -52,18 +52,18 @@ public SixBitBinarySearch(byte[][] compressedMass, boolean prefixSearch, byte[]
5252
*/
5353
@Override
5454
public int search(final byte[] key) {
55-
final int massLength = compressedMass.length;
55+
final int dataLength = compressedData.length;
5656

57-
if (massLength == 0)
57+
if (dataLength == 0)
5858
return -1;
5959

6060
final int keyLen = key.length;
6161
int low = 0;
62-
int high = massLength - 1;
62+
int high = dataLength - 1;
6363

6464
while (low <= high) {
6565
final int mid = low + high >>> 1;
66-
final byte[] compStr = compressedMass[mid];
66+
final byte[] compStr = compressedData[mid];
6767
final int cLenMinus = compStr.length - 1;
6868
int buffer = 0;
6969
int bits = 0;
@@ -75,7 +75,7 @@ public int search(final byte[] key) {
7575

7676
if (bits >= 6 &&
7777
(cmp = DEFAULT_6BIT_CHARSET[buffer >>> (bits -= 6) & 0x3F] - key[j++]) != 0 ||
78-
bits >= 6 && j < keyLen &&
78+
bits >= 6 && j < keyLen &&
7979
(cmp = DEFAULT_6BIT_CHARSET[buffer >>> (bits -= 6) & 0x3F] - key[j++]) != 0)
8080
break;
8181
}

src/test/java/com/dannemann/stringcompressor/FiveBitBinarySearchTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void searchSmallStringsTest() {
2929
final byte[][] destination = new byte[source.size()][];
3030
ManagedBulkCompressor.compressAndAddAll(COMPRESSOR, destination, source);
3131
final FiveBitBinarySearch bs = new FiveBitBinarySearch(destination, false);
32-
for (int j = 0, massLen = source.size(); j < massLen; j++)
32+
for (int j = 0, len = source.size(); j < len; j++)
3333
assertEquals(j, bs.search(getBytes(source.get(j))));
3434
}
3535
}
@@ -40,7 +40,7 @@ void searchBigArrayTest() {
4040
final byte[][] destination = new byte[source.size()][];
4141
ManagedBulkCompressor.compressAndAddAll(COMPRESSOR, destination, source);
4242
final FiveBitBinarySearch bs = new FiveBitBinarySearch(destination, false);
43-
for (int i = 0, massLen = source.size(); i < massLen; i++)
43+
for (int i = 0, len = source.size(); i < len; i++)
4444
assertEquals(i, bs.search(getBytes(source.get(i))));
4545
}
4646

@@ -50,7 +50,7 @@ void searchBigStringsTest() {
5050
final byte[][] destination = new byte[source.size()][];
5151
ManagedBulkCompressor.compressAndAddAll(COMPRESSOR, destination, source);
5252
final FiveBitBinarySearch bs = new FiveBitBinarySearch(destination, false);
53-
for (int i = 0, massLen = source.size(); i < massLen; i++)
53+
for (int i = 0, len = source.size(); i < len; i++)
5454
assertEquals(i, bs.search(getBytes(source.get(i))));
5555
}
5656

@@ -79,12 +79,12 @@ void searchBigStringsTest() {
7979
ManagedBulkCompressor.compressAndAddAll(COMPRESSOR, COMPRESSED_SPECIAL, SPECIAL_ARRAY);
8080
}
8181

82-
static int fiveBitBinarySearch(byte[][] compressedMass, String input) {
83-
return new FiveBitBinarySearch(compressedMass, false).search(getBytes(input));
82+
static int fiveBitBinarySearch(byte[][] compressedData, String input) {
83+
return new FiveBitBinarySearch(compressedData, false).search(getBytes(input));
8484
}
8585

86-
static int fiveBitPrefixSearch(byte[][] compressedMass, String input) {
87-
return new FiveBitBinarySearch(compressedMass, true).search(getBytes(input));
86+
static int fiveBitPrefixSearch(byte[][] compressedData, String input) {
87+
return new FiveBitBinarySearch(compressedData, true).search(getBytes(input));
8888
}
8989

9090
@Test

src/test/java/com/dannemann/stringcompressor/FourBitBinarySearchTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void searchSmallStringsTest() {
2929
final byte[][] destination = new byte[source.size()][];
3030
ManagedBulkCompressor.compressAndAddAll(COMPRESSOR, destination, source);
3131
final FourBitBinarySearch bs = new FourBitBinarySearch(destination, false);
32-
for (int j = 0, massLen = source.size(); j < massLen; j++)
32+
for (int j = 0, len = source.size(); j < len; j++)
3333
assertEquals(j, bs.search(getBytes(source.get(j))));
3434
}
3535
}
@@ -40,7 +40,7 @@ void searchBigArrayTest() {
4040
final byte[][] destination = new byte[source.size()][];
4141
ManagedBulkCompressor.compressAndAddAll(COMPRESSOR, destination, source);
4242
final FourBitBinarySearch bs = new FourBitBinarySearch(destination, false);
43-
for (int i = 0, massLen = source.size(); i < massLen; i++)
43+
for (int i = 0, len = source.size(); i < len; i++)
4444
assertEquals(i, bs.search(getBytes(source.get(i))));
4545
}
4646

@@ -50,7 +50,7 @@ void searchBigStringsTest() {
5050
final byte[][] destination = new byte[source.size()][];
5151
ManagedBulkCompressor.compressAndAddAll(COMPRESSOR, destination, source);
5252
final FourBitBinarySearch bs = new FourBitBinarySearch(destination, false);
53-
for (int i = 0, massLen = source.size(); i < massLen; i++)
53+
for (int i = 0, len = source.size(); i < len; i++)
5454
assertEquals(i, bs.search(getBytes(source.get(i))));
5555
}
5656

@@ -111,12 +111,12 @@ void searchBigStringsTest() {
111111
ManagedBulkCompressor.compressAndAddAll(COMPRESSOR, COMPRESSED_SPECIAL, SPECIAL_ARRAY);
112112
}
113113

114-
static int fourBitBinarySearch(byte[][] compressedMass, String input) {
115-
return new FourBitBinarySearch(compressedMass, false).search(getBytes(input));
114+
static int fourBitBinarySearch(byte[][] compressedData, String input) {
115+
return new FourBitBinarySearch(compressedData, false).search(getBytes(input));
116116
}
117117

118-
static int fourBitPrefixSearch(byte[][] compressedMass, String input) {
119-
return new FourBitBinarySearch(compressedMass, true).search(getBytes(input));
118+
static int fourBitPrefixSearch(byte[][] compressedData, String input) {
119+
return new FourBitBinarySearch(compressedData, true).search(getBytes(input));
120120
}
121121

122122
@Test

src/test/java/com/dannemann/stringcompressor/SixBitBinarySearchTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void searchSmallStringsTest() {
2929
final byte[][] destination = new byte[source.size()][];
3030
ManagedBulkCompressor.compressAndAddAll(COMPRESSOR, destination, source);
3131
final SixBitBinarySearch bs = new SixBitBinarySearch(destination, false);
32-
for (int j = 0, massLen = source.size(); j < massLen; j++)
32+
for (int j = 0, len = source.size(); j < len; j++)
3333
assertEquals(j, bs.search(getBytes(source.get(j))));
3434
}
3535
}
@@ -40,7 +40,7 @@ void searchBigArrayTest() {
4040
final byte[][] destination = new byte[source.size()][];
4141
ManagedBulkCompressor.compressAndAddAll(COMPRESSOR, destination, source);
4242
final SixBitBinarySearch bs = new SixBitBinarySearch(destination, false);
43-
for (int i = 0, massLen = source.size(); i < massLen; i++)
43+
for (int i = 0, len = source.size(); i < len; i++)
4444
assertEquals(i, bs.search(getBytes(source.get(i))));
4545
}
4646

@@ -50,7 +50,7 @@ void searchBigStringsTest() {
5050
final byte[][] destination = new byte[source.size()][];
5151
ManagedBulkCompressor.compressAndAddAll(COMPRESSOR, destination, source);
5252
final SixBitBinarySearch bs = new SixBitBinarySearch(destination, false);
53-
for (int i = 0, massLen = source.size(); i < massLen; i++)
53+
for (int i = 0, len = source.size(); i < len; i++)
5454
assertEquals(i, bs.search(getBytes(source.get(i))));
5555
}
5656

@@ -79,12 +79,12 @@ void searchBigStringsTest() {
7979
ManagedBulkCompressor.compressAndAddAll(COMPRESSOR, COMPRESSED_SPECIAL, SPECIAL_ARRAY);
8080
}
8181

82-
static int sixBitBinarySearch(byte[][] compressedMass, String input) {
83-
return new SixBitBinarySearch(compressedMass, false).search(getBytes(input));
82+
static int sixBitBinarySearch(byte[][] compressedData, String input) {
83+
return new SixBitBinarySearch(compressedData, false).search(getBytes(input));
8484
}
8585

86-
static int sixBitPrefixSearch(byte[][] compressedMass, String input) {
87-
return new SixBitBinarySearch(compressedMass, true).search(getBytes(input));
86+
static int sixBitPrefixSearch(byte[][] compressedData, String input) {
87+
return new SixBitBinarySearch(compressedData, true).search(getBytes(input));
8888
}
8989

9090
@Test

0 commit comments

Comments
 (0)