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
评论列表
文章目录