-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermutation_iterator.h
65 lines (58 loc) · 2.04 KB
/
permutation_iterator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Licensed under the MIT license.
#include <stdbool.h>
#include <stddef.h>
#include "array.h"
#include "comparer.h"
#include "equality_comparer.h"
/** Iterates over the lexicographical permutations of a collection. */
struct PermutationIterator
{
int (*itemComparer)(const void* left, const void* right);
void* items;
size_t length;
size_t itemSize;
bool end;
};
/** Iterates over the lexicographical permutations of a collection. */
typedef struct PermutationIterator* PermutationIterator;
/**
* Provides an iterator over the lexicographical permutations of a collection.
*
* @param iterator when this method returns, contains the iterator. This
* argument is passed uninitialized.
* @param items the collection.
* @param length the length of the `items` collection.
* @param itemSize the size of each element in `items`.
* @param itemComparer the comparer used to determine the lexicographical order.
*/
void permutation_begin(
PermutationIterator iterator,
Array items,
size_t length,
size_t itemSize,
Comparer itemComparer);
/**
* Advances the iterator to the next lexicographical permutation. This method
* shuffles the `items` field of the `iterator` argument.
*
* @param iterator the iterator.
*/
void permutation_next(PermutationIterator iterator);
/**
* Determines whether two collections are permutations of one another.
*
* @param left a collection to compare to `right`.
* @param leftLength the number of items in the `left` collection.
* @param right a collection to compare to `left`.
* @param rightLength the number of items in the `right` collection.
* @param itemSize the size of each element in `left` and `right`.
* @param itemComparer the comparer used to determine if two elements are equal.
* @return `true` if `left` and `right` are permutations; otherwise, `false`.
*/
bool permutation_test(
Array left,
size_t leftLength,
Array right,
size_t rightLength,
size_t itemSize,
EqualityComparer itemComparer);