From 68a939b3e64a35b6b76b8380df5f0bcedb90e467 Mon Sep 17 00:00:00 2001 From: Michael Whittaker Date: Fri, 22 Jan 2021 14:51:44 -0800 Subject: [PATCH] More efficently(?) check quorum system validity. --- quorums/quorum_system.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/quorums/quorum_system.py b/quorums/quorum_system.py index 43a81f9..aad2a02 100644 --- a/quorums/quorum_system.py +++ b/quorums/quorum_system.py @@ -18,10 +18,12 @@ class QuorumSystem(Generic[T]): def __init__(self, reads: Optional[Expr[T]] = None, writes: Optional[Expr[T]] = None) -> None: if reads is not None and writes is not None: - # TODO(mwhittaker): Think of ways to make this more efficient. - assert all(len(r & w) > 0 - for (r, w) in itertools.product(reads.quorums(), - writes.quorums())) + optimal_writes = reads.dual() + if not all(optimal_writes.is_quorum(write_quorum) + for write_quorum in writes.quorums()): + raise ValueError( + 'Not all read quorums intersect all write quorums') + self.reads = reads self.writes = writes elif reads is not None and writes is None: