header_filter fix + remove several unsustainable classes and interfaces
This commit is contained in:
parent
97fd1105d0
commit
547b233c97
@ -34,7 +34,7 @@ class ReductionStageProtocol(
|
|||||||
if previous.reference.null():
|
if previous.reference.null():
|
||||||
return self.protocol.initial(previous.factory)
|
return self.protocol.initial(previous.factory)
|
||||||
else:
|
else:
|
||||||
return previous.reference.resolve()
|
return self.protocol.header_filter(previous.reference.resolve())
|
||||||
|
|
||||||
def derive_header(
|
def derive_header(
|
||||||
self,
|
self,
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
from typing import Generic, TypeVar
|
|
||||||
|
|
||||||
from rainbowadn.data.collection.collection_interface.collectioninterface import CollectionInterface
|
|
||||||
from rainbowadn.hashing.hashpoint import HashPoint
|
|
||||||
|
|
||||||
__all__ = ('ActiveCollectionInterface',)
|
|
||||||
|
|
||||||
CollectionType = TypeVar('CollectionType')
|
|
||||||
KeyType = TypeVar('KeyType')
|
|
||||||
|
|
||||||
|
|
||||||
class ActiveCollectionInterface(CollectionInterface[CollectionType], Generic[CollectionType, KeyType]):
|
|
||||||
def add(self, key: HashPoint[KeyType]) -> 'ActiveCollectionInterface[KeyType]':
|
|
||||||
raise NotImplementedError
|
|
@ -1,17 +0,0 @@
|
|||||||
from typing import Generic, TypeVar
|
|
||||||
|
|
||||||
from rainbowadn.hashing.nullability.nullablereference import NullableReference
|
|
||||||
|
|
||||||
__all__ = ('CollectionFactory',)
|
|
||||||
|
|
||||||
CollectionType = TypeVar('CollectionType')
|
|
||||||
InterfaceType = TypeVar('InterfaceType')
|
|
||||||
|
|
||||||
|
|
||||||
class CollectionFactory(
|
|
||||||
Generic[CollectionType, InterfaceType],
|
|
||||||
):
|
|
||||||
"""вперёд, уроды, вас ждут заводы"""
|
|
||||||
|
|
||||||
def from_reference(self, source: NullableReference[CollectionType]) -> InterfaceType:
|
|
||||||
raise NotImplementedError
|
|
@ -1,13 +0,0 @@
|
|||||||
from typing import Generic, TypeVar
|
|
||||||
|
|
||||||
from rainbowadn.hashing.hashpoint import HashPoint
|
|
||||||
from rainbowadn.hashing.nullability.nullable import Nullable
|
|
||||||
|
|
||||||
__all__ = ('QueryCollectionInterface',)
|
|
||||||
|
|
||||||
KeyType = TypeVar('KeyType')
|
|
||||||
|
|
||||||
|
|
||||||
class QueryCollectionInterface(Generic[KeyType]):
|
|
||||||
def query(self, key: HashPoint[KeyType]) -> Nullable[HashPoint[KeyType]]:
|
|
||||||
raise NotImplementedError
|
|
@ -1,36 +0,0 @@
|
|||||||
from typing import Generic, TypeVar
|
|
||||||
|
|
||||||
from rainbowadn.data.collection.collection_interface.querycollectioninterface import QueryCollectionInterface
|
|
||||||
from rainbowadn.data.collection.keymetadata import KeyMetadata
|
|
||||||
from rainbowadn.hashing.hashpoint import HashPoint
|
|
||||||
from rainbowadn.hashing.nullability.notnull import NotNull
|
|
||||||
from rainbowadn.hashing.nullability.null import Null
|
|
||||||
from rainbowadn.hashing.nullability.nullable import Nullable
|
|
||||||
|
|
||||||
__all__ = ('KeyMetadataQueryCollection',)
|
|
||||||
|
|
||||||
ActiveKeyType = TypeVar('ActiveKeyType')
|
|
||||||
MetaDataType = TypeVar('MetaDataType')
|
|
||||||
|
|
||||||
|
|
||||||
class KeyMetadataQueryCollection(QueryCollectionInterface[ActiveKeyType], Generic[ActiveKeyType, MetaDataType]):
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
metadata: HashPoint[MetaDataType],
|
|
||||||
collection: QueryCollectionInterface[KeyMetadata[ActiveKeyType, MetaDataType]],
|
|
||||||
):
|
|
||||||
assert isinstance(metadata, HashPoint)
|
|
||||||
assert isinstance(collection, QueryCollectionInterface)
|
|
||||||
self.metadata = metadata
|
|
||||||
self.collection = collection
|
|
||||||
|
|
||||||
def query(self, key: HashPoint[ActiveKeyType]) -> Nullable[HashPoint[ActiveKeyType]]:
|
|
||||||
assert isinstance(key, HashPoint)
|
|
||||||
result: Nullable[
|
|
||||||
HashPoint[KeyMetadata[ActiveKeyType, MetaDataType]]
|
|
||||||
] = self.collection.query(HashPoint.of(KeyMetadata(key, self.metadata)))
|
|
||||||
assert isinstance(result, Nullable)
|
|
||||||
if result.null():
|
|
||||||
return Null()
|
|
||||||
else:
|
|
||||||
return NotNull(result.resolve().resolve().key)
|
|
@ -1,26 +0,0 @@
|
|||||||
from typing import Generic, TypeVar
|
|
||||||
|
|
||||||
from rainbowadn.data.collection.collection_interface.activecollectioninterface import ActiveCollectionInterface
|
|
||||||
from rainbowadn.data.collection.keyvalue import KeyValue
|
|
||||||
from rainbowadn.hashing.hashpoint import HashPoint
|
|
||||||
|
|
||||||
__all__ = ('ActiveMapping',)
|
|
||||||
|
|
||||||
KVKeyType = TypeVar('KVKeyType')
|
|
||||||
KVValueType = TypeVar('KVValueType')
|
|
||||||
|
|
||||||
|
|
||||||
class ActiveMapping(Generic[KVKeyType, KVValueType]):
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
collection: ActiveCollectionInterface[KeyValue[KVKeyType, KVValueType]]
|
|
||||||
):
|
|
||||||
assert isinstance(collection, ActiveCollectionInterface)
|
|
||||||
self.collection = collection
|
|
||||||
|
|
||||||
def add(self, key: HashPoint[KVKeyType], value: HashPoint[KVValueType]) -> 'ActiveMapping[KVKeyType, KVValueType]':
|
|
||||||
assert isinstance(key, HashPoint)
|
|
||||||
assert isinstance(value, HashPoint)
|
|
||||||
return ActiveMapping(
|
|
||||||
self.collection.add(HashPoint.of(KeyValue(key, value)))
|
|
||||||
)
|
|
@ -1,38 +0,0 @@
|
|||||||
from typing import Generic, TypeVar
|
|
||||||
|
|
||||||
from rainbowadn.data.collection.collection_interface.querycollectioninterface import QueryCollectionInterface
|
|
||||||
from rainbowadn.data.collection.keyvalue import KeyValue
|
|
||||||
from rainbowadn.hashing.hashpoint import HashPoint
|
|
||||||
from rainbowadn.hashing.nullability.notnull import NotNull
|
|
||||||
from rainbowadn.hashing.nullability.null import Null
|
|
||||||
from rainbowadn.hashing.nullability.nullable import Nullable
|
|
||||||
|
|
||||||
__all__ = ('QueryMapping',)
|
|
||||||
|
|
||||||
KVKeyType = TypeVar('KVKeyType')
|
|
||||||
KVValueType = TypeVar('KVValueType')
|
|
||||||
|
|
||||||
|
|
||||||
class QueryMapping(Generic[KVKeyType, KVValueType]):
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
collection: QueryCollectionInterface[KeyValue[KVKeyType, KVValueType]],
|
|
||||||
empty_value: HashPoint[KVValueType]
|
|
||||||
):
|
|
||||||
assert isinstance(collection, QueryCollectionInterface)
|
|
||||||
assert isinstance(empty_value, HashPoint)
|
|
||||||
self.collection = collection
|
|
||||||
self.empty_value = empty_value
|
|
||||||
|
|
||||||
def query(self, key: HashPoint[KVKeyType]) -> Nullable[HashPoint[KVValueType]]:
|
|
||||||
assert isinstance(key, HashPoint)
|
|
||||||
query_result: Nullable[
|
|
||||||
HashPoint[KeyValue[KVKeyType, KVValueType]]
|
|
||||||
] = self.collection.query(HashPoint.of(KeyValue(key, self.empty_value)))
|
|
||||||
assert isinstance(query_result, Nullable)
|
|
||||||
if query_result.null():
|
|
||||||
return Null()
|
|
||||||
else:
|
|
||||||
key_value: KeyValue[KVKeyType, KVValueType] = query_result.resolve().resolve()
|
|
||||||
assert isinstance(key_value, KeyValue)
|
|
||||||
return NotNull(key_value.value)
|
|
@ -60,3 +60,6 @@ class PairFactory(
|
|||||||
ResolverOrigin(self.e0_factory, source[:HashPoint.HASH_LENGTH], resolver).hash_point(),
|
ResolverOrigin(self.e0_factory, source[:HashPoint.HASH_LENGTH], resolver).hash_point(),
|
||||||
ResolverOrigin(self.e1_factory, source[HashPoint.HASH_LENGTH:], resolver).hash_point(),
|
ResolverOrigin(self.e1_factory, source[HashPoint.HASH_LENGTH:], resolver).hash_point(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def loose(self) -> RainbowFactory[Pair[E0Type, E1Type]]:
|
||||||
|
return self
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
from typing import Generic, Optional, TypeVar
|
from typing import Generic, Optional, TypeVar
|
||||||
|
|
||||||
from rainbowadn.data.collection.collection_interface.activecollectioninterface import ActiveCollectionInterface
|
from rainbowadn.data.collection.collection_interface.collectioninterface import CollectionInterface
|
||||||
from rainbowadn.data.collection.collection_interface.querycollectioninterface import QueryCollectionInterface
|
|
||||||
from rainbowadn.data.collection.keymetadata import KeyMetadata, KeyMetadataFactory
|
from rainbowadn.data.collection.keymetadata import KeyMetadata, KeyMetadataFactory
|
||||||
from rainbowadn.data.collection.keymetadataquerycollection import KeyMetadataQueryCollection
|
|
||||||
from rainbowadn.data.collection.trees.binary.balancedtreecreationprotocol import BalancedTreeCreationProtocol
|
from rainbowadn.data.collection.trees.binary.balancedtreecreationprotocol import BalancedTreeCreationProtocol
|
||||||
from rainbowadn.data.collection.trees.binary.binarytree import BinaryTree, BinaryTreeFactory
|
from rainbowadn.data.collection.trees.binary.binarytree import BinaryTree, BinaryTreeFactory
|
||||||
from rainbowadn.data.collection.trees.binary.binarytreebalancingprotocol import BinaryTreeBalancingProtocol
|
from rainbowadn.data.collection.trees.binary.binarytreebalancingprotocol import BinaryTreeBalancingProtocol
|
||||||
from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol
|
from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol
|
||||||
from rainbowadn.data.collection.trees.binary.querybinarytree import QueryBinaryTree
|
|
||||||
from rainbowadn.data.collection.trees.comparison.comparator import (Comparator, Comparison, Equal, Left, Replace, Right)
|
from rainbowadn.data.collection.trees.comparison.comparator import (Comparator, Comparison, Equal, Left, Replace, Right)
|
||||||
from rainbowadn.data.collection.trees.comparison.keyedcomparator import KeyedComparator
|
|
||||||
from rainbowadn.hashing.hashpoint import HashPoint
|
from rainbowadn.hashing.hashpoint import HashPoint
|
||||||
from rainbowadn.hashing.nullability.null import Null
|
from rainbowadn.hashing.nullability.null import Null
|
||||||
from rainbowadn.hashing.nullability.nullablereference import NullableReference
|
from rainbowadn.hashing.nullability.nullablereference import NullableReference
|
||||||
@ -23,7 +19,7 @@ MetaDataType = TypeVar('MetaDataType')
|
|||||||
|
|
||||||
|
|
||||||
class ActiveBinaryTree(
|
class ActiveBinaryTree(
|
||||||
ActiveCollectionInterface[BinaryTree[KeyMetadata[ActiveKeyType, MetaDataType]], ActiveKeyType],
|
CollectionInterface[BinaryTree[KeyMetadata[ActiveKeyType, MetaDataType]]],
|
||||||
Generic[ActiveKeyType, MetaDataType]
|
Generic[ActiveKeyType, MetaDataType]
|
||||||
):
|
):
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -85,14 +81,14 @@ class ActiveBinaryTree(
|
|||||||
|
|
||||||
def pop(
|
def pop(
|
||||||
self,
|
self,
|
||||||
tree_split: tuple[
|
split: tuple[
|
||||||
'ActiveBinaryTree[ActiveKeyType, MetaDataType]',
|
'ActiveBinaryTree[ActiveKeyType, MetaDataType]',
|
||||||
HashPoint[ActiveKeyType],
|
HashPoint[ActiveKeyType],
|
||||||
HashPoint[MetaDataType],
|
HashPoint[MetaDataType],
|
||||||
'ActiveBinaryTree[ActiveKeyType, MetaDataType]'
|
'ActiveBinaryTree[ActiveKeyType, MetaDataType]'
|
||||||
]
|
]
|
||||||
) -> tuple['ActiveBinaryTree[ActiveKeyType, MetaDataType]', HashPoint[ActiveKeyType]]:
|
) -> tuple['ActiveBinaryTree[ActiveKeyType, MetaDataType]', HashPoint[ActiveKeyType]]:
|
||||||
treel, original, _, treer = tree_split
|
treel, original, _, treer = split
|
||||||
if (splitl := self.creation.split(treel)) is None:
|
if (splitl := self.creation.split(treel)) is None:
|
||||||
return treer, original
|
return treer, original
|
||||||
else:
|
else:
|
||||||
@ -106,11 +102,11 @@ class ActiveBinaryTree(
|
|||||||
if (split := self.creation.split(self)) is None:
|
if (split := self.creation.split(self)) is None:
|
||||||
return self
|
return self
|
||||||
else:
|
else:
|
||||||
treel, original, _, treer = tree_split = split
|
treel, original, _, treer = split
|
||||||
comparison: Comparison = self.comparator.compare(original, key)
|
comparison: Comparison = self.comparator.compare(original, key)
|
||||||
assert isinstance(comparison, Comparison)
|
assert isinstance(comparison, Comparison)
|
||||||
if isinstance(comparison, Equal):
|
if isinstance(comparison, Equal):
|
||||||
return self.pop(tree_split)[0]
|
return self.pop(split)[0]
|
||||||
elif isinstance(comparison, Left):
|
elif isinstance(comparison, Left):
|
||||||
return self.creation.tree(treel.remove(key), treer, original)
|
return self.creation.tree(treel.remove(key), treer, original)
|
||||||
elif isinstance(comparison, Right):
|
elif isinstance(comparison, Right):
|
||||||
@ -118,11 +114,27 @@ class ActiveBinaryTree(
|
|||||||
else:
|
else:
|
||||||
raise TypeError
|
raise TypeError
|
||||||
|
|
||||||
def query_tree(self) -> QueryCollectionInterface[ActiveKeyType]:
|
def contains(self, key: HashPoint[ActiveKeyType]) -> bool:
|
||||||
return KeyMetadataQueryCollection(
|
assert isinstance(key, HashPoint)
|
||||||
self.protocol.empty_metadata(),
|
if (split := self.creation.split(self)) is None:
|
||||||
QueryBinaryTree(KeyedComparator(self.comparator), self.reference)
|
return False
|
||||||
)
|
else:
|
||||||
|
treel, original, _, treer = split
|
||||||
|
comparison: Comparison = self.comparator.compare(original, key)
|
||||||
|
assert isinstance(comparison, Comparison)
|
||||||
|
if isinstance(comparison, Equal):
|
||||||
|
return True
|
||||||
|
elif isinstance(comparison, Left):
|
||||||
|
return treel.contains(key)
|
||||||
|
elif isinstance(comparison, Right):
|
||||||
|
return treer.contains(key)
|
||||||
|
else:
|
||||||
|
raise TypeError
|
||||||
|
|
||||||
|
def loose(self) -> CollectionInterface[
|
||||||
|
BinaryTree[KeyMetadata[ActiveKeyType, MetaDataType]]
|
||||||
|
]:
|
||||||
|
return self
|
||||||
|
|
||||||
|
|
||||||
class ActiveCreationProtocol(BalancedTreeCreationProtocol[ActiveKeyType, MetaDataType, ActiveBinaryTree]):
|
class ActiveCreationProtocol(BalancedTreeCreationProtocol[ActiveKeyType, MetaDataType, ActiveBinaryTree]):
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
from typing import Generic, TypeVar
|
|
||||||
|
|
||||||
from rainbowadn.data.collection.collection_interface.querycollectioninterface import QueryCollectionInterface
|
|
||||||
from rainbowadn.data.collection.trees.binary.binarytree import BinaryTree
|
|
||||||
from rainbowadn.data.collection.trees.comparison.comparator import Comparator, Comparison, Equal, Left, Right
|
|
||||||
from rainbowadn.hashing.hashpoint import HashPoint
|
|
||||||
from rainbowadn.hashing.nullability.notnull import NotNull
|
|
||||||
from rainbowadn.hashing.nullability.null import Null
|
|
||||||
from rainbowadn.hashing.nullability.nullable import Nullable
|
|
||||||
from rainbowadn.hashing.nullability.nullablereference import NullableReference
|
|
||||||
|
|
||||||
__all__ = ('QueryBinaryTree',)
|
|
||||||
|
|
||||||
KeyType = TypeVar('KeyType')
|
|
||||||
|
|
||||||
|
|
||||||
class QueryBinaryTree(QueryCollectionInterface[KeyType], Generic[KeyType]):
|
|
||||||
def __init__(
|
|
||||||
self, comparator: Comparator[KeyType], reference: NullableReference[BinaryTree[KeyType]]
|
|
||||||
):
|
|
||||||
assert isinstance(comparator, Comparator)
|
|
||||||
assert isinstance(reference, NullableReference)
|
|
||||||
self.comparator = comparator
|
|
||||||
self.reference = reference
|
|
||||||
|
|
||||||
def query(self, key: HashPoint[KeyType]) -> Nullable[HashPoint[KeyType]]:
|
|
||||||
assert isinstance(key, HashPoint)
|
|
||||||
reference: Nullable[HashPoint[BinaryTree[KeyType]]] = self.reference.reference
|
|
||||||
assert isinstance(reference, Nullable)
|
|
||||||
if reference.null():
|
|
||||||
return Null()
|
|
||||||
else:
|
|
||||||
hash_point: HashPoint[BinaryTree[KeyType]] = reference.resolve()
|
|
||||||
assert isinstance(hash_point, HashPoint)
|
|
||||||
tree: BinaryTree[KeyType] = hash_point.resolve()
|
|
||||||
assert isinstance(tree, BinaryTree)
|
|
||||||
comparison: Comparison = self.comparator.compare(tree.key, key)
|
|
||||||
assert isinstance(comparison, Comparison)
|
|
||||||
if isinstance(comparison, Equal):
|
|
||||||
return NotNull(tree.key)
|
|
||||||
elif isinstance(comparison, Left):
|
|
||||||
return QueryBinaryTree(self.comparator, tree.treel).query(key)
|
|
||||||
elif isinstance(comparison, Right):
|
|
||||||
return QueryBinaryTree(self.comparator, tree.treer).query(key)
|
|
||||||
else:
|
|
||||||
raise TypeError
|
|
@ -17,6 +17,8 @@ EncryptedType = TypeVar('EncryptedType')
|
|||||||
|
|
||||||
|
|
||||||
class Encrypted(RecursiveMentionable, Generic[EncryptedType]):
|
class Encrypted(RecursiveMentionable, Generic[EncryptedType]):
|
||||||
|
"""unstable"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
key: bytes,
|
key: bytes,
|
||||||
@ -148,9 +150,6 @@ class EncryptedFactory(RainbowFactory[Encrypted[EncryptedType]], Generic[Encrypt
|
|||||||
decrypted
|
decrypted
|
||||||
)
|
)
|
||||||
|
|
||||||
def loose(self) -> RainbowFactory[Encrypted[EncryptedType]]:
|
|
||||||
return self
|
|
||||||
|
|
||||||
|
|
||||||
class EncryptedResolver(HashResolver):
|
class EncryptedResolver(HashResolver):
|
||||||
def __init__(self, mapping: dict[bytes, HashPoint[Encrypted]], key: bytes):
|
def __init__(self, mapping: dict[bytes, HashPoint[Encrypted]], key: bytes):
|
||||||
|
@ -11,6 +11,7 @@ from rainbowadn.chain.chaincollectioninterface import ChainCollectionInterface
|
|||||||
from rainbowadn.chain.reduction.reductionchainmetafactory import ReductionChainMetaFactory
|
from rainbowadn.chain.reduction.reductionchainmetafactory import ReductionChainMetaFactory
|
||||||
from rainbowadn.data.atomic.integer import Integer
|
from rainbowadn.data.atomic.integer import Integer
|
||||||
from rainbowadn.data.atomic.plain import Plain
|
from rainbowadn.data.atomic.plain import Plain
|
||||||
|
from rainbowadn.data.collection.pair import Pair, PairFactory
|
||||||
from rainbowadn.data.collection.trees.binary.activebinarytree import ActiveBinaryTree
|
from rainbowadn.data.collection.trees.binary.activebinarytree import ActiveBinaryTree
|
||||||
from rainbowadn.data.collection.trees.binary.avl import AVLBTBP
|
from rainbowadn.data.collection.trees.binary.avl import AVLBTBP
|
||||||
from rainbowadn.data.collection.trees.comparison.comparator import Replace
|
from rainbowadn.data.collection.trees.comparison.comparator import Replace
|
||||||
@ -18,6 +19,7 @@ from rainbowadn.data.collection.trees.comparison.plaincomparator import PlainCom
|
|||||||
from rainbowadn.encryption.encrypted import Encrypted
|
from rainbowadn.encryption.encrypted import Encrypted
|
||||||
from rainbowadn.hashing.hashpoint import HashPoint
|
from rainbowadn.hashing.hashpoint import HashPoint
|
||||||
from rainbowadn.hashing.nullability.notnull import NotNull
|
from rainbowadn.hashing.nullability.notnull import NotNull
|
||||||
|
from rainbowadn.hashing.rainbow_factory import RainbowFactory
|
||||||
from rainbowadn.hashing.resolvermetaorigin import ResolverMetaOrigin
|
from rainbowadn.hashing.resolvermetaorigin import ResolverMetaOrigin
|
||||||
from rainbowadn.testing.dictresolver import DictResolver
|
from rainbowadn.testing.dictresolver import DictResolver
|
||||||
from rainbowadn.v13.algo import MINT_CONST
|
from rainbowadn.v13.algo import MINT_CONST
|
||||||
@ -31,6 +33,7 @@ from rainbowadn.wrisbt.wrisbtroot import WrisbtRoot
|
|||||||
|
|
||||||
class TestAll(unittest.TestCase):
|
class TestAll(unittest.TestCase):
|
||||||
"""examples rather than real tests"""
|
"""examples rather than real tests"""
|
||||||
|
|
||||||
def test_bankchain(self):
|
def test_bankchain(self):
|
||||||
with self.subTest('setup'):
|
with self.subTest('setup'):
|
||||||
dr = DictResolver()
|
dr = DictResolver()
|
||||||
@ -84,13 +87,14 @@ class TestAll(unittest.TestCase):
|
|||||||
return delta
|
return delta
|
||||||
|
|
||||||
dr = DictResolver()
|
dr = DictResolver()
|
||||||
n = 10000
|
n = 2500
|
||||||
|
keysize = 7
|
||||||
with self.subTest('create empty'):
|
with self.subTest('create empty'):
|
||||||
btree = WrisbtRoot.empty(WrisbtParametres(1, 5))
|
btree = WrisbtRoot.empty(WrisbtParametres(1, keysize))
|
||||||
measure('init')
|
measure('init')
|
||||||
with self.subTest('add keys', n=n):
|
with self.subTest('add keys', n=n):
|
||||||
for _ in range(n):
|
for _ in range(n):
|
||||||
key = os.urandom(5)
|
key = os.urandom(keysize)
|
||||||
assert not btree.contains(key)
|
assert not btree.contains(key)
|
||||||
btree = btree.add(key)
|
btree = btree.add(key)
|
||||||
assert btree.contains(key)
|
assert btree.contains(key)
|
||||||
@ -105,7 +109,7 @@ class TestAll(unittest.TestCase):
|
|||||||
measure('resolve and iterate')
|
measure('resolve and iterate')
|
||||||
with self.subTest('resolve and add', n=n):
|
with self.subTest('resolve and add', n=n):
|
||||||
for _ in range(n):
|
for _ in range(n):
|
||||||
key = os.urandom(5)
|
key = os.urandom(keysize)
|
||||||
assert not btree.contains(key)
|
assert not btree.contains(key)
|
||||||
btree = btree.add(key)
|
btree = btree.add(key)
|
||||||
assert btree.contains(key)
|
assert btree.contains(key)
|
||||||
@ -114,12 +118,20 @@ class TestAll(unittest.TestCase):
|
|||||||
|
|
||||||
def test_wrisbt_index(self):
|
def test_wrisbt_index(self):
|
||||||
with self.subTest('create empty'):
|
with self.subTest('create empty'):
|
||||||
chain: ChainCollectionInterface[Any, Plain, WrisbtRoot] = BlockChainFactory(
|
factory: RainbowFactory[Pair[Plain, Plain]] = PairFactory(Plain.factory(), Plain.factory()).loose()
|
||||||
WrisbtChainProtocol(Plain.factory(), 2).loose()
|
chain: ChainCollectionInterface[Any, Pair[Plain, Plain], WrisbtRoot] = BlockChainFactory(
|
||||||
|
WrisbtChainProtocol(factory, 2).loose()
|
||||||
).empty().loose()
|
).empty().loose()
|
||||||
with self.subTest('fill'):
|
with self.subTest('fill'):
|
||||||
for _ in range(1000):
|
for _ in range(1000):
|
||||||
chain = chain.add(HashPoint.of(Plain(os.urandom(16))))
|
chain = chain.add(
|
||||||
|
HashPoint.of(
|
||||||
|
Pair(
|
||||||
|
HashPoint.of(Plain(os.urandom(16))),
|
||||||
|
HashPoint.of(Plain(os.urandom(16)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
with self.subTest('check'):
|
with self.subTest('check'):
|
||||||
assert chain
|
assert chain
|
||||||
with self.subTest('measure height'):
|
with self.subTest('measure height'):
|
||||||
@ -135,6 +147,14 @@ class TestAll(unittest.TestCase):
|
|||||||
tree = tree.add(HashPoint.of(Plain(bytes([ord('A') + i]))))
|
tree = tree.add(HashPoint.of(Plain(bytes([ord('A') + i]))))
|
||||||
print(tree.reference.str(0))
|
print(tree.reference.str(0))
|
||||||
|
|
||||||
|
def test_avl_stress(self):
|
||||||
|
tree: ActiveBinaryTree[Plain, Integer] = ActiveBinaryTree.empty(
|
||||||
|
AVLBTBP(PlainComparator(Replace())), Plain.factory()
|
||||||
|
)
|
||||||
|
for i in range(250):
|
||||||
|
tree = tree.add(HashPoint.of(Plain(os.urandom(16))))
|
||||||
|
print(tree.loose().reference.reference.resolve().resolve().key.resolve().metadata.resolve().integer)
|
||||||
|
|
||||||
def test_encryption(self):
|
def test_encryption(self):
|
||||||
with self.subTest('setup'):
|
with self.subTest('setup'):
|
||||||
key = b'a' * 32
|
key = b'a' * 32
|
||||||
|
@ -101,8 +101,8 @@ class BankState(RecursiveMentionable, StaticMentionable):
|
|||||||
minted: ActiveBinaryTree[Coin, Integer] = self.minted_tree()
|
minted: ActiveBinaryTree[Coin, Integer] = self.minted_tree()
|
||||||
used: ActiveBinaryTree[Coin, Integer] = self.used_tree()
|
used: ActiveBinaryTree[Coin, Integer] = self.used_tree()
|
||||||
for in_coin in coins:
|
for in_coin in coins:
|
||||||
assert not minted.query_tree().query(in_coin).null()
|
assert minted.contains(in_coin)
|
||||||
assert used.query_tree().query(in_coin).null()
|
assert not used.contains(in_coin)
|
||||||
used = used.add(in_coin)
|
used = used.add(in_coin)
|
||||||
return BankState(self.minted, used.reference, self.miner, self.length)
|
return BankState(self.minted, used.reference, self.miner, self.length)
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ class BankState(RecursiveMentionable, StaticMentionable):
|
|||||||
miner = self.miner_nullable()
|
miner = self.miner_nullable()
|
||||||
minted: ActiveBinaryTree[Coin, Integer] = self.minted_tree()
|
minted: ActiveBinaryTree[Coin, Integer] = self.minted_tree()
|
||||||
for coin, miner in transaction.iter_coins(self.mint(), miner):
|
for coin, miner in transaction.iter_coins(self.mint(), miner):
|
||||||
assert minted.query_tree().query(HashPoint.of(coin)).null()
|
assert not minted.contains(HashPoint.of(coin))
|
||||||
minted = minted.add(HashPoint.of(coin))
|
minted = minted.add(HashPoint.of(coin))
|
||||||
assert isinstance(minted, ActiveBinaryTree)
|
assert isinstance(minted, ActiveBinaryTree)
|
||||||
return BankState(minted.reference, self.used, NullableReference(miner, self.miner.factory), self.length)
|
return BankState(minted.reference, self.used, NullableReference(miner, self.miner.factory), self.length)
|
||||||
|
@ -90,9 +90,6 @@ class Coin(RecursiveMentionable, StaticMentionable):
|
|||||||
ResolverOrigin(Integer.factory(), source[2 * HashPoint.HASH_LENGTH:], resolver).hash_point(),
|
ResolverOrigin(Integer.factory(), source[2 * HashPoint.HASH_LENGTH:], resolver).hash_point(),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f'(coin)'
|
|
||||||
|
|
||||||
def str(self, tab: int) -> str:
|
def str(self, tab: int) -> str:
|
||||||
assert isinstance(tab, int)
|
assert isinstance(tab, int)
|
||||||
return f'(' \
|
return f'(' \
|
||||||
@ -266,9 +263,6 @@ class Transaction(RecursiveMentionable, StaticMentionable):
|
|||||||
assert data.verify(self.signatures, mint)
|
assert data.verify(self.signatures, mint)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f'(transaction)'
|
|
||||||
|
|
||||||
def str(self, tab: int) -> str:
|
def str(self, tab: int) -> str:
|
||||||
assert isinstance(tab, int)
|
assert isinstance(tab, int)
|
||||||
return f'(' \
|
return f'(' \
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import Iterable, Optional
|
from typing import Iterable
|
||||||
|
|
||||||
from rainbowadn.data.atomic.integer import Integer
|
from rainbowadn.data.atomic.integer import Integer
|
||||||
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate
|
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate
|
||||||
@ -85,11 +85,9 @@ class WrisbtRoot(RecursiveMentionable):
|
|||||||
return list(self.root.resolve().iter_keys())
|
return list(self.root.resolve().iter_keys())
|
||||||
|
|
||||||
def index(
|
def index(
|
||||||
self, target: HashPoint, exclude: Optional['WrisbtRoot']
|
self, target: HashPoint, exclude: 'WrisbtRoot'
|
||||||
) -> 'WrisbtRoot':
|
) -> 'WrisbtRoot':
|
||||||
assert isinstance(target, HashPoint)
|
assert isinstance(target, HashPoint)
|
||||||
if exclude is None:
|
|
||||||
exclude = self.empty(self.parametres)
|
|
||||||
assert isinstance(exclude, WrisbtRoot)
|
assert isinstance(exclude, WrisbtRoot)
|
||||||
key: bytes = target.point
|
key: bytes = target.point
|
||||||
assert isinstance(key, bytes)
|
assert isinstance(key, bytes)
|
||||||
|
Loading…
Reference in New Issue
Block a user