Esempio n. 1
0
// mode on strings: "1" and "1.0" and "1.0000" are distinct text.
static void stats1_mode_singest(void* pvstate, char* val) {
	stats1_mode_state_t* pstate = pvstate;
	lhmsie_t* pe = lhmsi_get_entry(pstate->pcounts_for_value, val);
	if (pe == NULL) {
		// lhmsi does a strdup so we needn't.
		lhmsi_put(pstate->pcounts_for_value, mlr_strdup_or_die(val), 1, FREE_ENTRY_KEY);
	} else {
		pe->value++;
	}
}
Esempio n. 2
0
// mode on strings? what about "1.0" and "1" and "1.0000" ??
static void acc_mode_singest(void* pvstate, char* val) {
	acc_mode_state_t* pstate = pvstate;
	lhmsie_t* pe = lhmsi_get_entry(pstate->pcounts_for_value, val);
	if (pe == NULL) {
		// xxx at the moment, lhmsi does a strdup so we needn't.
		lhmsi_put(pstate->pcounts_for_value, val, 1);
	} else {
		pe->value++;
	}
}
Esempio n. 3
0
lhmsi_t* get_default_repeat_ipses() {
	if (singleton_default_repeat_ipses == NULL) {
		singleton_default_repeat_ipses = lhmsi_alloc();
		lhmsi_put(singleton_default_repeat_ipses, "dkvp",    FALSE, NO_FREE);
		lhmsi_put(singleton_default_repeat_ipses, "json",    FALSE, NO_FREE);
		lhmsi_put(singleton_default_repeat_ipses, "csv",     FALSE, NO_FREE);
		lhmsi_put(singleton_default_repeat_ipses, "csvlite", FALSE, NO_FREE);
		lhmsi_put(singleton_default_repeat_ipses, "nidx",    FALSE, NO_FREE);
		lhmsi_put(singleton_default_repeat_ipses, "xtab",    TRUE,  NO_FREE);
		lhmsi_put(singleton_default_repeat_ipses, "pprint",  FALSE, NO_FREE);
	}
	return singleton_default_repeat_ipses;
}
Esempio n. 4
0
// ----------------------------------------------------------------
static char* test_lhmsi() {
	mu_assert_lf(0 == 0);

	lhmsi_t *pmap = lhmsi_alloc();
	mu_assert_lf(pmap->num_occupied == 0);
	mu_assert_lf(!lhmsi_has_key(pmap, "w"));
	mu_assert_lf(!lhmsi_has_key(pmap, "x"));
	mu_assert_lf(!lhmsi_has_key(pmap, "y"));
	mu_assert_lf(!lhmsi_has_key(pmap, "z"));
	mu_assert_lf(lhmsi_check_counts(pmap));

	lhmsi_put(pmap, "x", 3);
	mu_assert_lf(pmap->num_occupied == 1);
	mu_assert_lf(!lhmsi_has_key(pmap, "w"));
	mu_assert_lf(lhmsi_has_key(pmap, "x"));
	mu_assert_lf(!lhmsi_has_key(pmap, "y"));
	mu_assert_lf(!lhmsi_has_key(pmap, "z"));
	mu_assert_lf(lhmsi_check_counts(pmap));

	lhmsi_put(pmap, "y", 5);
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhmsi_has_key(pmap, "w"));
	mu_assert_lf(lhmsi_has_key(pmap, "x"));
	mu_assert_lf(lhmsi_has_key(pmap, "y"));
	mu_assert_lf(!lhmsi_has_key(pmap, "z"));
	mu_assert_lf(lhmsi_check_counts(pmap));

	lhmsi_put(pmap, "x", 4);
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhmsi_has_key(pmap, "w"));
	mu_assert_lf(lhmsi_has_key(pmap, "x"));
	mu_assert_lf(lhmsi_has_key(pmap, "y"));
	mu_assert_lf(!lhmsi_has_key(pmap, "z"));
	mu_assert_lf(lhmsi_check_counts(pmap));

	lhmsi_put(pmap, "z", 7);
	mu_assert_lf(pmap->num_occupied == 3);
	mu_assert_lf(!lhmsi_has_key(pmap, "w"));
	mu_assert_lf(lhmsi_has_key(pmap, "x"));
	mu_assert_lf(lhmsi_has_key(pmap, "y"));
	mu_assert_lf(lhmsi_has_key(pmap, "z"));
	mu_assert_lf(lhmsi_check_counts(pmap));

	lhmsi_remove(pmap, "y");
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhmsi_has_key(pmap, "w"));
	mu_assert_lf(lhmsi_has_key(pmap, "x"));
	mu_assert_lf(!lhmsi_has_key(pmap, "y"));
	mu_assert_lf(lhmsi_has_key(pmap, "z"));
	mu_assert_lf(lhmsi_check_counts(pmap));

	lhmsi_clear(pmap);
	mu_assert_lf(pmap->num_occupied == 0);
	mu_assert_lf(!lhmsi_has_key(pmap, "w"));
	mu_assert_lf(!lhmsi_has_key(pmap, "x"));
	mu_assert_lf(!lhmsi_has_key(pmap, "y"));
	mu_assert_lf(!lhmsi_has_key(pmap, "z"));
	mu_assert_lf(lhmsi_check_counts(pmap));

	lhmsi_free(pmap);

	return NULL;
}