mattwar/iqtoolkit

MostRecentlyUsedCache

Closed this issue · 1 comments

Hi Matt,

i think there is an issue in the MastRecentlyUsedCache class in method Lookup.

The method is always returing the last query not the one it found:

for (int i = 0, n = this.list.Count; i < n; i++)
{
   cached = this.list[i];

   if (fnEquals(cached, item))
   {
        cacheIndex = 0;
   }
}

I think this should be correct:

for (int i = 0, n = list.Count; i < n && cacheIndex < 0; i++)
{
   cached = this.list[i];

   if (_fnEquals(cached, item))
   {
       cacheIndex = i;
   }
}

The for-loop is two times in that method.

Thanks and best regards,

Markus

Yes, that code was wrong. bad code!

As far as I can tell, it was returning the found item, it was just never updating the MRU list.

I really need some unit tests for these common classes. 😞

I've fixed it with this change: a708c62