Skip to content

Commit

Permalink
Improve preloading in SortedList
Browse files Browse the repository at this point in the history
  • Loading branch information
Mukundan314 committed Oct 24, 2024
1 parent f25ac46 commit 6025997
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pyrival/data_structures/SortedList.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ class SortedList:
block_size = 700

def __init__(self, iterable=()):
self.macro = []
self.micros = [[]]
self.micro_size = [0]
self.fenwick = FenwickTree([0])
self.size = 0
for item in iterable:
self.insert(item)
iterable = sorted(iterable)
self.micros = [iterable[i:i + self.block_size - 1] for i in range(0, len(iterable), self.block_size - 1)] or [[]]
self.macro = [i[0] for i in self.micros[1:]]
self.micro_size = [len(i) for i in self.micros]
self.fenwick = FenwickTree(self.micro_size)
self.size = len(iterable)

def insert(self, x):
i = lower_bound(self.macro, x)
Expand Down

0 comments on commit 6025997

Please sign in to comment.