-
Notifications
You must be signed in to change notification settings - Fork 0
Java use guide
Martsim edited this page Jan 26, 2018
·
4 revisions
The code was tested with Java8
File: src/Huffman.java
- hcEncode(text) - encodes the text and returns the codeword.
- decode(encoded string) - decodes a bitstring. Assumes that it was previously encoded with the same object.
Modify the content of the main method or import the class, create an object and encode.
File: src/RANSimpl.java
- encode(symbol, x) - encodes the symbol to the given x and returns the new x.
- decode(x) - decodes a symbol and returns the new x.
- encode_text_with_dict(text, possible x value) - calculates probabilities of symbols in given text and then encodes the text based on this. Returns the variable into which the text is encoded. Default starting x is 0.
- encode_text_with_dict_check(text) - encodes the text and checks if it can be decoded as well. Returns the coded value.
- decode_text(x, nr_of_symbols) - takes the encoded x and the number of symbols to read from this x.
- demo_dickens(blockSize) - expects 'dickens' text file to exist in the running directory. Encodes the text into given block size pieces.
Either import the prementioned functions or run the main method for a test.
File: src/CompareTwo.java
- ComparisonValues - used by the comparer for storing calculated values during the test.
- CompareTwo - class which runs the tests.
- runTests(block_size, filename) - used for running tests. Reads chunks of block_size from given file and encodes them with Huffman coding and rANS. Calculates the average compression rates, how many times which algorithm was better.
Run from the main method or import the class and use runTests.