Constraint.__and__() currently intersects hash_options with list membership checks:
[v for v in other.hash_options[alg] if v in self.hash_options[alg]]
For each shared hash algorithm, this iterates one list and checks membership in another list. Since list membership is linear, the intersection is O(n*m).
This can be reduced to O(n+m) by building a temporary set for membership checks:
self_hashes = set(self.hash_options[alg])
[v for v in other.hash_options[alg] if v in self_hashes]
The implementation should preserve the current result ordering from other.hash_options[alg] unless we explicitly decide that hash option ordering is not observable.
Constraint.__and__()currently intersectshash_optionswith list membership checks:For each shared hash algorithm, this iterates one list and checks membership in another list. Since list membership is linear, the intersection is O(n*m).
This can be reduced to O(n+m) by building a temporary set for membership checks:
The implementation should preserve the current result ordering from
other.hash_options[alg]unless we explicitly decide that hash option ordering is not observable.