09-21-2021 07:04 AM
I am processing some data in which one of the data items is an index. It should be that each index is present exactly once. I can assemble the indices into an array, sort it, then check that the element values match their indices. But I also want 2 lists: One of indices that are missing, and another of indices that occur more than once.
Here is an example of a valid set of indices:
Here is an example of an invalid set of indices:
What's a nice clean way of getting the lists of invalid items?
09-21-2021 07:42 AM - edited 09-21-2021 07:43 AM
Here's what I quickly came up with. I used a Set to avoid duplicating replicated indecies and then a FOR loop that I expect to usually run 0 times to find the missing indicies.
09-21-2021 07:56 AM
09-21-2021 09:30 AM
@crossrulz wrote:
Here's what I quickly came up with. I used a Set to avoid duplicating replicated indecies and then a FOR loop that I expect to usually run 0 times to find the missing indicies.
Thank you; I like that. I started implementing it, then I realized I should have given the bigger picture instead of just a piece. I'm sure there's a better way to implement the whole thing.
I have a set of sockets that are identified by sequential zero-based numbers (i.e. socket indices). Each socket is a member of a group. Group IDs need not be sequential.
On my input, I have an array of clusters; each cluster containing a group identifier, and an array of IDs of member sockets.
On my output, I want an array with each element corresponding to a socket (array index = socket ID) whose element value is the ID of owning group.
I also want to generate a warning when the data make no sense, and to "repair" the data (of course it will be up to the user to read the warning and check the repaired data).
09-21-2021 10:21 AM - edited 09-21-2021 10:26 AM
Quick attempt at the original problem:
(note that "duplicate" simply means "more than one". we don't need to find or count all instances)
09-21-2021 03:10 PM
Thanks to everyone. Here's what I ended up with:
09-21-2021 03:23 PM
This is a little cleaner:
09-21-2021 04:48 PM
It is not clear how you do conflict resolution, but I guess the "Groups by Socket" is meaningless if there are still duplicates. For example it is not clear why you decide that the first element is 7 and not 2.
Here's my quick attempt. Same result (except first element is 2 instead of 7. Maybe less code, or at least easier to read). No guarantees. 🙂
09-22-2021 08:08 AM
@altenbach wrote:
It is not clear how you do conflict resolution, but I guess the "Groups by Socket" is meaningless if there are still duplicates. For example it is not clear why you decide that the first element is 7 and not 2.
Here's my quick attempt. Same result (except first element is 2 instead of 7. Maybe less code, or at least easier to read). No guarantees. 🙂
It doesn't really how conflicts are resolved; it's not possible for the S/W to determine what the data should be. I just need to have a valid data set to send to the GUI and a message to the user so he/she will look at it and make corrections.
09-22-2021 11:56 AM
... and a quick attempt to consolidate all that duplicate code for the error prep (just for fun 😉 ).