from pathlib import Path
from bluebase.core import (
Domain,
dump,
assignment,
)
from bluebase.pf import (
PfPageHeader,
PfManager,
)
from .node import (
IxNodeHeader,
IxPointer,
)
from .index import IxIndex
__all__ = (
'IxManager',
)
[docs]
class IxManager:
"""
A manager for the `IX <bluebase.ix>` component.
Attributes:
pf:
"""
pf: PfManager
def __repr__(self) -> str: # pragma: no cover
return f"IxManager({dump(pf=self.pf)})"
def __init__(self, pf: PfManager | None = None) -> None:
self.pf = pf or PfManager()
[docs]
def get_numbered_path(self, path: Path, number: int) -> Path:
"""
"""
return path.with_suffix(f'.index.{number}')
[docs]
def calc_slot_capacity(self, domain: Domain) -> int:
"""
"""
capacity = 0
while True:
estimate = sum((
PfPageHeader.size,
IxNodeHeader.size,
(capacity + 1) * domain.size,
(capacity + 2) * IxPointer.size,
))
if estimate > self.pf.page_size:
break
capacity += 1
return capacity
[docs]
@assignment
def create_index(self, path: Path, number: int, domain: Domain) -> None:
"""
"""
raise NotImplementedError
[docs]
@assignment
def destroy_index(self, path: Path, number: int) -> None:
"""
"""
raise NotImplementedError
[docs]
@assignment
def open_index(self, path: Path, number: int) -> IxIndex:
"""
"""
raise NotImplementedError
[docs]
@assignment
def close_index(self, index: IxIndex) -> None:
"""
"""
raise NotImplementedError