Skip to content

Commit 4cdfa95

Browse files
authored
Merge pull request cheran-senthil#94 from cheran-senthil/fix/sorted-list-preload
Improve preloading in SortedList
2 parents f25ac46 + 6025997 commit 4cdfa95

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pyrival/data_structures/SortedList.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@ class SortedList:
6464
block_size = 700
6565

6666
def __init__(self, iterable=()):
67-
self.macro = []
68-
self.micros = [[]]
69-
self.micro_size = [0]
70-
self.fenwick = FenwickTree([0])
71-
self.size = 0
72-
for item in iterable:
73-
self.insert(item)
67+
iterable = sorted(iterable)
68+
self.micros = [iterable[i:i + self.block_size - 1] for i in range(0, len(iterable), self.block_size - 1)] or [[]]
69+
self.macro = [i[0] for i in self.micros[1:]]
70+
self.micro_size = [len(i) for i in self.micros]
71+
self.fenwick = FenwickTree(self.micro_size)
72+
self.size = len(iterable)
7473

7574
def insert(self, x):
7675
i = lower_bound(self.macro, x)

0 commit comments

Comments
 (0)