33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
from typing import Generic, Optional, TypeVar
|
|
|
|
from rainbowadn.core.hashpoint import HashPoint
|
|
from rainbowadn.data.collection.trees.binary.binarytreesplit import BinaryTreeSplit
|
|
from rainbowadn.data.collection.trees.comparison.comparator import Comparator
|
|
|
|
__all__ = ('BinaryTreeCreationProtocol',)
|
|
|
|
TreeType = TypeVar('TreeType')
|
|
ActiveKeyType = TypeVar('ActiveKeyType')
|
|
MetaDataType = TypeVar('MetaDataType')
|
|
|
|
|
|
class BinaryTreeCreationProtocol(Generic[ActiveKeyType, MetaDataType, TreeType]):
|
|
def __init__(self, comparator: Comparator[ActiveKeyType]):
|
|
self.comparator = comparator
|
|
|
|
async def split(self, tree: TreeType) -> Optional[
|
|
BinaryTreeSplit[ActiveKeyType, MetaDataType, TreeType]
|
|
]:
|
|
"""result of this method is supposed to be used right after the call, therefore all values are resolved"""
|
|
raise NotImplementedError
|
|
|
|
async def fsplit(self, tree: TreeType) -> BinaryTreeSplit[
|
|
ActiveKeyType, MetaDataType, TreeType
|
|
]:
|
|
split: Optional[BinaryTreeSplit[ActiveKeyType, MetaDataType, TreeType]] = await self.split(tree)
|
|
assert split is not None
|
|
return split
|
|
|
|
async def tree(self, treel: TreeType, treer: TreeType, key: HashPoint[ActiveKeyType]) -> TreeType:
|
|
raise NotImplementedError
|