D r . P r o z a c said:
Hi,
I want to identify combinations of letters (a-z)... to make the combination
unique, but where the order of these letters is not important.
For example:
'er' and 're' should have the same unique identity.
If I don't misunderstand what you want to do...
You could use an array of structs like in
struct
{
char letters[SOME_SIZE_LARGE_ENOUGH_TO_HOLD_THE_LONGEST_SEQUENCE];
unsigned long id;
}[ENOUGH_TO_HOLD_ALL_PATTERNS] = {0};
Now iterate through the structs, fill the letters member of the structs with
your character sequences and qsort the letter arrays in _descending_ order
(so the zeroes from the initialisation will remain at the end of the char
arrays), then qsort the structs themselves, using the "letters" members as
sort criteria.
Finally you iterate through the array of structs again, assign values to the
"id" members (starting with 0 and only incrementing if struct[n].letters
compares unequal to the struct[n-1].letters, and you are done.
HTH
Robert