5、能上比较憋屈。可以将32字节换成8个int型或者4个longlong型,因为CPU可以直接对两个整型进行比较。实际开发中,我将32字节的key分成了8个int,将所有的缓存数据按模分类分级,先定义中间容器的结构:typedef struct yumei_cache_container_s yumei_cache_container_t; struct yumei_cache_container_s{ int container_num; int
7、_map_data_s { int key[8]; int times; int start_time; void* data; yumei_cache_map_data_t* next; };times是指这个数据被查询过多少次,start_time则是开始查询时间,这两个参数是为了新陈代谢用的,比如一个数据在昨天天被查了30次,times=30,在昨天会被当成频繁数据加到缓存里,但是今天一次都没有查过,这样的数据就要被淘汰出去。定义完了数据结构,就剩下算法了,主要推荐两种:1.红黑树2.hashmap