当前位置: 首页 > news >正文

网站建设价格明细表和网站预算google下载官方版

网站建设价格明细表和网站预算,google下载官方版,巴中 网站建设,wordpress 添加证书C# 实现Lru缓存 LRU 算法全称是最近最少使用算法#xff08;Least Recently Use#xff09;#xff0c;是一种简单的缓存策略。 通常用在对象池等需要频繁获取但是又需要释放不用的地方。 代码实现的基本原理就是使用链表#xff0c;当某个元素被访问时#xff08;Get或…C# 实现Lru缓存 LRU 算法全称是最近最少使用算法Least Recently Use是一种简单的缓存策略。 通常用在对象池等需要频繁获取但是又需要释放不用的地方。 代码实现的基本原理就是使用链表当某个元素被访问时Get或Set就将该元素放到链表的头部或者尾部根据用户自己定义规则即可当达到了缓存的最大容量时对最不常使用的元素进行移除移除的时候可以定义一系列的规则用于判读如何移除是否移除 下面直接贴出来代码供大家参考 using System; using System.Collections; using System.Collections.Generic; using System.Threading;namespace ET {public class LruCacheTKey, TValue: IEnumerableKeyValuePairTKey, TValue{private const int DEFAULT_CAPACITY 255;private int capacity;private ReaderWriterLockSlim locker;private DictionaryTKey, TValue dictionary;private LinkedListTKey linkedList;private FuncTKey, TValue, bool checkCanPopFunc;private ActionTKey, TValue popCb;public LruCache(): this(DEFAULT_CAPACITY){}public LruCache(int capacity){this.locker new ReaderWriterLockSlim();this.capacity capacity 0? capacity : DEFAULT_CAPACITY;this.dictionary new DictionaryTKey, TValue(DEFAULT_CAPACITY);this.linkedList new LinkedListTKey();}/// summary/// 设置检测什么条件可以释放/// /summary/// param namefunc/parampublic void SetCheckCanPopCallBack(FuncTKey, TValue, bool func){this.checkCanPopFunc func;}/// summary/// 设置如何释放/// /summary/// param nameaction/parampublic void SetPopCallBack(ActionTKey, TValue action){this.popCb action;}public TValue this[TKey t]{get{if (TryGet(t, out TValue val))return val;throw new ArgumentException();}set{Set(t,value);}}public bool TryGet(TKey key, out TValue value){this.locker.EnterUpgradeableReadLock();try{bool b this.dictionary.TryGetValue(key, out value);if (b){this.locker.EnterWriteLock();try{this.linkedList.Remove(key);this.linkedList.AddFirst(key);}finally{this.locker.ExitWriteLock();}}return b;}finally{this.locker.ExitUpgradeableReadLock();}}public void Set(TKey key, TValue value){this.locker.EnterWriteLock();try{if (this.checkCanPopFunc ! null)this.MakeFreeSpace();this.dictionary[key] value;this.linkedList.Remove(key);this.linkedList.AddFirst(key);//没有设置检测释放条件的话容量超载了就移除if (this.checkCanPopFunc null this.linkedList.Count this.capacity){this.dictionary.Remove(this.linkedList.Last.Value);this.linkedList.RemoveLast();}}finally{this.locker.ExitWriteLock();}}public DictionaryTKey, TValue GetAll(){return this.dictionary;}public void Remove(TKey key){this.locker.EnterWriteLock();try{this.dictionary.Remove(key);this.linkedList.Remove(key);}finally{this.locker.ExitWriteLock();}}public bool TryOnlyGet(TKey key, out TValue value){bool b this.dictionary.TryGetValue(key, out value);return b;}public bool ContainsKey(TKey key){this.locker.EnterReadLock();try{return this.dictionary.ContainsKey(key);}finally{this.locker.ExitReadLock();}}public int Count{get{this.locker.EnterReadLock();try{return this.dictionary.Count;}finally{this.locker.ExitReadLock();}}}public int Capacity{get{this.locker.EnterReadLock();try{return this.capacity;}finally{this.locker.ExitReadLock();}}set{this.locker.EnterUpgradeableReadLock();try{if (value 0 this.capacity ! value){this.locker.EnterWriteLock();try{this.capacity value;while (this.linkedList.Count this.capacity){this.linkedList.RemoveLast();}}finally{this.locker.ExitWriteLock();}}}finally{this.locker.ExitUpgradeableReadLock();}}}public ICollectionTKey Keys{get{this.locker.EnterReadLock();try{return this.dictionary.Keys;}finally{this.locker.ExitReadLock();}}}public ICollectionTValue Values{get{this.locker.EnterReadLock();try{return this.dictionary.Values;}finally{this.locker.ExitReadLock();}}}public void Clear(){this.dictionary.Clear();this.linkedList.Clear();}private void MakeFreeSpace(){LinkedListNodeTKey node this.linkedList.Last;//检测最不常用的10个int max_check_free_times 10; //最大检测空闲次数int cur_check_free_time 0; //当前检测空闲次数while (this.linkedList.Count 1 this.capacity){if (node null)break;LinkedListNodeTKey tuple_prev node.Previous;if (this.checkCanPopFunc null || this.checkCanPopFunc(node.Value, this.dictionary[node.Value])){//可以释放var value this.dictionary[node.Value];this.dictionary.Remove(node.Value);this.linkedList.RemoveLast();this.popCb?.Invoke(node.Value, value);}else{cur_check_free_time;if (cur_check_free_time max_check_free_times){break;}}node tuple_prev;}}public IEnumeratorKeyValuePairTKey, TValue GetEnumerator(){foreach (var item in this.dictionary){yield return item;}}IEnumerator IEnumerable.GetEnumerator(){foreach (var item in this.dictionary){yield return item;}}} }
http://www.hkea.cn/news/14564619/

相关文章:

  • 建设网站那家好网页制作基础题
  • 没有备案的交易网站wordpress文章浏览数
  • 绵阳新农网的网站是哪个公司做的厦门百度seo
  • 包小盒设计网站中山网站建设文化案例
  • 注册网站域名平台网页转app制作工具 安卓
  • 信誉好的赣州网站建设网络培训系统入口
  • 做房产网站用什么软件WordPress评论列表去掉回复
  • 行业网站方案网站建设作业做一个简单的网站
  • 国际网站怎么做优化微信商城小程序搭建教程
  • 门户网站建设方案wordpress5.0.3
  • asp网站做视频教程帝国cms对比WordPress
  • 网站 自定义表单网站首页的名字通常是
  • 淘宝网站开始怎么做的aspcms手机网站模板
  • php网站开发自学做电销哪些网站可以找到客户端
  • 潍坊建站公司沧州网络科技有限公司
  • 学习网站建设要报班吗自己建的网站如何做海外推广
  • 单页网站有哪些青海省教育厅门户网站登录
  • 校园网站建设的重要性png免费素材网站
  • 前端一般模仿什么网站计算机网络技术网站开发
  • 移动端网站优秀案例泉州seo外包平台
  • 西安网站建设畅网网站 营销方案
  • 鲤城区建设局网站dw用设计视图做网站
  • 怎么制作网站主页西安企业网站制作价格
  • 河南建设网站信息查询中心平面设计学费多少钱
  • 网站更新方法网站开发实验报告可行性分析
  • 做网站备案成功后怎么办网站建设质量保证
  • 惠州网站制作费用lisp 网站开发
  • 素材分享网站源码网站公司怎么做业务
  • 触屏版网站源码中文域名网站有哪些
  • 做网站去哪里做好猪八戒网网站设计