Skip to content
This repository has been archived by the owner on Mar 2, 2023. It is now read-only.

Commit

Permalink
Replaced list.sort(key
Browse files Browse the repository at this point in the history
darcs-hash:20060916120050-6d791-7bac16b5722044e3ef687fa956cd15367550a8cf.gz
  • Loading branch information
jmbr committed Sep 16, 2006
1 parent 3f88c38 commit f629fe9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Halberd/clues/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ def find_cluster(clues, num):
return tuple(clues[:num])
return ()

# Sort the clues by their time difference.
clues.sort(key=lambda x: x.diff)
clues = sort_clues(clues)

invrange = lambda num: [(num - x) for x in range(num)]

Expand Down Expand Up @@ -333,6 +332,16 @@ def slices(start, xs):
return [slice(start, None)]
return [slice(start, xs[0])] + slices(xs[0], xs[1:])

def sort_clues(clues):
"""Sorts clues according to their time difference.
"""
# This can be accomplished in newer (>= 2.4) Python versions using:
# clues.sort(key=lambda x: x.diff)
tmps = [(x.diff, x) for x in clues]
tmps.sort()
return [x[1] for x in tmps]


def filter_proxies(clues, maxdelta=3):
"""Detect and merge clues pointing to a proxy cache on the remote end.
Expand All @@ -359,7 +368,8 @@ def filter_proxies(clues, maxdelta=3):
results.append(cur_clues[0])
continue

cur_clues.sort(key=lambda x: x.diff)
cur_clues = sort_clues(cur_clues)

diffs = [c.diff for c in cur_clues]

# We find the indices of those clues which differ from the rest in
Expand Down

0 comments on commit f629fe9

Please sign in to comment.