/***************************************************************************************/ /* */ /* SCS editor Version 2 */ /* File : CompTreeUtils.pkg */ /* Version : 19 juin 2000 */ /* CompTree positions to nodes utility conversion functions */ /* */ /***************************************************************************************/ fun TREE_getNodeAmongBrothers( position, getBrother, node )= if (position == 0) || (node == nil) then node else TREE_getNodeAmongBrothers position-1 getBrother (exec getBrother with [node]) ;; /*************************************************************************************** returns a node from its position [I r1], 2 callbacks and root node first callback returns first son of a node second callback returns next brother of a node both callbacks are fun [u0] u0 validate by Mat 23/06/2000 ***************************************************************************************/ fun TREE_getNodeFromPosition( lposition, getSon, getBrother, node )= if (lposition == nil) || (node == nil) then node else TREE_getNodeFromPosition tl lposition getSon getBrother TREE_getNodeAmongBrothers (hd lposition) getBrother (exec getSon with [node]) ;; fun TREE_getPositionAmongBrothers( site, first, getBrother, node, count )= if first == node then count else TREE_getPositionAmongBrothers site (exec getBrother with [site first]) getBrother node count+1 ;; fun TREE_getReversedPositionFromNode( site, getFather, getSon, getBrother, node )= if node == nil then nil else let exec getFather with [site node] -> father in if father == nil then nil else (TREE_getPositionAmongBrothers site (exec getSon with [site father]) getBrother node 0):: TREE_getReversedPositionFromNode site getFather getSon getBrother father ;; /*************************************************************************************** returns a position [I r1] from a Site, 3 callbacks and root node first callback returns the father of a node second callback returns first son of a node third callback returns next brother of a node callbacks are fun [Site u0] u0 validate by Mat 23/06/2000 ***************************************************************************************/ fun TREE_getPositionFromNode( site, getFather, getSon, getBrother, node )= mirror TREE_getReversedPositionFromNode site getFather getSon getBrother node ;;