Ejemplo n.º 1
0
Archivo: sets.c Proyecto: wrpaape/euler
/************************************************************************
 *				HELPERS					*
 ************************************************************************/
void *sieve_range(void *arg)
{
	bool (*flip_fun)(const int, struct SquareTerms *);
	struct IntNode *cand;

	struct SieveArg *params = (struct SieveArg *) arg;
	struct IntNode **prv    = &params->head;
	const int until		= params->until;
	/*
	 * case where x will be largest corresponds to the third flipping
	 * quadratic:
	 *
	 * 3x² - y² = n  where x > y
	 *
	 * when y = one less than x = (x - 1)
	 *
	 * substituting:
	 *
	 * 3x² - (x - 1)² = n
	 * 2x² + 2x - (1 + n) = 0
	 *
	 * from quadratic equation:
	 * x_max = (-1 + sqrt(3 + 2n)) / 2
	 *
	 * add one to ensure that range of x includes x_max:
	 */
	const int LENGTH_TERMS =
		((((int) sqrtf((float) ((until * 2) + 3))) - 1) / 2) + 1;

	int x_sq_3[LENGTH_TERMS];
	int x_sq_4[LENGTH_TERMS];

	for (int x = 2, x_sq; x < LENGTH_TERMS; ++x) {
		x_sq = x * x;
		x_sq_3[x] = 3 * x_sq;
		x_sq_4[x] = 4 * x_sq;
	}

	struct SquareTerms SQ_TERMS = {
		.X_SQ_3 = x_sq_3,
		.X_SQ_4 = x_sq_4
	};

	for (int n = params->start; n < until; n+=2) {

		flip_fun = FLIP_MAP[n % 60];

		if (flip_fun && flip_fun(n, &SQ_TERMS)) {
			cand = handle_malloc(sizeof(struct IntNode));
			cand->val = n;
			*prv = cand;
			prv  = &cand->nxt;
		}
	}

	params->last = cand;

	pthread_exit(NULL);
}
Ejemplo n.º 2
0
void JNIFUNCF(ImageFilterGeometry, nativeApplyFilterFlip, jobject src, jint srcWidth, jint srcHeight, jobject dst, jint dstWidth, jint dstHeight, jint flip) {
    char* destination = 0;
    char* source = 0;
    if (srcWidth != dstWidth || srcHeight != dstHeight) {
        return;
    }
    AndroidBitmap_lockPixels(env, src, (void**) &source);
    AndroidBitmap_lockPixels(env, dst, (void**) &destination);
    flip_fun(flip, source, srcWidth, srcHeight, destination, dstWidth, dstHeight);
    AndroidBitmap_unlockPixels(env, dst);
    AndroidBitmap_unlockPixels(env, src);
}
Ejemplo n.º 3
0
static __inline__ void rotate270(char * source, int srcWidth, int srcHeight, char * destination, int dstWidth, int dstHeight){
    rotate90(source, srcWidth, srcHeight, destination, dstWidth, dstHeight);
    flip_fun(3, destination, dstWidth, dstHeight, destination, dstWidth, dstHeight);
}
Ejemplo n.º 4
0
__inline__ void rotate180(char * source, int srcWidth, int srcHeight, char * destination, int dstWidth, int dstHeight){
    flip_fun(3, source, srcWidth, srcHeight, destination, dstWidth, dstHeight);
}