Posted to tcl by evilotto at Thu Jul 03 17:33:02 GMT 2014view raw

  1. package require struct::list
  2. proc difflists {l1 l2} {
  3. set lcsData [struct::list longestCommonSubsequence $l1 $l2]
  4. set diffs [struct::list lcsInvert $lcsData [llength $l1] [llength $l2]]
  5. foreach d $diffs {
  6. lassign $d type i1 i2
  7. lassign $i1 s1 e1
  8. lassign $i2 s2 e2
  9. puts "$type: [lrange $l1 {*}$i1] -> [lrange $l2 {*}$i2]"
  10. puts "--dict treatment-- $type: [lindex $l1 $s1-1]:[lindex $l1 $e1] -> [lindex $l2 $s2-1]:[lindex $l2 $e2]"
  11. }
  12. }
  13.  
  14. # example
  15. set d1 {name Den can_heat true can_cool true hvac_mode heat target_temperature_c 17.0 target_temperature_f 63}
  16. set d2 {name Den can_heat true can_cool true hvac_mode heat target_temperature_c 15.5 target_temperature_f 60}
  17. difflists $d1 $d2
  18.  

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 }