示例#1
0
// ----------------------------------------------------------------
static char* test_hss() {

	hss_t *pset = hss_alloc();
	mu_assert_lf(pset->num_occupied == 0);

	hss_add(pset, "x");
	mu_assert_lf(pset->num_occupied == 1);
	mu_assert_lf(!hss_has(pset, "w"));
	mu_assert_lf(hss_has(pset, "x"));
	mu_assert_lf(!hss_has(pset, "y"));
	mu_assert_lf(!hss_has(pset, "z"));
	mu_assert_lf(hss_check_counts(pset));

	hss_add(pset, "y");
	mu_assert_lf(pset->num_occupied == 2);
	mu_assert_lf(!hss_has(pset, "w"));
	mu_assert_lf(hss_has(pset, "x"));
	mu_assert_lf(hss_has(pset, "y"));
	mu_assert_lf(!hss_has(pset, "z"));
	mu_assert_lf(hss_check_counts(pset));

	hss_add(pset, "x");
	mu_assert_lf(pset->num_occupied == 2);
	mu_assert_lf(!hss_has(pset, "w"));
	mu_assert_lf(hss_has(pset, "x"));
	mu_assert_lf(hss_has(pset, "y"));
	mu_assert_lf(!hss_has(pset, "z"));
	mu_assert_lf(hss_check_counts(pset));

	hss_add(pset, "z");
	mu_assert_lf(pset->num_occupied == 3);
	mu_assert_lf(!hss_has(pset, "w"));
	mu_assert_lf(hss_has(pset, "x"));
	mu_assert_lf(hss_has(pset, "y"));
	mu_assert_lf(hss_has(pset, "z"));
	mu_assert_lf(hss_check_counts(pset));

	hss_remove(pset, "y");
	mu_assert_lf(pset->num_occupied == 2);
	mu_assert_lf(!hss_has(pset, "w"));
	mu_assert_lf(hss_has(pset, "x"));
	mu_assert_lf(!hss_has(pset, "y"));
	mu_assert_lf(hss_has(pset, "z"));
	mu_assert_lf(hss_check_counts(pset));

	hss_clear(pset);
	mu_assert_lf(!hss_has(pset, "w"));
	mu_assert_lf(!hss_has(pset, "x"));
	mu_assert_lf(!hss_has(pset, "y"));
	mu_assert_lf(!hss_has(pset, "z"));
	mu_assert_lf(hss_check_counts(pset));

	hss_free(pset);

	return NULL;
}
示例#2
0
文件: uniqm.c 项目: johnkerl/scripts
int main(int argc, char** argv) {
	argf_t* pargf = argf_alloc(argv[0], argv+1, argc-1);
	int error = 0;
	hss_t* pset = hss_alloc();

	while (argf_fgets(pargf, line, MYBUFSIZ, &error) != NULL) {
		if (!hss_has(pset, line)) {
			fputs(line, stdout);
			hss_add(pset, strdup(line));
		}
	}
	argf_free(pargf);
	if (error) {
		return 1;
	}

	return 0;
}
示例#3
0
文件: mixutil.c 项目: 0-wiz-0/miller
// ----------------------------------------------------------------
hss_t* hss_from_slls(slls_t* plist) {
	hss_t* pset = hss_alloc();
	for (sllse_t* pe = plist->phead; pe != NULL; pe = pe->pnext)
		hss_add(pset, pe->value);
	return pset;
}