Say we have
typedef struct {
int value1;
int value2;
} values_t;
and
values_t* values;
is filled with values[i].value1 and values[i].value2 pairs that may or may not be unique.
and we want to fill
values_t* values_unique;
only with unique pairs from values, in the order they first appear in values.
What is the ideal way to do this in C?
EDIT: Assume they are properly malloced pointers; above is just pseudo code.
You probably use a hash of the values, maintaining a list of the hashes and the corresponding values, and only add a new pair to the
values_uniquearray (which the questiondoesoriginally did not declare as an array) if it is not found via the hash. If the list is large, the speed up from hashing instead of searching through the entire list sequentially can be quite significant.