After hours of thinking about this and no further clues I decided to simply replace my SortedList
with a SortedDictionary
Datastructure.
That solved the Problem, although if anyone knows why the Version with the SortedList
wasn't working, please tell me.
'failed to compare two elements in the array' for SortedList
-
22-06-2023 - |
Question
One of the people who use a Protocol generation tool that I wrote, reported an error that I can not really understand:
Failed to compare two elements in the array.
I use a SortedList
to hold all Issues for the Protocol and sort them with the following Sort method in a special comparer:
Public Function Compare(x As String, y As String) As Integer Implements IComparer(Of String).Compare
Dim val1BiggerVal2 As Integer = 0
Dim subkeysVal1 As String() = x.Split("_"c)
Dim subkeysVal2 As String() = y.Split("_"c)
Dim rxNumberOnly As Regex = New Regex("^[0-9]+$")
Dim leftTaskgroup, leftParent, leftKey, leftID, leftCompstring, rightTaskgroup, rightParent, rightKey, rightID, rightCompstring As String
leftCompstring = ""
For counter As Integer = 0 To subkeysVal1.Length - 5
leftCompstring &= subkeysVal1(counter)
Next
leftTaskgroup = subkeysVal1(subkeysVal1.Length - 4)
leftParent = subkeysVal1(subkeysVal1.Length - 3)
leftKey = subkeysVal1(subkeysVal1.Length - 2)
leftID = subkeysVal1(subkeysVal1.Length - 1)
rightCompstring = ""
For counter As Integer = 0 To subkeysVal1.Length - 5
rightCompstring &= subkeysVal2(counter)
Next
rightTaskgroup = subkeysVal2(subkeysVal2.Length - 4)
rightParent = subkeysVal2(subkeysVal2.Length - 3)
rightKey = subkeysVal2(subkeysVal2.Length - 2)
rightID = subkeysVal2(subkeysVal2.Length - 1)
val1BiggerVal2 = compareSubstring(leftCompstring, rightCompstring)
'If Components where the same, check Taskgroups
If (val1BiggerVal2 = 0) Then
val1BiggerVal2 = compareSubstring(leftTaskgroup, rightTaskgroup)
End If
'If Taskgroups where the same, check parent-child relation
If (val1BiggerVal2 = 0) Then
If rightKey = leftParent Then
val1BiggerVal2 = 1
ElseIf rightParent = leftKey Then
val1BiggerVal2 = -1
ElseIf rightParent = leftParent Then
val1BiggerVal2 = compareSubstring(leftKey, rightKey)
Else
Dim Left As String = leftParent
Dim Right As String = rightParent
If leftParent = "" Then
Left = leftKey
End If
If rightParent = "" Then
Right = rightKey
End If
val1BiggerVal2 = compareSubstring(Left, Right)
End If
End If
'if even the parent-child relation wasnt unquie, use the autoincremented endvalue
If val1BiggerVal2 = 0 Then
val1BiggerVal2 = leftID.compareTo(rightID)
End If
Return val1BiggerVal2
End Function
I think with the last check, if val1biggerVal2
is 0 I should always get a unique identification, because the last _ID
is auto increased each time I read an issue from the input file.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow