📄 lrulist.c
字号:
/********************************************************************
created: 2008/01/23
filename: lrulist.c
author: Lichuang
purpose:
*********************************************************************/
#include "lock.h"
#include "lrulist.h"
#include "node.h"
void linktolrulisthead(int index, ccache_t* cache)
{
if (-1 == cache->lrufirst && -1 == cache->lrulast)
{
cache->lrufirst = cache->lrulast = index;
return;
}
if (index == cache->lrufirst)
{
return;
}
node_t* node = NODE(cache, index), *tmp;
if (index == cache->lrulast)
{
cache->lrulast = node->lruprev;
}
int lrunext = node->lrunext, lruprev = node->lruprev;
if (-1 != lrunext)
{
tmp = NODE(cache, lrunext);
tmp->lruprev = lruprev;
}
if (-1 != lruprev)
{
tmp = NODE(cache, lruprev);
tmp->lrunext = lrunext;
}
node->lrunext = cache->lrufirst;
node->lruprev = -1;
if (-1 != cache->lrufirst)
{
tmp = NODE(cache, cache->lrufirst);
tmp->lruprev = index;
}
cache->lrufirst = index;
}
int freefromlrulist(int index, ccache_t* cache)
{
node_t* node = NODE(cache, index), *tmp;
int lrunext = node->lrunext, lruprev = node->lruprev;
if (0 <= lrunext)
{
tmp = NODE(cache, lrunext);
tmp->lruprev = lruprev;
}
if (0 <= lruprev)
{
tmp = NODE(cache, lruprev);
tmp->lrunext = lrunext;
}
if (index == cache->lrufirst)
{
cache->lrufirst = lrunext;
}
if (index == cache->lrulast)
{
cache->lrulast = lruprev;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -