22 lines
766 B
Python
22 lines
766 B
Python
from typing import Generic, TypeVar
|
|
|
|
from rainbowadn.core.hashpoint import HashPoint
|
|
from rainbowadn.data.collection.trees.comparison.comparator import Comparison, Left, Right
|
|
from rainbowadn.data.collection.trees.comparison.protocolcomparator import ProtocolComparator
|
|
|
|
__all__ = ('HashComparator',)
|
|
|
|
KeyType = TypeVar('KeyType')
|
|
|
|
|
|
class HashComparator(ProtocolComparator[KeyType], Generic[KeyType]):
|
|
async def compare(self, original: HashPoint[KeyType], key: HashPoint[KeyType]) -> Comparison:
|
|
assert isinstance(original, HashPoint)
|
|
assert isinstance(key, HashPoint)
|
|
if key.point < original.point:
|
|
return Left()
|
|
elif key.point > original.point:
|
|
return Right()
|
|
else:
|
|
return self.equal
|