X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fpermutation%2F_info;fp=ccan%2Fpermutation%2F_info;h=4998f5db56862c8c42977a4939a8ac3b55d352c9;hb=c3e9a05832ec5362bf108a7f1487aa4dcff96f99;hp=0000000000000000000000000000000000000000;hpb=e8d1e7304feb9318a841ad4a7d5a8773271ab814;p=ccan diff --git a/ccan/permutation/_info b/ccan/permutation/_info new file mode 100644 index 00000000..4998f5db --- /dev/null +++ b/ccan/permutation/_info @@ -0,0 +1,61 @@ +#include "config.h" +#include +#include +#include + +/** + * permutation - Generate permutations + * + * This module allows you to generate all permutations of a given + * number of elements. It can also modify a user-supplied array in + * place through all those permutations. + * + * It uses the "plain changes" method, aka the + * Steinhaus-Johnson-Trotter algorithm to generate the permtations. + * This has some advantages over a naive recursive algorithm: + * + * - Each permutation is generated from the last by a single swap of + * adjacent elements + * + * - Constructing each permutation in place from the last takes + * amortized O(1) time. + * + * License: LGPL (v2.1 or any later version) + * Example: + * // Given "1 2 3" outputs 1 2 3 1 3 2 3 1 2 3 2 1 2 3 1 2 1 3 + * #include + * #include + * + * int main(int argc, char *argv[]) + * { + * int i; + * struct permutation *pi = permutation_new(argc - 1); + * + * do { + * for (i = 1; i < argc; i++) + * printf("%s ", argv[i]); + * printf("\n"); + * } while (permutation_change_array(pi, + * &argv[1], sizeof(argv[1]))); + * exit(0); + * } + */ +int main(int argc, char *argv[]) +{ + /* Expect exactly one argument */ + if (argc != 2) + return 1; + + if (strcmp(argv[1], "depends") == 0) { + printf("ccan/build_assert\n"); + printf("ccan/mem\n"); + return 0; + } + + if (strcmp(argv[1], "testdepends") == 0) { + printf("ccan/array_size\n"); + return 0; + } + + return 1; +}