From 51a4778f089a0128bf0dd7baba06ace67f0980e7 Mon Sep 17 00:00:00 2001 From: tommyod Date: Thu, 5 Sep 2024 20:23:42 +0200 Subject: [PATCH] update self._v without loop in init() --- fenwick/fenwick.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fenwick/fenwick.py b/fenwick/fenwick.py index 716a629..4899d61 100644 --- a/fenwick/fenwick.py +++ b/fenwick/fenwick.py @@ -96,9 +96,8 @@ def __setitem__(self, idx, value): def init(self, frequencies): """Initialize in O(n) with specified frequencies.""" if len(frequencies) != self._n: - raise ValueError("Number of frequencies must match size of tree.") - for idx in _range(self._n): - self._v[idx] = frequencies[idx] + raise ValueError("Length of frequencies must match length of FenwickTree.") + self._v = list(frequencies) for idx in _range(1, self._n + 1): parent_idx = idx + (idx & -idx) # parent in update tree if parent_idx <= self._n: