Skip to content

Commit 41eb4e7

Browse files
committed
Update Decoder.kt
1 parent 3c2eec0 commit 41eb4e7

File tree

1 file changed

+9
-7
lines changed
  • Codex/src/main/java/org/operatorfoundation/codex

1 file changed

+9
-7
lines changed

Codex/src/main/java/org/operatorfoundation/codex/Decoder.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class Decoder(private val symbols: List<Symbol>)
2727
* @param encodedValues List of ByteArrays, one for each symbol
2828
* @return The decoded integer value
2929
*/
30-
fun decode(encodedValues: List<ByteArray>): Int {
30+
fun decode(encodedValues: List<ByteArray>): Int
31+
{
3132
val results = mutableListOf<Int>()
3233

3334
// Process each symbol with its corresponding encoded value
@@ -50,7 +51,8 @@ class Decoder(private val symbols: List<Symbol>)
5051
*/
5152
private fun decodeStep(encodedValue: ByteArray, symbol: Symbol, index: Int): Int
5253
{
53-
if (symbol.size() == 1) {
54+
if (symbol.size() == 1)
55+
{
5456
// Symbols with size 1 don't contribute to the numeric value
5557
println("decode_step(${encodedValue.decodeToString()}, $symbol, $index)")
5658

@@ -68,14 +70,14 @@ class Decoder(private val symbols: List<Symbol>)
6870
else
6971
{
7072
// Calculate product of remaining symbol sizes
71-
val history = symbols.subList(index + 1, symbols.size)
72-
val lens = history.map { it.size() }
73-
val p = lens.fold(1) { acc, size -> acc * size }
73+
val remainingSymbols = symbols.subList(index + 1, symbols.size)
74+
val remainingSymbolSizes = remainingSymbols.map { it.size() }
75+
val positionMultiplier = remainingSymbolSizes.fold(1) { acc, size -> acc * size }
7476

75-
println("history: $lens, p: $p")
77+
println("history: $remainingSymbolSizes, p: $positionMultiplier")
7678

7779
// Multiply decoded value by position weight
78-
val result = symbol.decode(encodedValue) * p
80+
val result = symbol.decode(encodedValue) * positionMultiplier
7981
println("result: $result")
8082

8183
return result

0 commit comments

Comments
 (0)