tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,33 @@
package require Tcl 8.6
package require struct::tree
# A wrapper round a coroutine for iterating over the leaves of a tree in order
proc leafiterator {tree} {
coroutine coro[incr ::coroutines] apply {tree {
yield [info coroutine]
$tree walk [$tree rootname] node {
if {[$tree isleaf $node]} {
yield $node
}
}
yieldto break
}} $tree
}
# Compare two trees for equality of their leaf node names
proc samefringe {tree1 tree2} {
set c1 [leafiterator $tree1]
set c2 [leafiterator $tree2]
try {
while 1 {
if {[set l1 [$c1]] ne [set l2 [$c2]]} {
puts "$l1 != $l2"; # Just so we can see where we failed
return 0
}
}
return 1
} finally {
rename $c1 {}
rename $c2 {}
}
}

View file

@ -0,0 +1,20 @@
# Make some trees to compare...
struct::tree t1 deserialize {
root {} {}
a 0 {}
d 3 {}
e 3 {}
b 0 {}
c 0 {}
}
struct::tree t2 deserialize {
root {} {}
a 0 {}
d 3 {}
e 3 {}
b 0 {}
cc 0 {}
}
# Print the boolean result of doing the comparison
puts [samefringe t1 t2]