From: burris Date: Sun, 1 Dec 2002 21:06:08 +0000 (+0000) Subject: utility module for random stuff X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a1254a3e9200a530516af7de64b586c1c8d0fe70;p=quix0rs-apt-p2p.git utility module for random stuff has func for counting min/max/average peers in table for a list of khashmir instances --- diff --git a/util.py b/util.py new file mode 100644 index 0000000..ea1e7f2 --- /dev/null +++ b/util.py @@ -0,0 +1,20 @@ +def bucket_stats(l): + """given a list of khashmir instances, finds min, max, and average number of nodes in tables""" + max = avg = 0 + min = None + def count(buckets): + c = 0 + for bucket in buckets: + c = c + len(bucket.l) + return c + for node in l: + c = count(node.table.buckets) + if min == None: + min = c + elif c < min: + min = c + if c > max: + max = c + avg = avg + c + avg = avg / len(l) + return {'min':min, 'max':max, 'avg':avg}