Click here to Skip to main content
15,915,513 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
musefan22-Dec-10 4:36
musefan22-Dec-10 4:36 
AnswerRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
cp987620-Dec-10 18:52
cp987620-Dec-10 18:52 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
musefan22-Dec-10 4:34
musefan22-Dec-10 4:34 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
Luc Pattyn22-Dec-10 4:47
sitebuilderLuc Pattyn22-Dec-10 4:47 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
Kirk Wood24-Dec-10 4:29
Kirk Wood24-Dec-10 4:29 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
Roger Wright3-Jan-11 18:37
professionalRoger Wright3-Jan-11 18:37 
AnswerRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
trooper081423-Dec-10 20:28
trooper081423-Dec-10 20:28 
AnswerRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
Mwanzia_M21-Jan-11 3:05
Mwanzia_M21-Jan-11 3:05 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
Roger Wright21-Jan-11 17:06
professionalRoger Wright21-Jan-11 17:06 
QuestionOpenSource Audio DSP Algorithms/Filters? Pin
Yuval Naveh10-Dec-10 7:40
Yuval Naveh10-Dec-10 7:40 
AnswerRe: OpenSource Audio DSP Algorithms/Filters? Pin
TweakBird22-Dec-10 20:05
TweakBird22-Dec-10 20:05 
GeneralRe: OpenSource Audio DSP Algorithms/Filters? Pin
Yuval Naveh22-Dec-10 23:25
Yuval Naveh22-Dec-10 23:25 
QuestionNumber of Integer Solutions to an Equation Pin
Skippums23-Nov-10 15:03
Skippums23-Nov-10 15:03 
AnswerRe: Number of Integer Solutions to an Equation PinPopular
Sauro Viti24-Nov-10 0:19
professionalSauro Viti24-Nov-10 0:19 
AnswerRe: Number of Integer Solutions to an Equation Pin
Luc Pattyn24-Nov-10 3:56
sitebuilderLuc Pattyn24-Nov-10 3:56 
GeneralRe: Number of Integer Solutions to an Equation Pin
Skippums24-Nov-10 4:26
Skippums24-Nov-10 4:26 
AnswerRe: Number of Integer Solutions to an Equation Pin
Luc Pattyn24-Nov-10 4:47
sitebuilderLuc Pattyn24-Nov-10 4:47 
GeneralRe: Number of Integer Solutions to an Equation Pin
_Erik_24-Nov-10 6:00
_Erik_24-Nov-10 6:00 
AnswerRe: Number of Integer Solutions to an Equation [modified] Pin
Alain Rist26-Nov-10 1:50
Alain Rist26-Nov-10 1:50 
Questionfind lower bound Pin
liquid_18-Nov-10 6:11
liquid_18-Nov-10 6:11 
Below, there is an algorithm which I wrote to find lower bound of the given key in a sorted table. In other words, it finds a key which is <= of a given one. I wonder whether there is a more compact algorithm or maybe more efficient.

#include <stddef.h>

/*
 * Perform a binary lower bound search.
 *
 */

static size_t blsize;
static const void *skey;
static int (*cmpf)(const void *e1, const void *e2);

static void *lbnd(const void *base, size_t size)
{
	const char *p,*p1;
	int c;
	size_t n;

	if(size==0) return NULL;
	if(size==1)
	{
		c = (*cmpf)(skey,base);
		if(c<0)
			return NULL;
		else
			return (void *)base;
	}
	n = size >> 1;
	p = (char *)base + n*blsize;
	c = (*cmpf)(skey,p);
	if(c==0) return (void *)p;
	if(c<0)
	{
		return lbnd(base,n);
	}
	else
	{
		p1 = lbnd((char*)p + blsize,size - n - 1);
		if(p1==NULL)
			return (void *)p;
		else
			return (void *)p1;
	}
}

void *lbound(const void *key, const void *base0, size_t nmemb, size_t size, int (*compar)(const void *e1, const void *e2))
{
	blsize = size;
	cmpf = compar;
	skey = key;
	return lbnd(base0,nmemb);
}


The static function lbnddoes the search using static variables which contain constant values because lbnd is called recursively and to minimize code overhead in parameters passing.
AnswerRe: find lower bound Pin
NeverHeardOfMe18-Nov-10 6:22
NeverHeardOfMe18-Nov-10 6:22 
GeneralRe: find lower bound Pin
liquid_18-Nov-10 20:25
liquid_18-Nov-10 20:25 
GeneralRe: find lower bound Pin
NeverHeardOfMe18-Nov-10 21:49
NeverHeardOfMe18-Nov-10 21:49 
GeneralRe: find lower bound Pin
harold aptroot18-Nov-10 21:35
harold aptroot18-Nov-10 21:35 
AnswerRe: find lower bound Pin
Alain Rist18-Nov-10 23:24
Alain Rist18-Nov-10 23:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.