From a1254a3e9200a530516af7de64b586c1c8d0fe70 Mon Sep 17 00:00:00 2001 From: burris Date: Sun, 1 Dec 2002 21:06:08 +0000 Subject: [PATCH] utility module for random stuff has func for counting min/max/average peers in table for a list of khashmir instances --- util.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 util.py 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} -- 2.39.5