From: Andreas K. <and...@ac...> - 2008-05-26 17:44:31
|
> You know that Tcl interpreter doesn't ensure that dict key ordering. If you are talking about Tcl 8.5's dict structre and command, then no, IIRC the ordering of keys is preserved by them (append order). If you are talking about the result of [array get], then yes, the order is 'random', based on the hashtable internals. Tcllib's testsuite support code contains a command 'dictsort' which sorts a dictionary by keys The definition is in Tcllib's file modules/devtools/testutilities.tcl, and modules/uri/uri.test, modules/mime/mime.test are examples of using it. > That is not matter for almost cases. > > But when we write test cases, > how to compare between program result and booked value? > Especially, it is difficult problem for multi rank dict. > > Thoughts? > > > > I wrote a proc, and replaced from [dict create $key_duplicated_dict]. > (yaml.tcl) > > # remove duplications with saving key order > proc ::yaml::_remove_duplication {dict} { > array set tmp $dict > array set tmp2 {} > foreach {key nop} $dict { > if [info exists tmp2($key)] continue > lappend result $key $tmp($key) lappend result $key $nop and the array 'tmp' is not required. > set tmp2($key) 1 > } > return $result > } -- Andreas Kupries <and...@Ac...> Developer @ http://www.ActiveState.com Tel: +1 778-786-1122 |