コード例 #1
0
void dump_ai_obj(FILE *fp, ai_obj *a)
{
	char dumpbuf[1024];

	if (C_IS_S(a->type) || C_IS_O(a->type)) {
		if (a->empty) {
			fprintf(fp, "\tSTRING ai_obj: EMPTY\n");
			return;
		}
		memcpy_ai_objStoDumpBuf(dumpbuf, a);
		fprintf(fp, "\tSTRING ai_obj: mt: %d len: %d -> (%s) type: %d\n", a->empty, a->len, dumpbuf, a->type);
	} else if (C_IS_C(a->type)) {
		if (a->empty) {
			fprintf(fp, "\tCNAME ai_obj: EMPTY\n");
			return;
		}
		memcpy_ai_objStoDumpBuf(dumpbuf, a);
		fprintf(fp, "\tCNAME ai_obj: mt: %d -> (%s) cmatch: %d", a->empty, dumpbuf, a->i);
		if (a->ic) {
			fprintf(fp, " ic: ");
			dumpIC(fp, a->ic);
		} else {
			fprintf(fp, "\n");
		}
	} else if (C_IS_I(a->type) || C_IS_P(a->type)) {
		char *name = C_IS_I(a->type) ? "INT" : "FUNC";
		if (a->enc == COL_TYPE_INT || a->enc == COL_TYPE_FUNC) {
			fprintf(fp, "\t%s ai_obj: mt: %d val: %u\n", name, a->empty, a->i);
		} else {
			memcpy_ai_objStoDumpBuf(dumpbuf, a);
			fprintf(fp, "\t%s(S) ai_obj: mt: %d val: %s\n", name, a->empty, dumpbuf);
		}
	} else if (C_IS_L(a->type)) {
		if (a->enc == COL_TYPE_LONG) {
			fprintf(fp, "\tLONG ai_obj: mt: %d val: %lu\n", a->empty, a->l);
		} else {
			memcpy_ai_objStoDumpBuf(dumpbuf, a);
			fprintf(fp, "\tLONG(S) ai_obj: mt: %d val: %s\n", a->empty, dumpbuf);
		}
	} else if (C_IS_X(a->type)) {
		fprintf(fp, "\tU128 ai_obj: mt: %d val: ", a->empty);
		DEBUG_U128(fp, a->x);
		fprintf(fp, "\n");
	} else if (C_IS_Y(a->type)) {
		fprintf(fp, "\tU160 ai_obj: mt: %d val: ", a->empty);
		DEBUG_U160(fp, a->y);
		fprintf(fp, "\n");
	} else if (C_IS_F(a->type)) {
		if (a->enc == COL_TYPE_INT) {
			fprintf(fp, "\tFLOAT ai_obj: mt: %d val: %f\n", a->empty, a->f);
		} else {
			memcpy_ai_objStoDumpBuf(dumpbuf, a);
			fprintf(fp, "\tFLOAT(S) ai_obj: mt: %d val: %s\n", a->empty, dumpbuf);
		}
	} else {
		fprintf(fp, "\tUNINITIALISED ai_obj mt: %d\n", a->empty);
	}
}
コード例 #2
0
btEntry *btRangeNext(btSIter *siter, bool asc) { //printf("btRangeNext\n");
	//printf("btRangeNext: siter: %p\n", (void *)siter);
	//if (siter) printf("btRangeNext: empty: %d\n", siter->empty);
	if (!siter || siter->empty) return NULL;
	bt_n *x  = NULL;
	int i = -1;
	uchar *stream = btNext(siter, &x, &i, asc);
	if (!streamToBTEntry(stream, siter, x, i)) return NULL;
	if (C_IS_I(siter->ktype) || C_IS_L(siter->ktype) || C_IS_G(siter->ktype)) {
		long l = C_IS_I(siter->ktype) ? (ulong)(siter->key.i) : siter->key.l;
		if (l == siter->x.high)  siter->x.finished = 1;       /* exact match */
		if (!asc) {
			//printf("btRangeNext: DESC: l: %lu dr: %u\n",
			//       l, getDR(siter->x.btr, x, i));
			l += getDR(siter->x.btr, x, i);
		}
		bool over = asc ? (l > siter->x.high) : (l < siter->x.high);
		if (over && siter->nim) {
			siter->missed = 1;
		}
		//printf("btRangeNext: over: %d l: %lu high: %lu\n",
		//       over, l, siter->x.high);
		return over ? NULL : &(siter->be);
	} else if (C_IS_X(siter->ktype)) {
		uint128 xx = siter->key.x;
		if (xx == siter->x.highx)  siter->x.finished = 1;     /* exact match */
		if (!asc) {
			xx += getDR(siter->x.btr, x, i);
		}
		bool over = asc ? (xx > siter->x.highx) : (xx < siter->x.highx);
		return over ? NULL : &(siter->be);
	} else if (C_IS_Y(siter->ktype)) {
		uint160 yy = siter->key.y;
		int ret = u160Cmp(&yy, &siter->x.highy);
		if (!ret) siter->x.finished = 1;                      /* exact match */
		if (!asc) { //TODO is ENDIANness of memcpy() correct
			uint32 low;
			char *spot = ((char *)&yy) + 12;
			memcpy(&low, spot, 4);
			low += getDR(siter->x.btr, x, i);
			memcpy(spot, &low, 4);
		}
		bool over = asc ? (ret > 0) : (ret < 0);
		return over ? NULL : &(siter->be);
	} else if (C_IS_F(siter->ktype)) {
		float f = siter->key.f;
		if (f == siter->x.highf) siter->x.finished = 1;       /* exact match */
		return asc ? ((f <= siter->x.highf) ? & (siter->be) : NULL) :
			   ((f >= siter->x.highf) ? & (siter->be) : NULL);
	} else { // C_IS_S()
		int r = strncmp(siter->key.s, siter->x.highs, siter->key.len);
		if (r == 0)              siter->x.finished = 1;       /* exact match */
		return asc ? ((r <= 0) ?              & (siter->be) : NULL) :
			   ((r >= 0) ?              & (siter->be) : NULL);
	}
}
コード例 #3
0
static int ai_objCmp(ai_obj *a, ai_obj *b)
{
	if (C_IS_S(a->type)) {
		return strncmp(a->s, b->s, a->len);
	} else if (C_IS_F(a->type)) {
		float f = a->f - b->f;
		return (f == 0.0)     ? 0 : ((f > 0.0)     ? 1 : -1);
	} else if (C_IS_L(a->type)) {
		return (a->l == b->l) ? 0 : ((a->l > b->l) ? 1 : -1);
	} else if (C_IS_X(a->type)) {
		return (a->x == b->x) ? 0 : ((a->x > b->x) ? 1 : -1);
	} else if (C_IS_Y(a->type)) {
		return u160Cmp_string20(&a->y, &b->y);
	} else if (C_IS_I(a->type) || C_IS_P(a->type)) {
		return (long) (a->i - b->i);
	} else {
		assert(!"ai_objCmp ERROR");
	}
}
コード例 #4
0
static void setHigh(btSIter *siter, ai_obj *high, uchar ktype) {
	if        (C_IS_S(ktype)) {
		siter->x.highs            = cf_malloc(high->len + 1);    /* FREE ME 058 */
		memcpy(siter->x.highs, high->s, high->len);
		siter->x.highs[high->len] = '\0';
	} else if (C_IS_I(ktype)) {
		siter->x.high  = high->i;
	}
	else if (C_IS_L(ktype) || C_IS_G(ktype)) {
		siter->x.high  = high->l;
	}
	else if (C_IS_X(ktype)) {
		siter->x.highx = high->x;
	}
	else if (C_IS_Y(ktype)) {
		siter->x.highy = high->y;
	}
	else if (C_IS_F(ktype)) {
		siter->x.highf = high->f;
	}
}