Skip to content

Commit

Permalink
fix(handler): fix UBI PEB size calculation.
Browse files Browse the repository at this point in the history
Computing the most frequent interval can only work if we return each and
every interval value observed in a list. Returning it in a set hides the
repeating interval patterns.

The 'get_intervals' function now _actually_ acts like numpy.diff.
  • Loading branch information
qkaiser committed Jan 19, 2024
1 parent c907b42 commit bb9cf0a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions tests/test_iter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
@pytest.mark.parametrize(
"values, expected",
[
([], set()),
([0, 0], {0}),
([0, 0, 0], {0}),
([1, 2, 3], {1}),
([1, 5, 8, 8, 10, 15], {4, 3, 0, 2, 5}),
([], []),
([0, 0], [0]),
([0, 0, 0], [0, 0]),
([1, 2, 3], [1, 1]),
([1, 5, 8, 8, 10, 15], [4, 3, 0, 2, 5]),
],
)
def test_get_internals(values, expected):
Expand Down
8 changes: 4 additions & 4 deletions unblob/iter_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import itertools
from typing import List, Set
from typing import List


def pairwise(iterable):
Expand All @@ -10,7 +10,7 @@ def pairwise(iterable):
return zip(a, b)


def get_intervals(values: List[int]) -> Set[int]:
def get_intervals(values: List[int]) -> List[int]:
"""Get all the intervals between numbers.
It's similar to numpy.diff function.
Expand All @@ -20,7 +20,7 @@ def get_intervals(values: List[int]) -> Set[int]:
>>> get_intervals([1, 4, 5, 6, 10])
[3, 1, 1, 4]
"""
all_diffs = set()
all_diffs = []
for value, next_value in pairwise(values):
all_diffs.add(next_value - value)
all_diffs.append(next_value - value)
return all_diffs

0 comments on commit bb9cf0a

Please sign in to comment.