def _traceindex(self, pos, node=None, addr=[], fail=True): # Returns (addr, pos) for an index in the flat rep of the node node = node or self.node addr = address.Address(addr) for i in range(len(node) + 1): for c in node.index(i): index = i + len(node) # naddr = new address # pos = overwritten with leftovers naddr, pos = self._traceindex(pos, node.get(index, c), addr + [index, c], False) if naddr != None: return naddr, pos # Check for finish, kill one for nondeleted characters if pos == 0: return addr, i + len(node) elif i < len(node) and not node._del[i]: pos -= 1 if fail: raise IndexError( "pos out of range, longer than len(node.flatten())") else: return None, pos
def set(self, key, value): if self.has(key): # Use existing SingleNode r = self.get(key).context().set(value) return address.Address([key, "/single"])+r else: # Make Singlenode s = instruction.InsertSingle([], key) # Make actual node n = node.make(value).op(0, [key, "/single"]) return s + n
def _traceelem(self, pos, node = None, addr = [], fail=True): # Returns (addr, pos) for a char in the flat rep of the node node = node or self.node addr = address.Address(addr) for i in range(len(node)+1): for c in node._children[i]: # naddr = new address # pos = overwritten with leftovers naddr, pos = self._traceelem(pos, node.get(i,c), addr+[i,c], False) if naddr != None: return naddr, pos if i < len(node) and not node._del[i]: if pos == 0: return addr, i else: pos -= 1 if fail: raise IndexError("pos out of range, longer than len(node.flatten())-1") else: return None, pos