]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
utility module for random stuff
authorburris <burris>
Sun, 1 Dec 2002 21:06:08 +0000 (21:06 +0000)
committerburris <burris>
Sun, 1 Dec 2002 21:06:08 +0000 (21:06 +0000)
has func for counting min/max/average peers in table for a list of
khashmir instances

util.py [new file with mode: 0644]

diff --git a/util.py b/util.py
new file mode 100644 (file)
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}