예제 #1
0
def path_collider(vector, path):
    """adding a path to a vector"""
    path_copy = list(path)
    if not isinstance( vector, VectorDict):
        if len(vector):
            vector = tree_from_path( * ( vector + [ "weight" , 1 ] ))
        else:
            vector = VectorDict( VectorDict, dict() )
    current = vector
    while len(path) :
        current_key = path.pop(0)
        if current_key in current.keys():
            
            current = current[current_key]
            if current.get("weight", False):
                current["weight"]+=1
        else:
            path = [ current_key ] + path
            break
    if len(path):
        vector.add_path( path_copy + [ "weight" , 1 ] )
    return vector