diffAsts.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:ITAP-django 作者: krivers 项目源码 文件源码
def diffLists(x, y, ignoreVariables=False):
    mapSet = matchLists(x, y)
    changeVectors = []

    # First, get all the added and deleted lines
    deletedLines = mapSet[-1] if -1 in mapSet else []
    for line in sorted(deletedLines):
        changeVectors.append(DeleteVector([line], x[line], None))

    addedLines = list(filter(lambda tmp : mapSet[tmp] == -1, mapSet.keys()))
    addedOffset = 0 # Because added lines don't start in the list, we need
                    # to offset their positions for each new one that's added
    for line in sorted(addedLines):
        changeVectors.append(AddVector([line - addedOffset], None, y[line]))
        addedOffset += 1

    # Now, find all the required moves
    changeVectors += findMoveVectors(mapSet, x, y, addedLines, deletedLines)

    # Finally, for each pair of lines (which have already been moved appropriately,
    # find if they need a normal ChangeVector
    for j in mapSet:
        i = mapSet[j]
        # Not a delete or an add
        if j != -1 and i != -1:
            tempVectors = diffAsts(x[i], y[j], ignoreVariables=ignoreVariables)
            for change in tempVectors:
                change.path.append(i)
            changeVectors += tempVectors
    return changeVectors
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号