Posted to tcl by evilotto at Thu Jul 03 17:33:02 GMT 2014view pretty
package require struct::list proc difflists {l1 l2} { set lcsData [struct::list longestCommonSubsequence $l1 $l2] set diffs [struct::list lcsInvert $lcsData [llength $l1] [llength $l2]] foreach d $diffs { lassign $d type i1 i2 lassign $i1 s1 e1 lassign $i2 s2 e2 puts "$type: [lrange $l1 {*}$i1] -> [lrange $l2 {*}$i2]" puts "--dict treatment-- $type: [lindex $l1 $s1-1]:[lindex $l1 $e1] -> [lindex $l2 $s2-1]:[lindex $l2 $e2]" } } # example set d1 {name Den can_heat true can_cool true hvac_mode heat target_temperature_c 17.0 target_temperature_f 63} set d2 {name Den can_heat true can_cool true hvac_mode heat target_temperature_c 15.5 target_temperature_f 60} difflists $d1 $d2
Comments
Posted by evilotto at Thu Jul 03 18:01:57 GMT 2014 [text] [code]
# just return the keys of the dicts proc difflists {l1 l2} { set lcsData [struct::list longestCommonSubsequence $l1 $l2] set diffs [struct::list lcsInvert $lcsData [llength $l1] [llength $l2]] set chkeys {} foreach d $diffs { lassign $d type i1 i2 lassign $i1 s1 e1 lassign $i2 s2 e2 # lets assume the changes items are dict values only lappend chkeys [lindex $l1 $s1-1] } return $chkeys }