void print_callback(const unsigned char sha1[20], void *data) { printf("%s\n", sha1_to_hex(sha1)); } void some_func(void) { struct sha1_array hashes = SHA1_ARRAY_INIT; unsigned char sha1[20]; /* Read objects into our set */ while (read_object_from_stdin(sha1)) sha1_array_append(&hashes, sha1); /* Check if some objects are in our set */ while (read_object_from_stdin(sha1)) { if (sha1_array_lookup(&hashes, sha1) >= 0) printf("it's in there!\n"); /* * Print the unique set of objects. We could also have * avoided adding duplicate objects in the first place, * but we would end up re-sorting the array repeatedly. * Instead, this will sort once and then skip duplicates * in linear time. */ sha1_array_for_each_unique(&hashes, print_callback, NULL); }