Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Gaming > Development Programming Algorithms > Re: Binary sear...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 11 Topic 665 of 680
Post > Topic >>

Re: Binary search with timestamps

by Makhno <root@[EMAIL PROTECTED] > Feb 13, 2008 at 09:07 PM

Hmmm, a slight modification seems to work!
Just what I was looking for.



template <class T> long binary_search
	(double t,T *array,long count)
{
	//handle trivial cases:
	if (count<2) return -1;
	if (count==2) return 0;
	if (t<array[0].time)
		return 0;
	if (t>array[count-2].time)
		return count-2;
	
	//binary search:
	long top=count-2;
	long bottom=0;
	for(;;)
	{
		long mid=(top+bottom)/2;
		if (t>array[mid].time && t<=array[mid+1].time)
			return mid;
		else if (t>array[mid+1].time)
			bottom=mid;
		else //if (t<=array[mid].time)
			top=mid;
	}
}
 




 11 Posts in Topic:
Binary search with timestamps
Makhno <root@[EMAIL PR  2008-02-12 21:27:40 
Re: Binary search with timestamps
Luc The Perverse <atay  2008-02-12 18:21:45 
Re: Binary search with timestamps
Miss Elaine Eos <Misc@  2008-02-13 06:15:07 
Re: Binary search with timestamps
Makhno <root@[EMAIL PR  2008-02-13 20:34:36 
Re: Binary search with timestamps
Makhno <root@[EMAIL PR  2008-02-13 21:07:58 
Re: Binary search with timestamps
Miss Elaine Eos <Misc@  2008-02-14 05:05:19 
Re: Binary search with timestamps
Luc The Perverse <atay  2008-02-15 08:35:05 
Re: Binary search with timestamps
Makhno <root@[EMAIL PR  2008-02-18 22:24:10 
Re: Binary search with timestamps
Makhno <root@[EMAIL PR  2008-02-13 20:42:16 
Re: Binary search with timestamps
Luc The Perverse <atay  2008-02-12 18:24:50 
Re: Binary search with timestamps
Makhno <root@[EMAIL PR  2008-02-13 20:51:21 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 2:12:05 CDT 2008.