Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb184b9

Browse files
Detect mini FAT cycles with Brent's algorithm
1 parent646e95e commiteb184b9

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

‎OpenMcdf/MiniFatChainEnumerator.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ internal sealed class MiniFatChainEnumerator : ContextBase, IEnumerator<uint>
1515
uintindex=uint.MaxValue;
1616
privateuintcurrent=uint.MaxValue;
1717
privatelonglength=-1;
18-
privateuintslow=uint.MaxValue;// Floyd's cycle-finding algorithm
18+
19+
// Brent's cycle-finding algorithm
20+
privateuintcycleLength=1;
21+
privateuintpower=1;
22+
privateuintslow=uint.MaxValue;
1923

2024
publicMiniFatChainEnumerator(RootContextSiterootContextSite,uintstartSectorId)
2125
:base(rootContextSite)
@@ -66,23 +70,27 @@ public bool MoveNext()
6670
{
6771
index=uint.MaxValue;
6872
current=uint.MaxValue;
73+
slow=uint.MaxValue;
6974
returnfalse;
7075
}
7176

7277
uintnextIndex=index+1;
7378
if(nextIndex>SectorType.Maximum)
7479
thrownewFileFormatException("Mini FAT chain length is greater than the maximum.");
7580

76-
if(nextIndex%2==0&&!SectorType.IsFreeOrEndOfChain(slow))
81+
if(value==slow)
82+
thrownewFileFormatException("Mini FAT chain contains a loop.");
83+
84+
if(cycleLength==power)
7785
{
78-
// Slow might become free or end of chain while shrinking
79-
slow=Context.MiniFat[slow];
80-
if(slow==value)
81-
thrownewFileFormatException("Mini FAT chain contains a loop.");
86+
cycleLength=0;
87+
power*=2;
88+
slow=value;
8289
}
8390

8491
index=nextIndex;
8592
current=value;
93+
cycleLength++;
8694
returntrue;
8795
}
8896

@@ -213,6 +221,8 @@ public void Reset()
213221
index=uint.MaxValue;
214222
current=uint.MaxValue;
215223
slow=uint.MaxValue;
224+
cycleLength=1;
225+
power=1;
216226
}
217227

218228
[ExcludeFromCodeCoverage]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp