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
| | #ifndef UNIQUE_PREFIX_H
#define UNIQUE_PREFIX_H
struct prefix_item {
const char *name;
size_t prefix_length;
};
/*
* Find unique prefixes in a given array of strings.
* Given a list of names, find unique prefixes (i.e. the first <n> characters
* that uniquely identify the names) and store the lengths of the unique
* prefixes in the 'prefix_length' field of the elements of the given array.
*
* Typically, the `struct prefix_item` information will be a field in the
* actual item struct; For this reason, the `items` parameter is specified
* as an array of pointers to the items.
*
* The `min_length`/`max_length` parameters define what length the unique
* prefixes should have.
*
* If no unique prefix could be found for a given item, its `prefix_length`
* will be set to 0.
*/
void find_unique_prefixes(struct prefix_item **items, size_t nr,
int min_length, int max_length);
#endif
|