コード例 #1
0
// ----------------------------------------------------------------
static char* test_lhmss() {

	lhmss_t *pmap = lhmss_alloc();
	mu_assert_lf(pmap->num_occupied == 0);
	mu_assert_lf(!lhmss_has_key(pmap, "w")); mu_assert_lf(lhmss_get(pmap, "w") == NULL);
	mu_assert_lf(!lhmss_has_key(pmap, "x")); mu_assert_lf(lhmss_get(pmap, "x") == NULL);
	mu_assert_lf(!lhmss_has_key(pmap, "y")); mu_assert_lf(lhmss_get(pmap, "y") == NULL);
	mu_assert_lf(!lhmss_has_key(pmap, "z")); mu_assert_lf(lhmss_get(pmap, "z") == NULL);
	mu_assert_lf(lhmss_check_counts(pmap));

	lhmss_put(pmap, "x", "3");
	mu_assert_lf(pmap->num_occupied == 1);
	mu_assert_lf(!lhmss_has_key(pmap, "w")); mu_assert_lf(lhmss_get(pmap, "w") == NULL);
	mu_assert_lf( lhmss_has_key(pmap, "x")); mu_assert_lf(streq(lhmss_get(pmap, "x"), "3"));
	mu_assert_lf(!lhmss_has_key(pmap, "y")); mu_assert_lf(lhmss_get(pmap, "y") == NULL);
	mu_assert_lf(!lhmss_has_key(pmap, "z")); mu_assert_lf(lhmss_get(pmap, "z") == NULL);
	mu_assert_lf(lhmss_check_counts(pmap));

	lhmss_put(pmap, "y", "5");
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhmss_has_key(pmap, "w")); mu_assert_lf(lhmss_get(pmap, "w") == NULL);
	mu_assert_lf( lhmss_has_key(pmap, "x")); mu_assert_lf(streq(lhmss_get(pmap, "x"), "3"));
	mu_assert_lf( lhmss_has_key(pmap, "y")); mu_assert_lf(streq(lhmss_get(pmap, "y"), "5"));
	mu_assert_lf(!lhmss_has_key(pmap, "z")); mu_assert_lf(lhmss_get(pmap, "z") == NULL);
	mu_assert_lf(lhmss_check_counts(pmap));

	lhmss_put(pmap, "x", "4");
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhmss_has_key(pmap, "w")); mu_assert_lf(lhmss_get(pmap, "w") == NULL);
	mu_assert_lf( lhmss_has_key(pmap, "x")); mu_assert_lf(streq(lhmss_get(pmap, "x"), "4"));
	mu_assert_lf( lhmss_has_key(pmap, "y")); mu_assert_lf(streq(lhmss_get(pmap, "y"), "5"));
	mu_assert_lf(!lhmss_has_key(pmap, "z")); mu_assert_lf(lhmss_get(pmap, "z") == NULL);
	mu_assert_lf(lhmss_check_counts(pmap));

	lhmss_put(pmap, "z", "7");
	mu_assert_lf(pmap->num_occupied == 3);
	mu_assert_lf(!lhmss_has_key(pmap, "w")); mu_assert_lf(lhmss_get(pmap, "w") == NULL);
	mu_assert_lf( lhmss_has_key(pmap, "x")); mu_assert_lf(streq(lhmss_get(pmap, "x"), "4"));
	mu_assert_lf( lhmss_has_key(pmap, "y")); mu_assert_lf(streq(lhmss_get(pmap, "y"), "5"));
	mu_assert_lf( lhmss_has_key(pmap, "z")); mu_assert_lf(streq(lhmss_get(pmap, "z"), "7"));
	mu_assert_lf(lhmss_check_counts(pmap));

	lhmss_remove(pmap, "y");
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhmss_has_key(pmap, "w")); mu_assert_lf(lhmss_get(pmap, "w") == NULL);
	mu_assert_lf( lhmss_has_key(pmap, "x")); mu_assert_lf(streq(lhmss_get(pmap, "x"), "4"));
	mu_assert_lf(!lhmss_has_key(pmap, "y")); mu_assert_lf(lhmss_get(pmap, "y") == NULL);
	mu_assert_lf( lhmss_has_key(pmap, "z")); mu_assert_lf(streq(lhmss_get(pmap, "z"), "7"));
	mu_assert_lf(lhmss_check_counts(pmap));

	lhmss_free(pmap);

	return NULL;
}
コード例 #2
0
ファイル: mlrcli.c プロジェクト: 0-wiz-0/miller
static lhmss_t* get_default_rses() {
	if (singleton_default_rses == NULL) {
		singleton_default_rses = lhmss_alloc();
		lhmss_put(singleton_default_rses, "dkvp",    "\n");
		lhmss_put(singleton_default_rses, "csv",     "\r\n");
		lhmss_put(singleton_default_rses, "csvlite", "\n");
		lhmss_put(singleton_default_rses, "nidx",    "\n");
		lhmss_put(singleton_default_rses, "xtab",    "(N/A)");
		lhmss_put(singleton_default_rses, "pprint",  "\n");
	}
	return singleton_default_rses;
}
コード例 #3
0
ファイル: mlrcli.c プロジェクト: jjlu521016/miller
lhmss_t* get_default_pses() {
	if (singleton_default_pses == NULL) {
		singleton_default_pses = lhmss_alloc();
		lhmss_put(singleton_default_pses, "dkvp",    "=",     NO_FREE);
		lhmss_put(singleton_default_pses, "json",    "(N/A)", NO_FREE);
		lhmss_put(singleton_default_pses, "nidx",    "(N/A)", NO_FREE);
		lhmss_put(singleton_default_pses, "csv",     "(N/A)", NO_FREE);
		lhmss_put(singleton_default_pses, "csvlite", "(N/A)", NO_FREE);
		lhmss_put(singleton_default_pses, "pprint",  "(N/A)", NO_FREE);
		lhmss_put(singleton_default_pses, "xtab",    " ",     NO_FREE);
	}
	return singleton_default_pses;
}
コード例 #4
0
ファイル: stats1_accumulators.c プロジェクト: indera/miller
stats1_acc_t* stats1_percentile_alloc(char* value_field_name, char* stats1_acc_name, int allow_int_float) {
	stats1_acc_t* pstats1_acc   = mlr_malloc_or_die(sizeof(stats1_acc_t));
	stats1_percentile_state_t* pstate = mlr_malloc_or_die(sizeof(stats1_percentile_state_t));
	pstate->ppercentile_keeper  = percentile_keeper_alloc();
	pstate->poutput_field_names = lhmss_alloc();
	pstate->reference_count     = 1;

	pstats1_acc->pvstate        = (void*)pstate;
	pstats1_acc->pdingest_func  = NULL;
	pstats1_acc->pningest_func  = stats1_percentile_ningest;
	pstats1_acc->psingest_func  = NULL;
	pstats1_acc->pemit_func     = stats1_percentile_emit;
	pstats1_acc->pfree_func     = stats1_percentile_free;
	return pstats1_acc;
}
コード例 #5
0
ファイル: mlrcli.c プロジェクト: jjlu521016/miller
static lhmss_t* get_desc_to_chars_map() {
	if (singleton_pdesc_to_chars_map == NULL) {
		singleton_pdesc_to_chars_map = lhmss_alloc();
		lhmss_put(singleton_pdesc_to_chars_map, "cr",        "\r",       NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "crcr",      "\r\r",     NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "newline",   "\n",       NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "lf",        "\n",       NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "lflf",      "\n\n",     NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "crlf",      "\r\n",     NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "crlfcrlf",  "\r\n\r\n", NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "tab",       "\t",       NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "space",     " ",        NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "comma",     ",",        NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "newline",   "\n",       NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "pipe",      "|",        NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "slash",     "/",        NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "colon",     ":",        NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "semicolon", ";",        NO_FREE);
		lhmss_put(singleton_pdesc_to_chars_map, "equals",    "=",        NO_FREE);
	}
	return singleton_pdesc_to_chars_map;
}
コード例 #6
0
ファイル: lhmss.c プロジェクト: johnkerl/miller
lhmss_t* lhmss_copy(lhmss_t* pmap) {
	lhmss_t* pnew = lhmss_alloc();
	for (lhmsse_t* pe = pmap->phead; pe != NULL; pe = pe->pnext)
		lhmss_put(pnew, mlr_strdup_or_die(pe->key), mlr_strdup_or_die(pe->value), FREE_ENTRY_KEY|FREE_ENTRY_VALUE);
	return pnew;
}