// ---------------------------------------------------------------- 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; }
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; }
// ---------------------------------------------------------------- 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; }