是否有差异,像算法处理的动线的块?算法、差异

2023-09-11 00:30:09 作者:七忆鱼

差异节目,在其各种化身,是计算两个文本文件和前$ P $的区别pssing比更紧凑显示这两个文件的相当好他们的全部内容。它显示了差作为线的插入或删除的块的序列(或改变线在某些情况下,但是这相当于删除,然后插入)。相同或非常相似的程序或算法使用补丁和源代码控制系统,以最大限度地减少重新present所需的存储两个版本相同的文件之间的差异。该算法这里讨论和的这里。

The diff program, in its various incarnations, is reasonably good at computing the difference between two text files and expressing it more compactly than showing both files in their entirety. It shows the difference as a sequence of inserted and deleted chunks of lines (or changed lines in some cases, but that's equivalent to a deletion followed by an insertion). The same or very similar program or algorithm is used by patch and by source control systems to minimize the storage required to represent the differences between two versions of the same file. The algorithm is discussed here and here.

但它倒下时,文本块的移动的文件中。

But it falls down when blocks of text are moved within the file.

假设你有以下两个文件,​​ a.txt中 b.txt (想象一下,他们是双方数百行长期而不仅仅是6):

Suppose you have the following two files, a.txt and b.txt (imagine that they're both hundreds of lines long rather than just 6):

a.txt   b.txt
-----   -----
1       4
2       5
3       6
4       1
5       2
6       3

差异a.txt中b.txt 显示了这一点:

$ diff a.txt b.txt 
1,3d0
< 1
< 2
< 3
6a4,6
> 1
> 2
> 3

a.txt中变更为 b.txt 可pssed作为前$ P $取前三行,并将其移动到最后,但差异显示线的移动块的完整内容两次,错过了一个机会来形容这个大的改变很简单。

The change from a.txt to b.txt can be expressed as "Take the first three lines and move them to the end", but diff shows the complete contents of the moved chunk of lines twice, missing an opportunity to describe this large change very briefly.

注意差异-e 显示文本块只有一次,但那是因为它不显示已删除行的内容。

Note that diff -e shows the block of text only once, but that's because it doesn't show the contents of deleted lines.

有没有在差异算法(一)保持差异的能力,重新$ p的变种$ psent插入和删除,以及(b)有效地重复presents移动文本块,而无需展示自己的全部内容?

Is there a variant of the diff algorithm that (a) retains diff's ability to represent insertions and deletions, and (b) efficiently represents moved blocks of text without having to show their entire contents?

推荐答案

既然你问了一个算法,而不是一个应用程序,看一看的

 
精彩推荐
图片推荐