#include #include "set.c" int main(int argc, char **argv) { assert(argc == 2); const char *s = argv[1]; assert(strncmp(s, "set:", 4) == 0); s += 4; int bpp, m; int rc = decode_set_init(s, &bpp, &m); assert(rc == 0); size_t len = strlen(s); int n = decode_set_size(len, m); assert(n > 0); unsigned v[n]; n = decode_set(s, m, v); assert(n > 0); // Read the list of symbols from stdin. struct set *set = set_new(); char *line = NULL; size_t alloc = 0; while ((len = getline(&line, &alloc, stdin)) != -1) { assert(len > 1); len--; assert(line[len] == '\n'); line[len] = '\0'; set_add(set, line); } // Hash and sort the symbols by hash. s = set_fini(set, bpp); assert(s && "non-empty set"); s = _free(s); // don't neeed the result, only the internal structure // Join v[] and set->sv[]. int w = (bpp + 3) / 4; for (int i = 0; i < n; i++) { // TODO: handle collisions and/or missing elements, // advance lists separately like in mergesort. assert(set->sv[i].v == v[i]); printf("%0*x %s\n", w, v[i], set->sv[i].s); } set_free(set); return 0; }