By far the best way to illustrate this problem is to show a (rather long because it is fully "instrumented" for debugging purposes!) code segment and its output (and the values of all of the relevant variables are shown in the output). So, first the code:
And here is the (unexpected!) output of the above code:
I will add that after I ran and then extracted the above code I added some instrumentation to show exactly how often this error occurs, and the output of that is:
I am using the word "faux" because they are really not failures in the sense that they are not even repeatable! (That is, when comparing the strings again in the code to display the error output both character-by-character and in toto indicates that they truly are equal!)
Code:
Iff "%FileRoot[%RootIndex]" == "" Then
Set FileRoot[%RootIndex] = %FileKey
ElseIff "%FileRoot[%RootIndex]" == "%FileKey" Then
@Echo Already in file root array: %FileKey
Else
Set RawIndex=%RootIndex
Set CollisionCount = 0
Do Until "%FileRoot[%RootIndex]" == "" .OR. ^
"%FileRoot[%RootIndex]" == "%FileKey" .OR. ^
%CollisionCount == %@ArrayInfo[FileRoot,1]
Set CollisionCount=%@Inc[%CollisionCount]
@Echo File root collision number %CollisionCount
@EchoS FileRoot[%@Right[4,0000%RootIndex]]:
@Echo %FileRoot[%RootIndex]
@Echo FileKey: %FileKey
Set RawIndex=%@Eval[((%RawIndex SHL 1) AND ^
4294967295) XOR %RawIndex]
Set RootIndex=%@Eval[%RawIndex MOD ^
%@Dec[%@ArrayInfo[FileRoot,1]]]
EndDo
Iff "%FileRoot[%RootIndex]" == "" Then
Set FileRoot[%RootIndex] = %FileKey
ElseIff "%FileRoot[%RootIndex]" != "%FileKey"
@EchoSErr Yes, error! Comparison indicates
@EchoSErr that they do not match!
Set QRS=%@Len[%FileRoot[%RootIndex]]
Set RST=%@Len[%FileKey]
Set STU=0
If %QRS != %RST ^
@EchoErr File root entry different length then file key.
Set Mismatch=
Do While %STU LT %QRS .AND. %STU LT %RST
Iff "%@Instr[%STU,1,%FileRoot[%RootIndex]]" != ^
"%@Instr[%STU,1,%FileKey]" Then
@EchoSErr Mismatch: File root:
@EchoSErr "%@Instr[%STU,1,%FileRoot[%RootIndex]]"
@EchoErr FileKey: "%@Instr[%STU,1,%FileKey]"
Set Mismatch=T
EndIff
Set STU=%@Inc[%STU]
EndDo
Iff "%Mismatch" == "T" Then
@EchoSErr Internal Error: Unexpected results when
@EchoErr searching for file key "%FileKey" in file name array.
@EchoSErr Final incorrect entry found was
@EchoErr "%FileRoot[%RootIndex]"
Else
@EchoSErr Internal Error: Unexpected results when
@EchoErr searching for file key "%FileKey" in file name array.
@EchoErr Search terminated but entry was found!
Iff "%FileRoot[%RootIndex]" == "%FileKey" Then
@EchoErr And this time file root: "%FileRoot[%RootIndex]"
@EchoErr matches file key: "%FileKey"!!!
Else
@EchoErr Again FileRoot[%RootIndex]: "%FileRoot[%RootIndex]"
@EchoErr And FileKey: "%FileKey"
EndIff
EndIff
EndIff
EndIff
Code:
Yes, error! Comparison indicates that they do not match!
Internal Error: Unexpected results when searching for file key "Trans-2010-07-09.txt?01/21/10?19:29?14384" in file name array.
Search terminated but entry was found!
And this time file root: "Trans-2010-07-09.txt?01/21/10?19:29?14384"
matches file key: "Trans-2010-07-09.txt?01/21/10?19:29?14384"!!!
Code:
There were 3 faux failures.
3 of those failures were confirmed to be faux in the sense that they were
not repeatable, out of 10 iterations of the code in question.
Which is a confirmed faux failure percentage of 30%
(which means, of course, that the code in question works correctly
70% of the time).