My understanding of a binary search is that you keep adjusting the floor and ceiling. You would need to check to find when floor and ceiling are consecutive items. At that point, you would only have two items, and you could run a comparison to see which is closer to your target number.
Sid Maskit Partner CraftySpace Better Websites for a Better World http://www.CraftySpace.com blog: http://smaskit.blogspot.com/ ----- Original Message ---- From: blc187 <[EMAIL PROTECTED]> To: [email protected] Sent: Wednesday, August 13, 2008 3:11:06 PM Subject: [flexcoders] Re: how to search an arraycollection can i use a binary search if the value i am searching for is not explicitly in my arraycollection? i want to get the closest value to the timestamp i am searching for. --- In [EMAIL PROTECTED] ups.com, "Michael VanDaniker" <[EMAIL PROTECTED] > wrote: > > If your collection is sorted by timestamp a binary search would be faster. > > --- In [EMAIL PROTECTED] ups.com, "Alex Harui" <aharui@> wrote: > > > > You'll have to loop through yourself and keep track of the minimum > > difference > > > > > > > > ____________ _________ _________ __ > > > > From: [EMAIL PROTECTED] ups.com [mailto:[EMAIL PROTECTED] ups.com] On > > Behalf Of blc187 > > Sent: Wednesday, August 13, 2008 12:57 PM > > To: [EMAIL PROTECTED] ups.com > > Subject: [flexcoders] how to search an arraycollection > > > > > > > > I have an arraycollection of objects, each of which has a timestamp. > > ex: {timestamp:43424234 32, value:5} > > > > I want to search the arraycollection for the object which has the > > closest timestamp to the time I'm looking for. > > Is there a way to search the arraycollection for an approximate value? > > > > As of right now I'm looping through each object in my arraycollection > > to find if the value is between 2 numbers. > > > > for(var i:int = 0; i < dataProvider. length; i++) { > > if(myTimestamp > dataProvider[ i] && myTimestamp < dataProvider [i+1]) > > //this is the correct spot. > > } > > >

