def increaseHeight( self ): old_sentinel_l = self._start old_sentinel_r = self._start._next new_sentinel_l = SkipListNode( self._MIN_VALUE, None, None, old_sentinel_l, None ) new_sentinel_r = SkipListNode( self._MAX_VALUE, new_sentinel_l, None, old_sentinel_r, None ) new_sentinel_l._next = new_sentinel_r old_sentinel_l._abov = new_sentinel_l old_sentinel_r._abov = new_sentinel_r self._height += 1 self._start = new_sentinel_l
def insertAfterAbove( self, p, q, element ): newnode = SkipListNode( element, p, p._next, q, None ) p._next._prev = newnode p._next = newnode if not( q is None ): q._abov = newnode return newnode
def updateSkipListOnInsert(self, pathname, data, verbose=False): ''' Adds a new pathname to the skiplist, with related data. To be called on each insertion. @pathname: the pathname to be inserted in the structure @data: its related file content hash. raise: SkipListHandlingException if illegal operations are performed. ''' if self._isGuard(pathname): raise SkipListHandlingException("%s is a guard!" % pathname) if pathname in self.pathnames: raise SkipListHandlingException("Pathname %s already in set" % pathname) if data == None: raise SkipListHandlingException( "Trying to insert a pathname %s with None filehash attached: " % pathname) self.pathnames.append(pathname) newleaf = SkipListNode(pathname, 0, data, filehash=data) newplateau = self._buildTower(newleaf) self.leaves[pathname] = newleaf self.plateaus[pathname] = newplateau node = newleaf while isinstance(node, SkipListNode): self._interposeNewNode(node) node = node.father self._linkLeftBuddy(newplateau) newplateau.outdateAncestors() if verbose: self.logger.debug( '(%s) Pathname %s inserted in skip list with %s.' % (self.who, pathname, data))
def increaseHeight(self): #on retient les anciennes sentinelles du plus haut niveau old_sentinel_l = self._start old_sentinel_r = self._start._next #on crée deux nouvelles sentinelles pour la nouveau niveau new_sentinel_l = SkipListNode(self._MIN_VALUE, None, None, old_sentinel_l, None) new_sentinel_r = SkipListNode(self._MAX_VALUE, new_sentinel_l, None, old_sentinel_r, None) new_sentinel_l._next = new_sentinel_r #on relie les pointeurs du dessus des vielles sentinelles aux nouvelles old_sentinel_l._abov = new_sentinel_l old_sentinel_r._abov = new_sentinel_r #on augmente la variable qui indique la hauteur de la skiplist self._height += 1 #on ajuste le début de la skiplist self._start = new_sentinel_l
def _createUpperNode(self, lower_node): ''' Creates a father node in a column, given a child node. Returns the newly created upper node. ''' new_node = SkipListNode(lower_node.pathname, lower_node.height + 1) self._linkLowerChild(new_node, lower_node) return new_node
def _comparePathnames(a, b): ''' Comparison function: - uses alphanumeric ordering - +/-INF are lower and greate values possible Returns 1 if a is gt b Returns -1 if a is lt b Returns 0 if a is eq b ''' return SkipListNode.comparePathnames(a, b)
def __init__(self): ''' Main fields are initialized at start. ''' self.pathnames = [NEGATIVE_INFINITE, POSITIVE_INFINITE] self.leaves = {} self.plateaus = {} self.root = None self.who = self.__class__.__name__ self.logger = None # This is supposed to be set by extending classes self.leaves[NEGATIVE_INFINITE] = SkipListNode( NEGATIVE_INFINITE, 0, label=NEGATIVE_INFINITE, filehash=NEGATIVE_INFINITE) self.leaves[POSITIVE_INFINITE] = SkipListNode( POSITIVE_INFINITE, 0, label=POSITIVE_INFINITE, filehash=POSITIVE_INFINITE) for leaf in self.leaves: self.plateaus[leaf] = self._buildTower(self.leaves[leaf]) self.root = self.plateaus[NEGATIVE_INFINITE]
def insertAfterAbove(self, p, q, element): #p est pour le précédent #q est pour celui au-dessous #arguments de SkipListNode : element, prev, next, belo, abov #abov toujours None car on insère toujours au niveau le plus haut #le nouveau noeud a p comme précédent, p._next comme suivant, # q au-dessous et rien au-dessus newnode = SkipListNode(element, p, p._next, q, None) #on relie le précédent de l'ancien suivant, next._prev, au nouveau noeud p._next._prev = newnode #on relie le suivant du précédent, p._next, au nouveau noeud p._next = newnode #s'il y a un noeud en-dessous, q n'est pas à None, on le relie au nouveau noeud #which is abov it if not (q is None): q._abov = newnode #on retourne le nouveau noeud return newnode
def _isNodeOnPath(starting_leaf, target_node): ''' It searches a node on a path from starting_leaf to the root. Return False if node is never found on such path, True otherwise. @param starting_leaf: the leaf from which the path starts from. @param target_node: the node to be found raise: Exception if a node passed is None. ''' if target_node == None or starting_leaf == None: raise Exception("Invalid check: a None-argument was passed.") node = starting_leaf searching = True while searching: if node.__eq__(target_node): return True node = node.father try: still_on_the_right = (SkipListNode.comparePathnames(target_node.pathname, node.pathname) <= 0) except: still_on_the_right = False searching = (isinstance(node, SkipListNode)) and ( still_on_the_right ) return False
def __init__(self, json_serialized): self.proofpaths = {} json_decoded = json.loads(json_serialized) proofpaths = json_decoded['proofpaths'] self.pathname = json_decoded['pathname'] self.operation = json_decoded['operation'] for starting_pathname in proofpaths: starting_node = None previous = None for nodedata in proofpaths[starting_pathname]: node = SkipListNode(nodedata['pathname'],nodedata['height'], label = nodedata['label'], filehash = nodedata['filehash']) proxy = None if nodedata['proxy']!=None: proxydata = nodedata['proxy'] proxy = ProxyNode(proxydata['pathname'],proxydata['height'],proxydata['label']) proxyside = nodedata['proxy_side'] if proxyside =='r': node.right_child = proxy if proxyside =='l': node.lower_child = proxy proxy.father = node if starting_node==None: starting_node = node try: previous.father = node if previous.pathname == node.pathname: node.lower_child = previous else: node.right_child = previous except: pass previous = node self.proofpaths[starting_pathname] = starting_node
def __init__(self, _MIN_VALUE=_MIN, _MAX_VALUE=_MAX): #valeurs pour les sentinelles, -infini à +infini self._MIN_VALUE = _MIN_VALUE self._MAX_VALUE = _MAX_VALUE #une instance de Coin pour les tours de hauteurs variables self._coin = Coin() #hauteur de départ self._height = 1 #taille initiale de 0 self._size = 0 #les 4 sentinelles et leurs interrelations #lr = low-right; ll = low-left; ul = upper-left; ur = upper-right sentinel_lr = SkipListNode(self._MAX_VALUE) sentinel_ll = SkipListNode(self._MIN_VALUE, None, sentinel_lr, None, None) sentinel_lr._prev = sentinel_ll sentinel_ul = SkipListNode(self._MIN_VALUE, None, None, sentinel_ll, None) sentinel_ur = SkipListNode(self._MAX_VALUE, sentinel_ul, None, sentinel_lr, None) sentinel_ul._next = sentinel_ur sentinel_ll._abov = sentinel_ul sentinel_lr._abov = sentinel_ur #par convention, le début de la skiplist est la sentinelle _ul self._start = sentinel_ul
def __init__( self, _MIN_VALUE = -999999999, _MAX_VALUE = 999999999 ): self._MIN_VALUE = _MIN_VALUE self._MAX_VALUE = _MAX_VALUE self._coin = Coin() self._height = 1 self._count = 0 sentinel_lr = SkipListNode( self._MAX_VALUE ) sentinel_ll = SkipListNode( self._MIN_VALUE, None, sentinel_lr, None, None ) sentinel_lr._prev = sentinel_ll sentinel_ul = SkipListNode( self._MIN_VALUE, None, None, sentinel_ll, None ) sentinel_ur = SkipListNode( self._MAX_VALUE, sentinel_ul, None, sentinel_lr, None ) sentinel_ul._next = sentinel_ur sentinel_ll._abov = sentinel_ul sentinel_lr._abov = sentinel_ur self._start = sentinel_ul