Skip to content

Commit

Permalink
Improve the logic of _last_pos_filled considering edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
Susmita-Chakrabarty committed Feb 9, 2025
1 parent 3613556 commit 92f2c92
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pydatastructs/linear_data_structures/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,12 @@ def _modify(self, force=False):
below load factor.
"""
if force:
i = self._size - 1
while i >= 0 and self._data[i] is None:
i -= 1
self._last_pos_filled = i
left = 0
for i in range(self._size):
if self._data[i] is not None:
self._data[left], self._data[i] = self._data[i], self._data[left]
left += 1
self._last_pos_filled = left - 1
if (self._num/self._size < self._load_factor):
arr_new = OneDimensionalArray(self._dtype, 2*self._num + 1)
j = 0
Expand Down

0 comments on commit 92f2c92

Please sign in to comment.