@@ -124,29 +124,6 @@ to the Add method. */
124
124
/// </remarks>
125
125
protected abstract int ReplacementOffset { get ; }
126
126
127
- /// <summary>
128
- /// Return an enumerable container of indices into the value array from a set in the key array.
129
- /// </summary>
130
- /// <param name="set">The set to operate on.</param>
131
- /// <remarks>
132
- /// Generalizing enumeration of sets this way is actually slower -- notably, but not excessively --
133
- /// than copying the loop to all the places in the class that need to enumerate sets. I'll stay
134
- /// with this trade-off for now since it gives me some flexibility to modify the implementation
135
- /// later.
136
- /// </remarks>
137
- protected IEnumerable < int > GetSetPointerIndices ( int set ) {
138
- /* Get the first array index for the set; in other words, where in the array does the set start? */
139
- var setBegin = set * ways_ ;
140
-
141
- int setOffset ; // Offset into the set in the index array for where the key is stored
142
- int pointerIndex ; // Actual array location in the key array for setOffset
143
-
144
- /* Loop over the set, incrementing both the set offset (setOffset) and the pointer-array index (pointerIndex) */
145
- for ( setOffset = 0 , pointerIndex = setBegin ; setOffset < ways_ ; ++ setOffset , ++ pointerIndex ) {
146
- yield return pointerIndex ;
147
- }
148
- }
149
-
150
127
/// <summary>
151
128
/// Adds an element with the provided <paramref name="key"/> and <paramref name="value"/>
152
129
/// to the ParksComputing.ISetAssociativeCache if the <paramref name="key"/> is not found.
@@ -167,7 +144,7 @@ protected void AddOrUpdate(TKey key, TValue value, Action<TKey, TValue, int, int
167
144
168
145
/// <remarks>
169
146
/// We don't use the WalkSet method here because that introduces just enough extra
170
- /// logic to make this code path about 33 % slower, and that's too much of a slow-down
147
+ /// logic to make this code path about 30 % slower, and that's too much of a slow-down
171
148
/// even if it is still really fast in absolute terms.
172
149
/// </remarks>
173
150
@@ -395,11 +372,6 @@ public virtual bool Remove(TKey key) {
395
372
public virtual bool Remove ( KeyValuePair < TKey , TValue > item ) {
396
373
var set = FindSet ( item . Key ) ;
397
374
398
- /* Get the first array index for the set; in other words, where in the array does the
399
- set start? */
400
- var setBegin = set * ways_ ;
401
- var setEnd = setBegin + ways_ ;
402
-
403
375
return WalkSet ( set , ( set , pointerIndex ) => {
404
376
int valueIndex = pointerArray_ [ pointerIndex ] . Key ;
405
377
@@ -421,6 +393,16 @@ set start? */
421
393
} ) ;
422
394
}
423
395
396
+ /// <summary>
397
+ /// Walks over each element of a set in the key array and calls a delegate for each
398
+ /// element, passing the set and the key-array index corresponding to the current
399
+ /// element to the delegate. If the delegate returns <c>true</c>, the iteration stops.
400
+ /// </summary>
401
+ /// <param name="set">The set to iterate over.</param>
402
+ /// <param name="func">The delegate to call for each element.</param>
403
+ /// <returns>
404
+ /// <c>true</c> if the delegate returns <c>true</c> at any time; <c>false</c> otherwise.
405
+ /// </returns>
424
406
protected bool WalkSet ( int set , Func < int , int , bool > func ) {
425
407
/* Get the first array index for the set; in other words, where in the array does the
426
408
set start? */
@@ -437,6 +419,27 @@ set start? */
437
419
return false ;
438
420
}
439
421
422
+ /// <summary>
423
+ /// Return an enumerable container of indices into the value array from a set in the key array.
424
+ /// </summary>
425
+ /// <param name="set">The set to operate on.</param>
426
+ /// <remarks>
427
+ /// Compare this to the <c>WalkSet</c> method. Generalizing enumeration of sets this way is
428
+ /// noticeably slower than <c>WalkSet</c>, probably because of all the code that is
429
+ /// generated behind the scenes. I left it here in case it still may serve some purpose,
430
+ /// </remarks>
431
+ protected IEnumerable < int > GetSetPointerIndices ( int set ) {
432
+ /* Get the first array index for the set; in other words, where in the array does the set start? */
433
+ var setBegin = set * ways_ ;
434
+
435
+ int setOffset ; // Offset into the set in the index array for where the key is stored
436
+ int pointerIndex ; // Actual array location in the key array for setOffset
437
+
438
+ /* Loop over the set, incrementing both the set offset (setOffset) and the pointer-array index (pointerIndex) */
439
+ for ( setOffset = 0 , pointerIndex = setBegin ; setOffset < ways_ ; ++ setOffset , ++ pointerIndex ) {
440
+ yield return pointerIndex ;
441
+ }
442
+ }
440
443
441
444
/// <summary>
442
445
/// Gets an System.Collections.Generic.ICollection containing the keys of the ParksComputing.ISetAssociativeCache.
0 commit comments