@@ -128,13 +128,13 @@ public static IReadOnlyList<IReadOnlyList<TextBlock>> Get(IReadOnlyList<IReadOnl
128128 throw new ArgumentException ( "The algorithm cannot be used with a document of less than 2 pages." , nameof ( pagesTextBlocks ) ) ;
129129 }
130130
131- ConcurrentDictionary < int , List < TextBlock > > pageDecorations = new ConcurrentDictionary < int , List < TextBlock > > ( ) ;
131+ ConcurrentDictionary < int , OrderedSet < TextBlock > > pageDecorations = new ConcurrentDictionary < int , OrderedSet < TextBlock > > ( ) ;
132132
133133 ParallelOptions parallelOptions = new ParallelOptions ( ) { MaxDegreeOfParallelism = maxDegreeOfParallelism } ;
134134
135135 Parallel . For ( 0 , pagesTextBlocks . Count , parallelOptions , p =>
136136 {
137- if ( ! pageDecorations . TryAdd ( p , new List < TextBlock > ( ) ) )
137+ if ( ! pageDecorations . TryAdd ( p , new OrderedSet < TextBlock > ( ) ) )
138138 {
139139 throw new ArgumentException ( "Cannot add element with index " + p + " in ConcurrentDictionary." ) ;
140140 }
@@ -165,7 +165,7 @@ public static IReadOnlyList<IReadOnlyList<TextBlock>> Get(IReadOnlyList<IReadOnl
165165 var score = Score ( current , previousPage , nextPage , minimumEditDistanceNormalised , similarityThreshold , n ) ;
166166 if ( score >= similarityThreshold )
167167 {
168- if ( ! pageDecorations [ p ] . Contains ( current ) ) pageDecorations [ p ] . Add ( current ) ;
168+ pageDecorations [ p ] . TryAdd ( current ) ;
169169 }
170170 }
171171
@@ -180,7 +180,7 @@ public static IReadOnlyList<IReadOnlyList<TextBlock>> Get(IReadOnlyList<IReadOnl
180180 var score = Score ( current , previousPage , nextPage , minimumEditDistanceNormalised , similarityThreshold , n ) ;
181181 if ( score >= similarityThreshold )
182182 {
183- if ( ! pageDecorations [ p ] . Contains ( current ) ) pageDecorations [ p ] . Add ( current ) ;
183+ pageDecorations [ p ] . TryAdd ( current ) ;
184184 }
185185 }
186186
@@ -195,7 +195,7 @@ public static IReadOnlyList<IReadOnlyList<TextBlock>> Get(IReadOnlyList<IReadOnl
195195 var score = Score ( current , previousPage , nextPage , minimumEditDistanceNormalised , similarityThreshold , n ) ;
196196 if ( score >= similarityThreshold )
197197 {
198- if ( ! pageDecorations [ p ] . Contains ( current ) ) pageDecorations [ p ] . Add ( current ) ;
198+ pageDecorations [ p ] . TryAdd ( current ) ;
199199 }
200200 }
201201
@@ -210,12 +210,12 @@ public static IReadOnlyList<IReadOnlyList<TextBlock>> Get(IReadOnlyList<IReadOnl
210210 var score = Score ( current , previousPage , nextPage , minimumEditDistanceNormalised , similarityThreshold , n ) ;
211211 if ( score >= similarityThreshold )
212212 {
213- if ( ! pageDecorations [ p ] . Contains ( current ) ) pageDecorations [ p ] . Add ( current ) ;
213+ pageDecorations [ p ] . TryAdd ( current ) ;
214214 }
215215 }
216216 } ) ;
217217
218- return pageDecorations . OrderBy ( x => x . Key ) . Select ( x => x . Value ) . ToList ( ) ;
218+ return pageDecorations . OrderBy ( x => x . Key ) . Select ( x => x . Value . GetList ( ) ) . ToList ( ) ;
219219 }
220220
221221 /// <summary>
0 commit comments