forked from nonstriater/Learn-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
冉文杰
committed
Mar 21, 2017
1 parent
2603c0e
commit 6b61aca
Showing
4 changed files
with
68 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
## YYCache | ||
|
||
### 项目简介 | ||
|
||
[YYCache](https://github.com/ibireme/YYCache.git)是iOS系统上一套线程安全的Key-Value缓存实现,使用Objective-C语言实现。YYCache使用双向链表队列+hash表结构实现。 | ||
|
||
### 用到的算法介绍 | ||
|
||
先来看一下它的数据结构: | ||
|
||
``` | ||
// 这是一个节点的结构 | ||
@interface _YYLinkedMapNode : NSObject { | ||
@package | ||
__unsafe_unretained _YYLinkedMapNode *_prev; // retained by dic | ||
__unsafe_unretained _YYLinkedMapNode *_next; // retained by dic | ||
id _key; | ||
id _value; | ||
NSUInteger _cost; | ||
NSTimeInterval _time; | ||
} | ||
``` | ||
|
||
这里定义了一个双向链表结构,_prev,_next分别指向前缀节点和后缀节点。 | ||
|
||
``` | ||
@interface _YYLinkedMap : NSObject { | ||
@package | ||
CFMutableDictionaryRef _dic; // do not set object directly | ||
NSUInteger _totalCost; | ||
NSUInteger _totalCount; | ||
_YYLinkedMapNode *_head; // MRU, do not change it directly | ||
_YYLinkedMapNode *_tail; // LRU, do not change it directly | ||
BOOL _releaseOnMainThread; | ||
BOOL _releaseAsynchronously; | ||
} | ||
``` | ||
_dic 就是存储缓存节点的hash结构 | ||
_head 指向链表的头部,_tail指向链表的尾部,组成一个队列结构 | ||
|
||
|