Created
May 2, 2021 15:30
-
-
Save samueleresca/e50f62f55c8bc5dc40cd695bc9378b64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Original code available at: https://github.com/mwhittaker/quoracle/blob/main/quoracle/quorum_system.py#L596 | |
""" | |
class Strategy(Generic[T]): | |
def __init__(self, | |
qs: QuorumSystem[T], | |
sigma_r: Dict[FrozenSet[T], float], | |
sigma_w: Dict[FrozenSet[T], float]) -> None: | |
self.qs = qs | |
self.sigma_r = sigma_r | |
self.sigma_w = sigma_w | |
# The probability that x is chosen as part of a read quorum. | |
self.x_read_probability: Dict[T, float] = collections.defaultdict(float) | |
for (read_quorum, p) in self.sigma_r.items(): | |
for x in read_quorum: | |
self.x_read_probability[x] += p | |
# The probability that x is chosen as part of a write quorum. | |
self.x_write_probability: Dict[T, float] = collections.defaultdict(float) | |
for (write_quorum, weight) in self.sigma_w.items(): | |
for x in write_quorum: | |
self.x_write_probability[x] += weight |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment