Posted to tcl by Napier at Sun Jul 06 17:53:06 GMT 2014view raw
- proc difflists {l1 l2} {
- set lcsData [struct::list longestCommonSubsequence $l1 $l2]
- set diffs [struct::list lcsInvert $lcsData [llength $l1] [llength $l2]]
- set changedKeys ""
- foreach d $diffs {
- set op ""
- lassign $d type i1 i2; lassign $i1 s1 e1; lassign $i2 s2 e2
- puts "$type: [lrange $l2 {*}$i2] to -> [lrange $l1 {*}$i1]"
- #:[lindex $l1 $e1] -> [lindex $l2 $s2-1]:[lindex $l2 $e2]
- set flatkey [lindex $l1 $s1-1]; lappend op [string map {. " "} $flatkey]
- lappend op [lrange $l1 {*}$i1]
- lappend changedKeys $op
- }
- return $changedKeys
- }
-
- proc dict_flatten {dictVal} {
- dict for {k v} $dictVal {
- if {[llength $v] % 2 == 0} {
- set dictVal [dict remove $dictVal[set dictVal {}] $k]
- dict for {sk sv} [dict_flatten $v] {dict set dictVal ${k}.${sk} $sv}
- }
- }
- return $dictVal
- }
-
- proc dictCompare {newDict oldDict} {
- # Compares Two Dictionaries and Returns with a List
- # with all changed Dictionary Keys.
- # Example Resonse:
- # {key1 key1 key1} {key1 key1 key2} {key2 key1 key1}
- # Get Values using the {*} operator on the response:
- # dict get $dict {*}[lindex $differences 0]
- set differences [difflists [dict_flatten $newDict] [dict_flatten $oldDict]]
- return $differences
- }
-
-