def _merge_sorted_lists(keyfn):
def merge(l1, l2):
# TODO might be nice to have a specialized version of this which
# re-uses uninterrupted subtrees from one side; it would boost
# lists that are mostly sorted already.
min1, max1 = keyfn(l1[0]), keyfn(l1[-1])
min2, max2 = keyfn(l2[0]), keyfn(l2[-1])
if max1 <= min2:
return l1 + l2
if max2 < min1: # not "<=" here because it would make the sort unstable
return l2 + l1
return viewablelist(list(_mergesorted(iter(l1), iter(l2), keyfn)))
return merge
#
# Other
#
评论列表
文章目录