Skip to content

Commit 653f8e4

Browse files
committed
trying to make the code pass ruff auto review
1 parent 521d7a2 commit 653f8e4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

compression/ppm.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
from __future__ import annotations
21
import sys
2+
from __future__ import annotations
33
from collections import defaultdict
44

55
# Description for the ppm algorithm can be found at https://en.wikipedia.org/wiki/Prediction_by_partial_matching
66

77

88
class PPMNode:
99
def __init__(self) -> None:
10-
# Initialize a PPMNode with a dictionary for child nodes and a count of total occurrences
10+
# Initialize a PPMNode with a dictionary for child nodes
11+
# and a count of total occurrences
1112
self.counts: dict[str, PPMNode] = defaultdict(PPMNode)
1213
self.total: int = 0
1314

@@ -47,7 +48,7 @@ def compress(self, data: str) -> list[float]:
4748
context = (context + symbol)[-self.order :] # Keep the context within order
4849

4950
return compressed_output
50-
51+
5152
def encode_symbol(self, context: str, symbol: str) -> float:
5253
# Encode a symbol based on the current context and return its probability
5354
node = self.root
@@ -92,7 +93,8 @@ def decode_symbol(self, context: str, prob: float) -> str | None:
9293
else:
9394
return None # Return None if the context is not found
9495

95-
# Iterate through the children of the node to find the symbol matching the given probability
96+
# Iterate through the children of the node to
97+
# find the symbol matching the given probability
9698
for symbol, child in node.counts.items():
9799
if child.total / node.total == prob:
98100
return symbol # Return the symbol if the probability matches

0 commit comments

Comments
 (0)