From 2f2ba19f2c5c0d00166054971e98d7573ae96848 Mon Sep 17 00:00:00 2001 From: timotheyca Date: Tue, 26 Jul 2022 03:03:53 +0300 Subject: [PATCH] nullable reference inlining --- rainbowadn/collection/trees/binary/binarytree.py | 3 ++- rainbowadn/nullability/nullablereference.py | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/rainbowadn/collection/trees/binary/binarytree.py b/rainbowadn/collection/trees/binary/binarytree.py index c4143a1..b172d99 100644 --- a/rainbowadn/collection/trees/binary/binarytree.py +++ b/rainbowadn/collection/trees/binary/binarytree.py @@ -19,7 +19,8 @@ class BinaryTree(RecursiveMentionable, Generic[TreeKeyType]): def __init__( self, - treel: NullableReference['BinaryTree[TreeKeyType]'], treer: NullableReference['BinaryTree[TreeKeyType]'], + treel: NullableReference['BinaryTree[TreeKeyType]'], + treer: NullableReference['BinaryTree[TreeKeyType]'], key: HashPoint[TreeKeyType] ): assert isinstance(treel, NullableReference) diff --git a/rainbowadn/nullability/nullablereference.py b/rainbowadn/nullability/nullablereference.py index d5f9ef7..4339169 100644 --- a/rainbowadn/nullability/nullablereference.py +++ b/rainbowadn/nullability/nullablereference.py @@ -1,6 +1,7 @@ -from typing import Generic, Iterable, TypeVar +from typing import Generic, Iterable, Optional, TypeVar from rainbowadn.core import * +from rainbowadn.inlining import * from .notnull import * from .null import * from .nullable import * @@ -69,11 +70,14 @@ class NullableReference(RecursiveMentionable, Generic[Referenced]): return await self.hashpoint().resolve() -class NullableReferenceFactory(RainbowFactory[NullableReference[Referenced]], Generic[Referenced]): +class NullableReferenceFactory(Inlining[NullableReference[Referenced]], Generic[Referenced]): def __init__(self, factory: RainbowFactory[Referenced]): assert isinstance(factory, RainbowFactory) self.factory = factory + def size(self) -> Optional[int]: + return HashPoint.HASH_LENGTH + def from_bytes(self, source: bytes, resolver: HashResolver) -> NullableReference[Referenced]: assert isinstance(source, bytes) assert isinstance(resolver, HashResolver) @@ -81,7 +85,7 @@ class NullableReferenceFactory(RainbowFactory[NullableReference[Referenced]], Ge return NullableReference(Null(), self.factory) else: return NullableReference.of( - ResolverOrigin(self.factory, source, resolver).hash_point() + ResolverMetaOrigin(resolver).hash_point(self.factory, source) ) def loose(self) -> RainbowFactory[NullableReference[Referenced]]: