return res
class Filenode(unittest.TestCase, testutil.ShouldFailMixin):
- # this used to be in Publish, but we removed the limit. Some of
- # these tests test whether the new code correctly allows files
+ # this used to be in Publish, but we removed the limit. Some of
+ # these tests test whether the new code correctly allows files
# larger than the limit.
OLD_MAX_SEGMENT_SIZE = 3500000
def setUp(self):
def __init__(self, basedir, num_peers=10):
self._num_peers = num_peers
- peerids = [tagged_hash("peerid", "%d" % i)[:20]
+ peerids = [tagged_hash("peerid", "%d" % i)[:20]
for i in range(self._num_peers)]
self.storage_broker = StorageFarmBroker(None, True)
for peerid in peerids:
Note that this function does little to no error checking and is
intended for internal use and testing only.
"""
- pmf_list = [ binomial_distribution_pmf(p_list.count(p), p)
+ pmf_list = [ binomial_distribution_pmf(p_list.count(p), p)
for p in set(p_list) ]
return reduce(convolve, pmf_list)
def print_pmf(pmf, n=4, out=sys.stdout):
"""
Print a PMF in a readable form, with values rounded to n
- significant digits.
+ significant digits.
"""
for k, p in enumerate(pmf):
print >>out, "i=" + str(k) + ":", round_sigfigs(p, n)
def find_k_from_pmf(pmf, target_loss_prob):
"""
- Find the highest k value that achieves the targeted loss
+ Find the highest k value that achieves the targeted loss
probability, given the share survival PMF given in pmf.
"""
assert valid_pmf(pmf)
# Probability of 0 to repair is the probability of all shares
# surviving plus the probability of less than k surviving.
pmf = [ survival_pmf[n] + sum(survival_pmf[0:k]) ]
-
+
# Probability of more than 0, up to N-k to repair
for i in range(1, n-k+1):
pmf.append(survival_pmf[n-i])
-
+
# Probability of more than N-k to repair is 0, because that means
# there are less than k available and the file is irreparable.
for i in range(n-k+1, n+1):
"""
n = len(list_a)
m = len(list_b)
-
+
result = []
for i in range(n + m - 1):
sum = 0.0
lower = max(0, i - n + 1)
upper = min(m - 1, i)
-
+
for j in range(lower, upper+1):
sum += list_a[i-j] * list_b[j]
result = []
for k in range(n+1):
- result.append(math.pow(p , k ) *
- math.pow(1 - p, n - k) *
+ result.append(math.pow(p , k ) *
+ math.pow(1 - p, n - k) *
binomial_coeff(n, k))
assert valid_pmf(result)