模組 Diffing_with_keys

module Diffing_with_keys: sig .. end

當比較列表中每個元素都有一個獨特鍵值時,我們可以透過引入兩個複合編輯動作來改進差異比較修補:交換 (swaps) 和移動 (moves)。

Swap 會交換兩個元素的位置。Swap 的成本設定為 2 * change - epsilonMove 會變更一個元素的位置。Move 的成本設定為 delete + addition - epsilon

當成本 delete + addition 大於 change,並且使用這些特定的權重時,可以使用原始的最佳修補程式直接且低成本地計算出使用 SwapMove 的最佳修補程式。


type 'a with_pos = {
   pos : int;
   data : 'a;
}
val with_pos : 'a list -> 'a with_pos list
type ('l, 'r, 'diff) mismatch = 
| Name of {
   pos : int;
   got : string;
   expected : string;
   types_match : bool;
}
| Type of {
   pos : int;
   got : 'l;
   expected : 'r;
   reason : 'diff;
}
type ('l, 'r, 'diff) change = 
| Change of ('l, 'r, 'diff) mismatch
| Swap of {
   pos : int * int;
   first : string;
   last : string;
}
| Move of {
   name : string;
   got : int;
   expected : int;
}
| Insert of {
   pos : int;
   insert : 'r;
}
| Delete of {
   pos : int;
   delete : 'l;
}

這個特殊版本的變更引入了兩個複合變更:MoveSwap

val prefix : Format.formatter -> ('l, 'r, 'diff) change -> unit
module Define: 
functor (D : Diffing.Defs with type eq := unit-> sig .. end