C 基於List與Map實現的LRU快取

2021-10-03 12:33:14 字數 591 閱讀 7838

常見的快取淘汰演算法有先進先出淘汰演算法(fifo),最近最少使用淘汰演算法(lsu),最近最久未使用演算法(lru),mru(最近最常使用演算法)。其中最常用的就是lru快取淘汰演算法,下面給出**實現。

#include "stdafx.h"

#include #include #include using namespace std;

templateclass ******lrucache

bool contain(tkey& szkey)

bool get(tkey& szkey, tvalue &rvalue)

bool put(tkey& szkey, tvalue& szvalue)

return true;

} bool remove(tkey &szkey) };

int main()

int ival;

bool bget;

for (int i = 12; i >=0; i--) }

return 0;

}

核心設計思想:

1、使用鍊錶維護訪問順序

2、使用map加速查詢

List迴圈與Map迴圈的總結

做了一下list和map的總結,沒有什麼技術含量,就全當複習了一下api。測試環境是在junit4下,如果沒有自己寫乙個main方法也是一樣的。首先是list的三種迴圈 test public void forlisttest foreach相對比for來講,不需要知道集合的長度 for strin...

雜湊表 基於c 中map容器的實現

雜湊表是一類經常使用的查詢技術,在程式設計中也經常使用,這裡簡單談談基於map的雜湊表的實現。對映 map 是stl的乙個關聯容器,它提供一對一 第乙個為關鍵字,每個關鍵字只能出現一次 第二個為該關鍵字的值,即key value的形式 的資料處理能力 map常用的建構函式如下 1 map mapst...

Scala中List集合與Map集合的相互轉換

list集合轉換成map集合object demo println tuples 將list轉換成map val map map string,int tuples.tomap println map 結果為 list dog,3 tiger,5 lion,4 cat,3 panther,7 eag...