Earlier quoted context omitted.
I'd like to more about this. Can I use this?
Search for HN username tagging extension. There's quite a few options available.
Beating TimSort at Merging
71–72 of 72 posts
Re: Beating TimSort at Merging
#72Earlier quoted context omitted.
So we could determine what gains I am getting are due to C and the specific compares and which are due just being 2 lists? That would be an interesting test. Maybe I'll do a follow-up. Thanks for reading the article. I suspect you know way more about C extensions in Python than I do. I saw you have a talk on this topic. I think you are totally right that pop is not the way to go, but using an offset to track the head…
Well the version I'm saying is essentially the same as the pop version you have so I don't think it's too complicated. You would just do something like this instead: def merge_sorted_lists(l1, l2): sorted_list = [] i = 0 j = 0 while i I haven't tested that (you probably should before using it), but it looks mostly right and is essentially the same algorithm as yours.
def merge2(l1, l2):
if len(l1) == 0:
return [x for x in l2]
if len(l2) == 0:
return [x for x in l1]
# ensure l1 is exhausted first to minimize
# comparisons
if l1[-1] > l2[-1]:
l1, l2 = l2, l1
sorted_list = []
i = 0
j = 0
N = len(l1)
while i