Ubuntu下LRUCache的实现

最近在看java的LInkedHashMap,提到了LRU算法,就查了下相关的资料,电脑是linux系统,就想着在该环境下试着实现吧,相对来说比winow开发麻烦一点,主要涉及到头文件的引用,命名空间的引用

关键点在于,应用HashMap和双向链表

(1)HashMap在于创建Key值和节点地址的对应关系

(2)双向链表在于控制节点的顺序,消除链表尾部的数据

代码如下,以备复习使用

 

#include<iostream>
#include<vector>
#include<hash_map>
#include<hash_set>
#include "HASH_MAP_HPP.h"

using namespace std;
using namespace __gnu_cxx;


/*namespace __gun_cxx
{
	template<> struct hash<string>
	{
		size_t operator()(const string& s) const
		{
			return __stl_hash_string(s.c_str());	
		}
	};
}*/

struct LRUCacheEntry{
	string key;
	string value;
	struct LRUCacheEntry * prev;
	struct LRUCacheEntry * next;
};

class LRUCache{
public:
	LRUCache(size_t size){
		entries = new  LRUCacheEntry[size];
		for(int i=0;i<size;i++){
			_freeEntries.push_back(entri
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值