library/src/utility/BP-GenericFastWeightedBalancer.cc
// recalculates weight percentages and updates values.  Must be called
// before any of the data in the percentage fields can be considered up to
// date.
recalculates weight percentages and updates values.  Must be called
before any of the data in the percentage fields can be considered up to
date.
recalculates weight percentages and updates values . Must be called before any of the data in the percentage fields can be considered up to date .
BP_ERROR_T BP_BalancerUpdate(P_BP_WEIGHTED_BALANCER balancer)
{
	if(!balancer)
		return ERR_FAILURE;
	size_t total_weight = 0;
	size_t total_hits   = 0;
	size_t n = 0;
	for (; n < balancer->entry_n; n++)
	{
		total_weight+=balancer->entries[n].current_weight;
		total_hits  +=balancer->entries[n].current_hits;
	}
	if(total_weight==0)
		return ERR_SUCCESS;
	for(n = 0; n < balancer->entry_n; n++)
	{
		balancer->entries[n].current_percentage     = BP_GetPercentage(balancer->entries[n].current_hits,   total_hits);
		balancer->entries[n].weight_goal_percentage = BP_GetPercentage(balancer->entries[n].current_weight, total_weight);
		if(balancer->entries[n].current_percentage > balancer->entries[n].weight_goal_percentage)
			balancer->entries[n].overweight = 1;
		else
			balancer->entries[n].overweight = 0;
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_BalancerUpdate ( P_BP_WEIGHTED_BALANCER balancer ) { if ( ! balancer ) return ERR_FAILURE ; size_t total_weight = 0 ; size_t total_hits = 0 ; size_t n = 0 ; for ( ; n < balancer -> entry_n ; n ++ ) { total_weight += balancer -> entries [ n ] . current_weight ; total_hits += balancer -> entries [ n ] . current_hits ; } if ( total_weight == 0 ) return ERR_SUCCESS ; for ( n = 0 ; n < balancer -> entry_n ; n ++ ) { balancer -> entries [ n ] . current_percentage = BP_GetPercentage ( balancer -> entries [ n ] . current_hits , total_hits ) ; balancer -> entries [ n ] . weight_goal_percentage = BP_GetPercentage ( balancer -> entries [ n ] . current_weight , total_weight ) ; if ( balancer -> entries [ n ] . current_percentage > balancer -> entries [ n ] . weight_goal_percentage ) balancer -> entries [ n ] . overweight = 1 ; else balancer -> entries [ n ] . overweight = 0 ; } return ERR_SUCCESS ; }
recalculates weight percentages and updates values.
recalculates weight percentages and updates values .
//ensure we have a balancer // initialize // loop and set values // check for empty totals // now update percentages // calculate percentages // determine if item is overweight or not // return indicating sussess