www.pudn.com > ccache.rar > node.c


/******************************************************************** 
	created:	2008/01/23 
	filename: 	node.c 
	author:		Lichuang 
                 
	purpose:     
*********************************************************************/ 
 
#include "node.h" 
#include "lock.h" 
#include "operator.h" 
#include "hash.h" 
#include "lrulist.h" 
 
int getfreenode(ccache_t* cache, cmpfun cmp, delfun fun) 
{ 
    int index = cache->firstfreenode; 
    node_t *node; 
    void *data, *key; 
 
    if (0 > index) 
    { 
        index = cache->lrulast; 
        node = NODE(cache, index); 
        int hash = node->hashindex; 
 
        if (NULL != fun) 
        { 
            key = NODE_KEY(NODE(cache, index)); 
            data = NODE_DATA(NODE(cache, index)); 
            fun(key, data); 
        } 
 
        freefromlrulist(index, cache); 
 
        DELETE_NODE(hash, index, cache, cmp); 
    } 
    else 
    { 
        node = NODE(cache, index); 
        cache->firstfreenode = node->next; 
    } 
 
    return index; 
}