Skip to content

Commit 8207182

Browse files
committed
Added a missing "rest" output
1 parent 4282b76 commit 8207182

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

arithmeticCoder.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type ArithmeticCoder struct {
2929
step uint64
3030
quarters []uint64
3131
e3Counter uint32
32-
outputBytes []uint8
32+
outputBits []bool
3333
//How many bits we're going to write, later used to avoid append functions when writing into file
3434
writtenSize uint32
3535
}
@@ -112,7 +112,6 @@ func (arithmeticCoder *ArithmeticCoder) intervalCalculation(data []uint8) {
112112
quarters := arithmeticCoder.quarters
113113
step := arithmeticCoder.step
114114
e3Counter := arithmeticCoder.e3Counter
115-
outputBytes := arithmeticCoder.outputBytes
116115
outputBits := make([]bool, 0)
117116
var i uint64 = 0
118117
for ; i < uint64(len(data)); i++ {
@@ -156,17 +155,11 @@ func (arithmeticCoder *ArithmeticCoder) intervalCalculation(data []uint8) {
156155
e3Counter++
157156
}
158157
}
159-
//fmt.Println("")
160-
//For each 8 bits ready to be written, turn into a byte
161-
if arithmeticCoder.writtenSize%8 == 0 {
162-
outputBytes = append(outputBytes, bitSliceToByte(&outputBits))
163-
outputBits = nil
164-
}
158+
165159
}
166160
arithmeticCoder.high = high
167161
arithmeticCoder.low = low
168162
arithmeticCoder.step = step
169163
arithmeticCoder.e3Counter = e3Counter
170-
arithmeticCoder.outputBytes = outputBytes
171-
164+
arithmeticCoder.outputBits = outputBits
172165
}

binaryIO.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,19 @@ func readBinaryFile(arithmeticCoder *ArithmeticCoder, filepath string, operation
6565
//fmt.Println("The rest:")
6666
if arithmeticCoder.low < arithmeticCoder.quarters[0] {
6767
//fmt.Print("\n01 ")
68+
arithmeticCoder.outputBits = append(arithmeticCoder.outputBits, false, true)
6869
arithmeticCoder.writtenSize++
6970
for i := 0; uint32(i) < arithmeticCoder.e3Counter; i++ {
7071
//fmt.Print("1")
72+
arithmeticCoder.outputBits = append(arithmeticCoder.outputBits, true)
7173
arithmeticCoder.writtenSize++
7274
}
7375
} else {
76+
fmt.Println("10")
7477
for i := 0; uint32(i) < arithmeticCoder.e3Counter; i++ {
7578
arithmeticCoder.writtenSize++
7679
//fmt.Print("0")
80+
arithmeticCoder.outputBits = append(arithmeticCoder.outputBits, false)
7781
}
7882
}
7983
//fmt.Println("")

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func main() {
2626
quarters := make([]uint64, 4)
2727
//A series of 0(false) and 1(true) that is then written into bytes and written into the binary compressed file
2828
//TODO: turn this into output byte array
29-
outputBits := make([]uint8, 0)
29+
outputBits := make([]bool, 0)
3030
var upperLimit uint64 = 4294967295
3131
//Initialize an arithmetic codec with empty values except for the upper limit, which has the value of 2^32-1
3232
//After creating the model is done, we go on to interval creation

0 commit comments

Comments
 (0)