]> git.ozlabs.org Git - ccan/blob - ccan/permutation/_info
crypto/shachain/tools: update to new rbuf API.
[ccan] / ccan / permutation / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5
6 /**
7  * permutation - Generate permutations
8  *
9  * This module allows you to generate all permutations of a given
10  * number of elements.  It can also modify a user-supplied array in
11  * place through all those permutations.
12  *
13  * It uses the "plain changes" method, aka the
14  * Steinhaus-Johnson-Trotter algorithm to generate the permtations.
15  * This has some advantages over a naive recursive algorithm:
16  *
17  * - Each permutation is generated from the last by a single swap of
18  *   adjacent elements
19  *
20  * - Constructing each permutation in place from the last takes
21  *   amortized O(1) time.
22  *
23  * License: LGPL (v2.1 or any later version)
24  * Example:
25  *      // Given "1 2 3" outputs 1 2 3 1 3 2 3 1 2 3 2 1 2 3 1 2 1 3
26  *      #include <stdio.h>
27  *      #include <ccan/permutation/permutation.h>
28  *
29  *      int main(int argc, char *argv[])
30  *      {
31  *              int i;
32  *              struct permutation *pi = permutation_new(argc - 1);
33  *
34  *              do {
35  *                      for (i = 1; i < argc; i++)
36  *                              printf("%s ", argv[i]);
37  *                      printf("\n");
38  *              } while (permutation_change_array(pi,
39  *                       &argv[1], sizeof(argv[1])));
40  *              exit(0);
41  *      }
42  */
43 int main(int argc, char *argv[])
44 {
45         /* Expect exactly one argument */
46         if (argc != 2)
47                 return 1;
48
49         if (strcmp(argv[1], "depends") == 0) {
50                 printf("ccan/build_assert\n");
51                 printf("ccan/mem\n");
52                 return 0;
53         }
54
55         if (strcmp(argv[1], "testdepends") == 0) {
56                 printf("ccan/array_size\n");
57                 return 0;
58         }
59
60         return 1;
61 }