Tk Library Source Code

Artifact [a7b94bac4b]
Login

Artifact a7b94bac4bd8c85b4e43866cae2ed4f6f42cb0fe:

Attachment "460230.diff" to ticket [460230ffff] added by andreas_kupries 2001-09-15 01:14:36.
Index: modules/struct/graph.n
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/struct/graph.n,v
retrieving revision 1.4
diff -u -r1.4 graph.n
--- modules/struct/graph.n	2001/08/02 16:38:07	1.4
+++ modules/struct/graph.n	2001/09/14 18:11:33
@@ -75,6 +75,10 @@
 arc is not specified the system will generate a unique name of the
 form \fBarc\fR\fIx\fR.
 .TP
+\fIgraphName\fR \fBarc keyexists\fR \fIarc\fR ?\fI-key key\fR?
+Return a boolean value indicating whether the key \fIkey\fR exists for
+the \fIarc\fR.  If no key is specified, the key \fBdata\fR is assumed.
+.TP
 \fIgraphName\fR \fBarc set\fR \fIarc\fR ?\fI-key key\fR? ?\fIvalue\fR?
 Set or get one of the keyed values associated with an arc.  If no key
 is specified, the key \fBdata\fR is assumed.  Each arc that is added
@@ -145,6 +149,11 @@
 Insert a node named \fIchild\fR into the graph. The nodes has no arcs
 connected to it. If the name of the new child is not specified the
 system will generate a unique name of the form \fBnode\fR\fIx\fR.
+.TP
+\fIgraphName\fR \fBnode keyexists\fR \fInode\fR ?\fI-key key\fR?
+Return a boolean value indicating whether the key \fIkey\fR exists for
+the \fInode\fR.  If no key is specified, the key \fBdata\fR is
+assumed.
 .TP
 \fIgraphName\fR \fBnode opposite\fR \fInode\fR \fIarc\fR
 Return the node at the other end of the specified \fIarc\fR, which
Index: modules/struct/graph.tcl
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/struct/graph.tcl,v
retrieving revision 1.3
diff -u -r1.3 graph.tcl
--- modules/struct/graph.tcl	2001/06/22 15:29:18	1.3
+++ modules/struct/graph.tcl	2001/09/14 18:11:33
@@ -49,6 +49,7 @@
 	    "exists"	\
 	    "get"	\
 	    "insert"	\
+	    "keyexists"	\
 	    "set"	\
 	    "source"	\
 	    "target"	\
@@ -61,6 +62,7 @@
 	    "exists"	\
 	    "get"	\
 	    "insert"	\
+	    "keyexists"	\
 	    "opposite"	\
 	    "set"	\
 	    "unset"	\
@@ -278,7 +280,6 @@
 #	arc		The name of the new arc.
 
 proc ::struct::graph::__arc_insert {name source target args} {
-
     if { [llength $args] == 0 } {
 	# No arc name was given; generate a unique one
 	set arc [__generateUniqueArcName $name]
@@ -314,6 +315,33 @@
     return $arc
 }
 
+# ::struct::graph::__arc_keyexists --
+#
+#	check existence of a key for the specified arc
+#
+# Arguments:
+#	name		name of the graph.
+#	arc		arc to look at.
+#	flag	        -key; anything else is an error
+#	key	        key to lookup; defaults to data
+#
+# Results:
+#	exists		Boolean value. Indicates existence of key in arc.
+
+proc ::struct::graph::__arc_keyexists {name arc {flag -key} {key data}} {
+    if { ![__arc_exists $name $arc] } {
+	error "arc \"$arc\" does not exist in graph \"$name\""
+    }
+    
+    upvar ::struct::graph::graph${name}::arc${arc} data
+
+    if { ![info exists data($key)] } {
+	return 0
+    } else {
+	return 1
+    }
+}
+
 # ::struct::graph::__arc_set --
 #
 #	Set or get a value for an arc in a graph.
@@ -890,6 +918,33 @@
     set data(data) ""
 
     return $node
+}
+
+# ::struct::graph::__node_keyexists --
+#
+#	check existence of a key for the specified node
+#
+# Arguments:
+#	name		name of the graph.
+#	node		node to look at.
+#	flag	        -key; anything else is an error
+#	key	        key to lookup; defaults to data
+#
+# Results:
+#	exists		Boolean value. Indicates existence of key in node.
+
+proc ::struct::graph::__node_keyexists {name node {flag -key} {key data}} {
+    if { ![__node_exists $name $node] } {
+	error "node \"$node\" does not exist in graph \"$name\""
+    }
+    
+    upvar ::struct::graph::graph${name}::node${node} data
+
+    if { ![info exists data($key)] } {
+	return 0
+    } else {
+	return 1
+    }
 }
 
 # ::struct::graph::__node_opposite --
Index: modules/struct/graph.test
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/struct/graph.test,v
retrieving revision 1.3
diff -u -r1.3 graph.test
--- modules/struct/graph.test	2000/06/16 20:15:32	1.3
+++ modules/struct/graph.test	2001/09/14 18:11:33
@@ -297,6 +297,34 @@
     set msg
 } "invalid key \"foo\" for arc \"arc0\""
 
+test graph-6.8 {arc keyexists with standard key} {
+    graph mygraph
+    mygraph node insert node0
+    mygraph node insert node1
+    mygraph arc insert node0 node1 arc0
+    set msg [mygraph arc keyexists arc0 -key data]
+    mygraph destroy
+    set msg
+} 1
+test graph-6.9 {arc keyexists with standard key, implicit} {
+    graph mygraph
+    mygraph node insert node0
+    mygraph node insert node1
+    mygraph arc insert node0 node1 arc0
+    set msg [mygraph arc keyexists arc0]
+    mygraph destroy
+    set msg
+} 1
+test graph-6.10 {arc keyexists with bad key} {
+    graph mygraph
+    mygraph node insert node0
+    mygraph node insert node1
+    mygraph arc insert node0 node1 arc0
+    set msg [mygraph arc keyexists arc0 -key foo]
+    mygraph destroy
+    set msg
+} 0
+
 # ---------------------------------------------------
 
 test graph-7.1 {arc source gives error on bogus arc} {
@@ -759,6 +787,28 @@
     mygraph destroy
     set msg
 } "invalid key \"foo\" for node \"node0\""
+
+test graph-17.8 {node keyexists with standard key} {
+    graph mygraph
+    mygraph node insert node0
+    set msg [mygraph node keyexists node0 -key data]
+    mygraph destroy
+    set msg
+} 1
+test graph-17.9 {node keyexists with standard key, implicit} {
+    graph mygraph
+    mygraph node insert node0
+    set msg [mygraph node keyexists node0]
+    mygraph destroy
+    set msg
+} 1
+test graph-17.10 {node keyexists with bad key} {
+    graph mygraph
+    mygraph node insert node0
+    set msg [mygraph node keyexists node0 -key foo]
+    mygraph destroy
+    set msg
+} 0
 
 # ---------------------------------------------------
 
Index: modules/struct/tree.n
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/struct/tree.n,v
retrieving revision 1.12
diff -u -r1.12 tree.n
--- modules/struct/tree.n	2001/09/05 23:36:15	1.12
+++ modules/struct/tree.n	2001/09/14 18:11:33
@@ -93,6 +93,11 @@
 Returns true if \fInode\fR is a leaf of the tree (if \fInode\fR has no
 children), false otherwise.
 .TP
+\fIgraphName\fR \fBkeyexists\fR \fInode\fR ?\fI-key key\fR?
+Return a boolean value indicating whether the key \fIkey\fR exists for
+the \fInode\fR.  If no key is specified, the key \fBdata\fR is
+assumed.
+.TP
 \fItreeName\fR \fBmove\fR \fIparent\fR \fIindex\fR \fInode\fR ?\fInode ...\fR?
 Make the specified nodes children of \fIparent\fR, inserting them
 into the parent's child list at the index given by \fIindex\fR.
Index: modules/struct/tree.tcl
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/struct/tree.tcl,v
retrieving revision 1.15
diff -u -r1.15 tree.tcl
--- modules/struct/tree.tcl	2001/09/05 23:36:15	1.15
+++ modules/struct/tree.tcl	2001/09/14 18:11:33
@@ -44,6 +44,7 @@
 	    "index"		\
 	    "insert"		\
 	    "isleaf"		\
+	    "keyexists"		\
 	    "move"		\
 	    "next"		\
 	    "numchildren"	\
@@ -503,6 +504,33 @@
     
     upvar ::struct::tree::tree${name}::children children
     return [expr {[llength $children($node)] == 0}]
+}
+
+# ::struct::tree::_keyexists --
+#
+#	check existence of a key for the specified node
+#
+# Arguments:
+#	name		name of the tree.
+#	node		node to look at.
+#	flag	        -key; anything else is an error
+#	key	        key to lookup; defaults to data
+#
+# Results:
+#	exists		Boolean value. Indicates existence of key in node.
+
+proc ::struct::tree::_keyexists {name node {flag -key} {key data}} {
+    if { ![_exists $name $node] } {
+	error "node \"$node\" does not exist in tree \"$name\""
+    }
+    
+    upvar ::struct::tree::tree${name}::node${node} data
+
+    if { ![info exists data($key)] } {
+	return 0
+    } else {
+	return 1
+    }
 }
 
 # ::struct::tree::_move --
Index: modules/struct/tree.test
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/struct/tree.test,v
retrieving revision 1.13
diff -u -r1.13 tree.test
--- modules/struct/tree.test	2001/09/05 23:36:15	1.13
+++ modules/struct/tree.test	2001/09/14 18:11:33
@@ -34,7 +34,7 @@
     catch {mytree foo} msg
     mytree destroy
     set msg
-} "bad option \"foo\": must be children, cut, destroy, delete, depth, exists, get, index, insert, isleaf, move, next, numchildren, parent, previous, set, size, splice, swap, unset, or walk"
+} "bad option \"foo\": must be children, cut, destroy, delete, depth, exists, get, index, insert, isleaf, keyexists, move, next, numchildren, parent, previous, set, size, splice, swap, unset, or walk"
 test tree-0.4 {tree errors} {
     catch {tree set} msg
     set msg
@@ -468,6 +468,27 @@
     mytree destroy
     set msg
 } "invalid key \"foo\" for node \"node0\""
+test tree-10.8 {keyexists with standard key} {
+    tree mytree
+    mytree insert root end node0
+    set msg [mytree keyexists node0 -key data]
+    mytree destroy
+    set msg
+} 1
+test tree-10.9 {keyexists with standard key, implicit} {
+    tree mytree
+    mytree insert root end node0
+    set msg [mytree keyexists node0]
+    mytree destroy
+    set msg
+} 1
+test tree-10.10 {keyexists with bad key} {
+    tree mytree
+    mytree insert root end node0
+    set msg [mytree keyexists node0 -key foo]
+    mytree destroy
+    set msg
+} 0
 
 test tree-11.1 {depth} {
     tree mytree