コード例 #1
0
ファイル: memory_storage.cpp プロジェクト: thekvs/numerator
std::pair<bool, NumID>
MemoryStorage::find(const std::string &s, NumID &counter)
{
    NumID id = 0;
    bool  inserted = false;

    JError_t err;

    memset(&err, 0, sizeof(err));
    PPvoid_t rv = JudySLGet(data, reinterpret_cast<const uint8_t*>(s.c_str()), &err);
    THROW_EXC_IF_FAILED(JU_ERRNO(&err) == 0 && rv != PPJERR,
        "Memory operaton failed, error code: %i", JU_ERRNO(&err));

    if (rv != NULL) {
        id = *reinterpret_cast<NumID*>(rv);
    } else {
        memset(&err, 0, sizeof(err));
        rv = JudySLIns(&data, reinterpret_cast<const uint8_t*>(s.c_str()), &err);
        THROW_EXC_IF_FAILED(JU_ERRNO(&err) == 0 && rv != NULL && rv != PPJERR,
            "Memory allocation failed, error code: %i", JU_ERRNO(&err));
        value = reinterpret_cast<PWord_t>(rv);
        id = counter++;
        *value = id;
        inserted = true;
    }

    return std::make_pair(inserted, id);
}
コード例 #2
0
ファイル: memory_storage.cpp プロジェクト: thekvs/numerator
void
MemoryStorage::insert(const std::string &s, NumID id)
{
    JError_t err;

    memset(&err, 0, sizeof(err));
    PPvoid_t rv = JudySLGet(data, reinterpret_cast<const uint8_t*>(s.c_str()), &err);
    THROW_EXC_IF_FAILED(JU_ERRNO(&err) == 0 && rv != PPJERR,
        "Memory operaton failed, error code: %i", JU_ERRNO(&err));

    if (rv == NULL) {
        memset(&err, 0, sizeof(err));
        rv = JudySLIns(&data, reinterpret_cast<const uint8_t*>(s.c_str()), &err);
        THROW_EXC_IF_FAILED(JU_ERRNO(&err) == 0 && rv != NULL && rv != PPJERR,
            "Memory allocation failed, error code: %i", JU_ERRNO(&err));
    }

    value = reinterpret_cast<PWord_t>(rv);
    *value = id;
}
コード例 #3
0
ファイル: jmap.c プロジェクト: stewartsmith/ccan
const char *jmap_error_(struct jmap *map)
{
	char *str;
	free((char *)map->errstr);
	map->errstr = str = malloc(100);
	if (!map->errstr)
		return "out of memory";

	sprintf(str,
		"JU_ERRNO_* == %d, ID == %d\n",
		JU_ERRNO(&map->err), JU_ERRID(&map->err));
	return str;
}
コード例 #4
0
ファイル: judy_int_set.c プロジェクト: dohop/py-judy
static void print_word_and_error(const char* s, Word_t w, JError_t* e)
{
	switch (JU_ERRNO(e)) {
		case JU_ERRNO_NONE:          printf(" JU_ERRNO_NONE\n");          break;
		case JU_ERRNO_FULL:          printf(" JU_ERRNO_FULL\n");          break;
		//case JU_ERRNO_NFMAX:         printf(" JU_ERRNO_NFMAX\n");         break;
		case JU_ERRNO_NOMEM:         printf(" JU_ERRNO_NOMEM\n");         break;
		case JU_ERRNO_NULLPPARRAY:   printf(" JU_ERRNO_NULLPPARRAY\n");   break;
		case JU_ERRNO_NONNULLPARRAY: printf(" JU_ERRNO_NONNULLPARRAY\n"); break;
		case JU_ERRNO_NULLPINDEX:    printf(" JU_ERRNO_NULLPINDEX\n");    break;
		case JU_ERRNO_NULLPVALUE:    printf(" JU_ERRNO_NULLPVALUE\n");    break;
		case JU_ERRNO_NOTJUDY1:      printf(" JU_ERRNO_NOTJUDY1\n");      break;
		case JU_ERRNO_NOTJUDYL:      printf(" JU_ERRNO_NOTJUDYL\n");      break;
		case JU_ERRNO_NOTJUDYSL:     printf(" JU_ERRNO_NOTJUDYSL\n");     break;
		case JU_ERRNO_UNSORTED:      printf(" JU_ERRNO_UNSORTED\n");      break;
		case JU_ERRNO_OVERRUN:       printf(" JU_ERRNO_OVERRUN\n");       break;
		case JU_ERRNO_CORRUPT:       printf(" JU_ERRNO_CORRUPT\n");       break;
		default:                     printf(" UNKNOWN\n");                break;
	}
}
コード例 #5
0
ファイル: run.c プロジェクト: HSchroeder/ccan
int main(int argc, char *argv[])
{
	struct jset_long {
		JSET_MEMBERS(unsigned long);
	} *set;
	size_t i;
	const char *err;

	plan_tests(34);

	set = jset_new(struct jset_long);
	ok1(jset_error(set) == NULL);

	ok1(jset_set(set, 0) == true);
	ok1(jset_set(set, 0) == false);
	ok1(jset_clear(set, 0) == true);
	ok1(jset_clear(set, 0) == false);
	ok1(jset_popcount(set, 0, -1) == 0);
	ok1(jset_nth(set, 0, 0) == 0);
	ok1(jset_nth(set, 0, -1) == (size_t)-1);
	ok1(jset_first(set) == 0);
	ok1(jset_last(set) == 0);
	ok1(jset_first_clear(set) == 1);
	ok1(jset_last_clear(set) == (size_t)-1);
	ok1(jset_prev_clear(set, 1) == 0);
	ok1(jset_next_clear(set, 1) == 2);
	ok1(jset_next_clear(set, -1) == 0);

	/* Set a million bits, 16 bits apart. */
	for (i = 0; i < 1000000; i++)
		jset_set(set, 1 + (i << 4));

	/* This only take 1.7MB on my 32-bit system. */
	diag("%u bytes memory used\n", (unsigned)Judy1MemUsed(set->raw.judy));

	ok1(jset_popcount(set, 0, -1) == 1000000);
	ok1(jset_nth(set, 0, -1) == 1);
	ok1(jset_nth(set, 999999, -1) == 1 + (999999 << 4));
	ok1(jset_nth(set, 1000000, -1) == (size_t)-1);
	ok1(jset_first(set) == 1);
	ok1(jset_last(set) == 1 + (999999 << 4));
	ok1(jset_first_clear(set) == 2);
	ok1(jset_last_clear(set) == (size_t)-1);
	ok1(jset_prev_clear(set, 3) == 2);
	ok1(jset_prev_clear(set, 2) == 0);
	ok1(jset_next(set, 1) == 1 + (1 << 4));
	ok1(jset_next(set, 1 + (999999 << 4)) == 0);
	ok1(jset_prev(set, 1) == 0);
	ok1(jset_prev(set, 2) == 1);
	ok1(jset_error(set) == NULL);

	/* Test error handling */
	JU_ERRNO(&set->raw.err) = 100;
	JU_ERRID(&set->raw.err) = 991;
	err = jset_error(set);
	ok1(err);
	ok1(strstr(err, "100"));
	ok1(strstr(err, "991"));
	ok1(err == set->raw.errstr);
	jset_free(set);

	return exit_status();
}