this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

rename MST 'keys' to 'paths', for clarity

+29 -29
+5 -5
src/atmst/mst/diff.py
··· 127 127 deleted.add(a.frame.node.cid) 128 128 129 129 while True: 130 - while a.rkey != b.rkey: # we need a loop because they might "leapfrog" each other 130 + while a.rpath != b.rpath: # we need a loop because they might "leapfrog" each other 131 131 # "catch up" cursor a, if it's behind 132 - while a.rkey < b.rkey and not a.is_final: 132 + while a.rpath < b.rpath and not a.is_final: 133 133 if a.subtree: # recurse down every subtree 134 134 a.down() 135 135 deleted.add(a.frame.node.cid) ··· 137 137 a.right() 138 138 139 139 # catch up cursor b, likewise 140 - while b.rkey < a.rkey and not b.is_final: 140 + while b.rpath < a.rpath and not b.is_final: 141 141 if b.subtree: # recurse down every subtree 142 142 b.down() 143 143 created.add(b.frame.node.cid) 144 144 else: 145 145 b.right() 146 146 147 - # the rkeys now match, but the subrees below us might not 147 + # the rpaths now match, but the subrees below us might not 148 148 149 149 _mst_diff_recursive(created, deleted, a.subtree_walker(), b.subtree_walker()) 150 150 151 151 # check if we can still go right XXX: do we need to care about the case where one can, but the other can't? 152 152 # To consider: maybe if I just step a, b will catch up automagically 153 - if a.rkey == a.stack[0].rkey and b.rkey == b.stack[0].rkey: 153 + if a.rpath == a.stack[0].rpath and b.rpath == b.stack[0].rpath: 154 154 break 155 155 156 156 a.right()
+23 -23
src/atmst/mst/node_walker.py
··· 18 18 19 19 Recall MSTNode layout: :: 20 20 21 - keys: (lkey) (0, 1, 2, 3) (rkey) 22 - vals: (0, 1, 2, 3) 23 - subtrees: (0, 1, 2, 3, 4) 21 + keys: (lpath) (0, 1, 2, 3) (rpath) 22 + vals: (0, 1, 2, 3) 23 + subtrees: (0, 1, 2, 3, 4) 24 24 25 25 """ 26 - KEY_MIN = "" # string that compares less than all legal key strings 27 - KEY_MAX = "\xff" # string that compares greater than all legal key strings 26 + PATH_MIN = "" # string that compares less than all legal path strings 27 + PATH_MAX = "\xff" # string that compares greater than all legal path strings 28 28 29 29 @dataclass 30 30 class StackFrame: 31 31 node: MSTNode # could store CIDs only to save memory, in theory, but not much point 32 - lkey: str 33 - rkey: str 32 + lpath: str 33 + rpath: str 34 34 idx: int 35 35 36 36 ns: NodeStore 37 37 stack: List[StackFrame] 38 38 39 - def __init__(self, ns: NodeStore, root_cid: Optional[CID], lkey: Optional[str]=KEY_MIN, rkey: Optional[str]=KEY_MAX) -> None: 39 + def __init__(self, ns: NodeStore, root_cid: Optional[CID], lpath: Optional[str]=PATH_MIN, rpath: Optional[str]=PATH_MAX) -> None: 40 40 self.ns = ns 41 41 self.stack = [self.StackFrame( 42 42 node=MSTNode.empty_root() if root_cid is None else self.ns.get_node(root_cid), 43 - lkey=lkey, 44 - rkey=rkey, 43 + lpath=lpath, 44 + rpath=rpath, 45 45 idx=0 46 46 )] 47 47 48 48 def subtree_walker(self) -> Self: 49 - return NodeWalker(self.ns, self.subtree, self.lkey, self.rkey) 49 + return NodeWalker(self.ns, self.subtree, self.lpath, self.rpath) 50 50 51 51 @property 52 52 def frame(self) -> StackFrame: 53 53 return self.stack[-1] 54 54 55 55 @property 56 - def lkey(self) -> str: 57 - return self.frame.lkey if self.frame.idx == 0 else self.frame.node.keys[self.frame.idx - 1] 56 + def lpath(self) -> str: 57 + return self.frame.lpath if self.frame.idx == 0 else self.frame.node.keys[self.frame.idx - 1] 58 58 59 59 @property 60 60 def lval(self) -> Optional[CID]: ··· 64 64 def subtree(self) -> Optional[CID]: 65 65 return self.frame.node.subtrees[self.frame.idx] 66 66 67 - # hmmmm rkey is overloaded here... "right key" not "record key"... 68 67 @property 69 - def rkey(self) -> str: 70 - return self.frame.rkey if self.frame.idx == len(self.frame.node.keys) else self.frame.node.keys[self.frame.idx] 68 + def rpath(self) -> str: 69 + return self.frame.rpath if self.frame.idx == len(self.frame.node.keys) else self.frame.node.keys[self.frame.idx] 71 70 72 71 @property 73 72 def rval(self) -> Optional[CID]: ··· 75 74 76 75 @property 77 76 def is_final(self) -> bool: 78 - return (not self.stack) or (self.subtree is None and self.rkey == self.stack[0].rkey) 77 + return (not self.stack) or (self.subtree is None and self.rpath == self.stack[0].rpath) 79 78 80 79 def right(self) -> None: 81 80 if (self.frame.idx + 1) >= len(self.frame.node.subtrees): ··· 93 92 94 93 self.stack.append(self.StackFrame( 95 94 node=self.ns.get_node(subtree), 96 - lkey=self.lkey, 97 - rkey=self.rkey, 95 + lpath=self.lpath, 96 + rpath=self.rpath, 98 97 idx=0 99 98 )) 100 99 ··· 105 104 while self.subtree: # recurse down every subtree 106 105 self.down() 107 106 self.right() 108 - return self.lkey, self.lval # the kv pair we just jumped over 107 + return self.lpath, self.lval # the kv pair we just jumped over 109 108 110 109 # iterate over every k/v pair in key-sorted order 110 + # NB: should really be p/v standing for path/value 111 111 def iter_kv(self) -> Iterable[Tuple[str, CID]]: 112 112 while not self.is_final: 113 113 yield self.next_kv() ··· 128 128 # start inclusive 129 129 def iter_kv_range(self, start: str, end: str, end_inclusive: bool=False) -> Iterable[Tuple[str, CID]]: 130 130 while True: 131 - while self.rkey < start: 131 + while self.rpath < start: 132 132 self.right() 133 133 if not self.subtree: 134 134 break ··· 141 141 142 142 def find_value(self, key: str) -> Optional[CID]: 143 143 while True: 144 - while self.rkey < key: 144 + while self.rpath < key: 145 145 self.right() 146 146 if not self.subtree: 147 147 break 148 148 self.down() 149 - if self.rkey != key: 149 + if self.rpath != key: 150 150 return None 151 151 return self.rval
+1 -1
tests/test_varint.py
··· 22 22 self.assertRaises(ValueError, decode_varint, io.BytesIO(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f')) # too big 23 23 self.assertRaises(ValueError, decode_varint, io.BytesIO(b"")) # too short 24 24 self.assertRaises(ValueError, decode_varint, io.BytesIO(b'\xff')) # truncated 25 - self.assertRaises(ValueError, decode_varint, io.BytesIO(b"\x80\x00")) # too minimally encoded 25 + self.assertRaises(ValueError, decode_varint, io.BytesIO(b"\x80\x00")) # not minimally encoded 26 26 27 27 if __name__ == '__main__': 28 28 unittest.main(module="tests.test_varint")