• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Recursive partitioning algorithm
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Recursive partitioning algorithm


  • Subject: Recursive partitioning algorithm
  • From: Andrew Merenbach <email@hidden>
  • Date: Wed, 18 Jun 2003 11:15:47 -0700

I've produced the following tail-recursive algorithm, to divide an array into groups of 'size' (the remainder will have their own group):

- (NSArray *)partition1:(unsigned)size {
unsigned count = [self count];
return (count > size && size > 0) ? [[[self subarrayWithRange:NSMakeRange(size, count - size)] partition1:size] arrayByAddingObject:[self subarrayWithRange:NSMakeRange(0, size)]] : [NSArray arrayWithObject:self];
}

in a category of NSArray. Is there any reason to use or not to use this algorithm? (At least as compared to the following:)

- (NSArray *)partition2:(unsigned)size {
NSMutableArray *array = [NSMutableArray array];

if (size) {
unsigned count = [self count];
unsigned start = 0;

for (start = 0; start < count; start += size) {
if (start + size >= count) size = count - start;
[array addObject:[self subarrayWithRange:NSMakeRange(start, size)]];
}
}

return (NSArray *)array;
}

I've looked at the program in both GDB and ObjectAlloc, but have not been able to discern very much about the actual efficiency of each particular operation.

Take care,
Andrew
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Localising paths
  • Next by Date: Re: EDCommon Anyone?
  • Previous by thread: NSPopUpButton - menu exchange
  • Next by thread: gdb breaks on _NSRaiseError
  • Index(es):
    • Date
    • Thread