Changeset 5215

Show
Ignore:
Timestamp:
02/04/08 07:13:22 (6 months ago)
Author:
morris
Message:

Don't depend on sorting to get heaviest child node

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Tuna/trunk/TNNode.h

    r5208 r5215  
    5757- (NSUInteger)children; 
    5858- (TNNode *)childAtIndex:(NSUInteger)index; 
    59 - (TNNode *)firstChild; 
    6059- (id)childWithFunction:(TNFunction *)function; 
    6160- (id)childWithFunctionIdenticalTo:(TNFunction *)function; 
     61- (TNNode *)childWithHighestCumulativePercent; 
    6262- (TNNode *)parent; 
    6363- (BOOL)isLeaf; 
  • Tuna/trunk/TNNode.m

    r5208 r5215  
    180180 
    181181 
    182 - (TNNode *)firstChild { 
    183         return ([_children count] == 0) ? NULL : [_children objectAtIndex:0]; 
    184 } 
    185  
    186  
    187  
    188182- (id)childWithFunction:(TNFunction *)function { 
    189183        TNNode                  *node; 
     
    222216         
    223217        return NULL; 
     218} 
     219 
     220 
     221 
     222- (TNNode *)childWithHighestCumulativePercent { 
     223        TNNode                  *node, *child = NULL; 
     224        NSUInteger              i, count; 
     225        double                  percent = 0.0; 
     226         
     227        if(_children) { 
     228                count = CFArrayGetCount((CFMutableArrayRef) _children); 
     229                 
     230                for(i = 0; i < count; i++) { 
     231                        node = (id) CFArrayGetValueAtIndex((CFMutableArrayRef) _children, i); 
     232                         
     233                        if(!child || node->_cumulativePercent > percent) { 
     234                                child = node; 
     235                                percent = child->_cumulativePercent; 
     236                        } 
     237                } 
     238        } 
     239         
     240        return child; 
    224241} 
    225242 
  • Tuna/trunk/TNSessionController.m

    r5208 r5215  
    184184        while([node children] > 0) { 
    185185                before  = [node cumulativePercent]; 
    186                 node    = [node firstChild]; 
     186                node    = [node childWithHighestCumulativePercent]; 
    187187                after   = [node cumulativePercent]; 
    188188                delta   = (before - after) / before;