• 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
Re: dividing values into range groups?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dividing values into range groups?


  • Subject: Re: dividing values into range groups?
  • From: Michael Gersten <email@hidden>
  • Date: Fri, 14 Jun 2002 13:41:01 -0700

In general, sorting will go faster when you divide the list into smaller pieces.
This is what quicksort does.

Sorting a large list of values will be n log n.
Dumping unsorted into X lists will be n x

So the question is, what is the cost of x (number of lists) compared to log n (number of items)

And, after the sorting, you still have a single N pass to break the list up.

Now, if you want an implementation idea, typed directly into the browser,

- placeIt (id <NSComparable> thisValue) // is that the right protocol for 'compare:' ?
{
// Assume that there are MAX dividers, and MAX+1 bins.
// Anything less than divide[0] goes into bin[0], etc.
// Todo: Convert to using collections and objectEnumerators instead of C arrays.
for (i=0; i < MAX; i++)
if (([thisValue compare: divide[i]]) < 0)
{
[bin[i] addObject: thisItem];
return;
}
// Not found -- put in the last one
[bin[i] addObject: thisItem];
}

Jonathan Rochkind wrote:
>
> I have an initially unsorted array of values. They could be Numbers, or
> they could be Dates. I want to divide them into ranges. For instance, if
> they are numbers, all of them between 0 and 10, between 10 and 20, 20 and
> 30, etc. Not neccesarily equal groups, but specified groups.
>
> What's the easiest/quickest way to do this? Is there anything built into
> the frameworks that will do this for me? Or should I just sort the list,
> and then step through it and divide it into sub-arrays?
>
> --Jonathan
>
> _______________________________________________
> WebObjects-dev mailing list
> email@hidden
> http://www.omnigroup.com/mailman/listinfo/webobjects-dev

--
I am a Mac 10-Cocoa/WOF/EOF developer, and I'm available for hire. Please contact me at michael-job @ stb.nccom.com if interested. Resume at http://resumes.dice.com/keybounce
_______________________________________________
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: Quartz over GhostScript
  • Next by Date: Re: 8b color NSBitMapImageReps--no such thing?
  • Previous by thread: Re: Protecting Software w/ Software License Keys...
  • Next by thread: Oracle BLOB over the Java bridge
  • Index(es):
    • Date
    • Thread