Skip to content

Commit

Permalink
cleanup some codebeat issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Frotty committed Jun 9, 2017
1 parent bfb4eac commit 9f8a6c0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/main/java/ru/eustas/zopfli/Deflate.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class Deflate {

static enum BlockType {
enum BlockType {
DYNAMIC,
FIXED
}
Expand Down Expand Up @@ -49,7 +49,7 @@ private static void getFixedTree(int[] llLengths, int[] dLengths) {
}
}

public static void greedy(Cookie cookie, LongestMatchCache lmc, byte[] input, int from, int to, LzStore store) {
static void greedy(Cookie cookie, LongestMatchCache lmc, byte[] input, int from, int to, LzStore store) {
Hash h = cookie.h;
h.init(input, Math.max(from - 0x8000, 0), from, to);
int prevLength = 0;
Expand Down
24 changes: 9 additions & 15 deletions src/main/java/ru/eustas/zopfli/SymbolStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,35 +114,30 @@ final void calculateDists() {
}

final void alloy(final SymbolStats ligand) {
int[] ligandLitLens = ligand.litLens;
for (int i = 0; i < 288; i++) {
litLens[i] += ligandLitLens[i] / 2;
litLens[i] += ligand.litLens[i] / 2;
}
litLens[256] = 1;

int[] ligandDists = ligand.dists;
for (int i = 0; i < 32; i++) {
dists[i] += ligandDists[i] / 2;
dists[i] += ligand.dists[i] / 2;
}
}

final int randomizeFreqs(int z) {
int[] data = litLens;
int n = data.length;
for (int i = 0; i < n; i++) {
z = 0x7FFFFFFF & (1103515245 * z + 12345);
if ((z >>> 4) % 3 == 0) {
z = 0x7FFFFFFF & (1103515245 * z + 12345);
int p = z % n;
if (data[i] < data[p]) {
data[i] = data[p];
}
}
}
z = getZ(z, data, n);
data[256] = 1;

data = dists;
n = data.length;
z = getZ(z, data, n);

return z;
}

private int getZ(int z, int[] data, int n) {
for (int i = 0; i < n; i++) {
z = 0x7FFFFFFF & (1103515245 * z + 12345);
if ((z >>> 4) % 3 == 0) {
Expand All @@ -153,7 +148,6 @@ final int randomizeFreqs(int z) {
}
}
}

return z;
}

Expand Down
42 changes: 17 additions & 25 deletions src/main/java/systems/crigges/jmpq3/compression/Huffman.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package systems.crigges.jmpq3.compression;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Map.Entry;
import java.util.TreeMap;

public class Huffman {
class Huffman {
private static class Node {
public Node parent;
public final Node[] child = new Node[2];
public Node next;
public Node prev;
public int value;
public int probability;

public void treeSwap(Node with) {
Node parent;
final Node[] child = new Node[2];
Node next;
Node prev;
int value;
int probability;

void treeSwap(Node with) {
Node temp;

if (parent == with.parent) {
Expand All @@ -33,14 +32,14 @@ public void treeSwap(Node with) {
with.parent = temp;
}

public void insertAfter(Node where) {
void insertAfter(Node where) {
prev = where;
next = where.next;
where.next = this;
next.prev = this;
}

public void listSwap(Node with) {
void listSwap(Node with) {
if (next == with) {
next = with.next;
with.next = this;
Expand Down Expand Up @@ -74,11 +73,11 @@ public void listSwap(Node with) {
}
}

public void newList() {
void newList() {
prev = next = this;
}

public Node removeFromList() {
Node removeFromList() {
if (this == next) return null;

prev.next = next;
Expand All @@ -87,7 +86,7 @@ public Node removeFromList() {
return next;
}

public void joinList(Node list) {
void joinList(Node list) {
Node tail = prev;

prev = list.prev;
Expand All @@ -98,13 +97,10 @@ public void joinList(Node list) {
}
}

private boolean adjustProbability;

private Node nodes = null;
private TreeMap<Integer, Node> sorted2 = new TreeMap<Integer, Node>();
private TreeMap<Integer, Node> sorted2 = new TreeMap<>();

private Node root = null;
private Node[] valueToNode = new Node[0x102];

private int bitBuffer;
private byte bitNumber;
Expand Down Expand Up @@ -144,7 +140,6 @@ private void destroyTree(Node root) {
else nodes.joinList(root);
this.root = null;
sorted2.clear();
Arrays.fill(valueToNode, null);
}

private void insertNode(Node node) {
Expand All @@ -156,7 +151,6 @@ private void insertNode(Node node) {
current = test2.getValue();
node.insertAfter(current);
} else {
current = root;
if (root != null) {
node.insertAfter(root.prev);
} else {
Expand All @@ -176,7 +170,6 @@ private Node addValueToTree(int value) {
node.child[0] = null;
node.child[1] = null;

valueToNode[value] = node;
insertNode(node);

// create branch node
Expand Down Expand Up @@ -251,7 +244,6 @@ private void buildTree(byte tree) {
node.child[1] = null;

insertNode(node);
valueToNode[i] = node;
}

// generate tree
Expand All @@ -276,12 +268,12 @@ private void buildTree(byte tree) {
root.parent = null;
}

public void Decompress(ByteBuffer in, ByteBuffer out) {
void Decompress(ByteBuffer in, ByteBuffer out) {
setSource(in);
byte type = (byte) getBits(8);
buildTree(type);

adjustProbability = type == 0;
boolean adjustProbability = type == 0;

for (; ; ) {
Node current = root;
Expand Down

0 comments on commit 9f8a6c0

Please sign in to comment.