of_balanceright


pfcapsrv.pbl   >   pfc_n_cst_tree   >   of_balanceright   

Full name pfc_n_cst_tree.of_balanceright
Access protected
Extend of integer
Return value integer
Prototype protected function integer of_balanceright(ref n_cst_treenode,ref boolean)

Name Datatype
No Data

Name Datatype
li_b1 integer
li_b2 integer
lnv_pivot1 n_cst_treenode
lnv_pivot2 n_cst_treenode
lnv_temp n_cst_treenode

protected function integer of_balanceright (ref n_cst_treenode anv_currentnode, ref boolean ab_height);//////////////////////////////////////////////////////////////////////////////
//
//	Function:  of_balanceright
//
//	Access:  protected
//
//	Arguments : 
//	anv_currentnode n_cst_treenode : node to be balanced
//	ab_height boolean : indicates whether the 'height; of the tree has changed or not
//
//	Returns:  integer
//	1 : success (always)
//
//	Description:  Balances the right side of a node
//
//////////////////////////////////////////////////////////////////////////////
//
//	Revision History
//
//	Version
//	6.0   Initial version
//
//////////////////////////////////////////////////////////////////////////////
//
//	Copyright © 1996-1997 Sybase, Inc. and its subsidiaries.  All rights reserved.
//	Any distribution of the PowerBuilder Foundation Classes (PFC)
//	source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//
//////////////////////////////////////////////////////////////////////////////
n_cst_treenode lnv_pivot1,lnv_pivot2,lnv_temp
integer li_b1,li_b2

choose case anv_currentnode.of_getbalance() // right branch has become less high
	case 1
		anv_currentnode.of_setbalance(0)
	case 0
		anv_currentnode.of_setbalance(-1)
		ab_height = false		
	case -1 // rebalance
		anv_currentnode.of_getprev(lnv_pivot1)

		li_b1 = lnv_pivot1.of_getbalance()
		if li_b1 <= 0 then // single LL rotation
			lnv_pivot1.of_getnext(lnv_temp)
			anv_currentnode.of_setprev(lnv_temp)
			lnv_pivot1.of_setnext(anv_currentnode)
			if li_b1 = 0 then
				anv_currentnode.of_setbalance(-1)
				lnv_pivot1.of_setbalance(1)
				ab_height = false		
			else
				anv_currentnode.of_setbalance(0)
				lnv_pivot1.of_setbalance(0)
			end if			
			anv_currentnode = lnv_pivot1
		else // double LR rotation
			lnv_pivot1.of_getnext(lnv_pivot2)
			li_b2 = lnv_pivot2.of_getbalance()
			
			lnv_pivot2.of_getprev(lnv_temp)
			lnv_pivot1.of_setnext(lnv_temp)
			lnv_pivot2.of_setprev(lnv_pivot1)
			
			lnv_pivot2.of_getnext(lnv_temp)
			anv_currentnode.of_setprev(lnv_temp)
			lnv_pivot2.of_setnext(anv_currentnode)
			if li_b2 = -1 then
				anv_currentnode.of_setbalance(1)
			else
				anv_currentnode.of_setbalance(0)
			end if
			if li_b2 = 1 then
				lnv_pivot1.of_setbalance(-1)
			else
				lnv_pivot1.of_setbalance(0)
			end if
			anv_currentnode = lnv_pivot2
			lnv_pivot2.of_setbalance(0)
		end if
end choose
return 1

end function

     
Name Owner
pfc_n_cst_tree.of_delnode pfc_n_cst_tree
pfc_n_cst_tree.of_balance pfc_n_cst_tree

     
Name Owner
pfc_n_cst_treenode.of_getbalance pfc_n_cst_treenode
pfc_n_cst_treenode.of_setbalance pfc_n_cst_treenode
pfc_n_cst_nodebase.of_setprev pfc_n_cst_nodebase
pfc_n_cst_nodebase.of_setnext pfc_n_cst_nodebase
pfc_n_cst_nodebase.of_getnext pfc_n_cst_nodebase
pfc_n_cst_nodebase.of_getprev pfc_n_cst_nodebase

     
Full name
No Data

     
Name Scope
No Data