diff --git a/二叉树/赫夫曼编码.md b/二叉树/赫夫曼编码.md index 2e4fb8e..b121e98 100644 --- a/二叉树/赫夫曼编码.md +++ b/二叉树/赫夫曼编码.md @@ -9,12 +9,12 @@ 需要一个字符编码表来解码,通过二叉树建立huffman编码和解码的字典表 -原始串: -二级制编码: -huffman编码: +原始串: +二级制编码: +huffman编码: -###存储结构和基本操作 +### 存储结构和基本操作 ``` struct node{ @@ -24,14 +24,14 @@ struct node{ } ``` -###构建赫夫曼树 +### 构建赫夫曼树 原则:出现频率越多的会在越上层,编码也越短,出现频率越少的在越下层,编码也越长。 不存在某一个编码是另一个编码的前缀,字符都在叶节点上,所以不会存在一个编码是另一个编码的前缀 二叉树每个节点要么是叶子节点,要么是双分支节点(且左分支编码为0,右分支编码为1) -###压缩 +### 压缩 1. 扫描输入文件,统计各个字符出现的次数,对结构排序 (hash统计每个字符出现的次数) 2. 根据排序结构,构建赫夫曼树 (贪心策略,每次选频率值最低的2个节点合并,需要优先队列帮组(priority queue,又叫最小堆)) diff --git a/字符串/README.md b/字符串/README.md index 4bb1247..0cb5783 100644 --- a/字符串/README.md +++ b/字符串/README.md @@ -5,44 +5,14 @@ * 排序 * 查找 -* 正则表达式 + * 单词查找树 + * 子串查找 +* 正则表达式 正则表达式是模式匹配的基础。是一个一般化了的子字符串的查找问题。也是搜索工具grep的核心。 + * 模式匹配 + * grep * 数据压缩 - - -### 排序 - - -### 查找 - - -#### 单词查找树 - - -#### 子串查找 - - - -### 正则表达式 - -正则表达式是模式匹配的基础。是一个一般化了的子字符串的查找问题。也是搜索工具grep的核心。 - - - -#### 模式匹配 - - -#### grep - - - -### 数据压缩 - - -#### 游程编码 - - -#### 赫夫曼树 - + * 赫夫曼树 + * 游程编码 ## 参考 diff --git a/开源项目中的算法/README.md b/开源项目中的算法/README.md index a3056a7..9a3c068 100644 --- a/开源项目中的算法/README.md +++ b/开源项目中的算法/README.md @@ -10,96 +10,19 @@ 2. 用到的算法介绍 -## [YYCache](https://github.com/ibireme/YYCache.git) - -### 项目简介 - -YYCache 是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指向链表的尾部,组成一个队列结构 - -## [cocos2d-objc](https://github.com/cocos2d/cocos2d-objc) - -### 项目简介 - - -### 用到的算法介绍 - - - -## [AsyncDisplayKit](https://github.com/facebook/AsyncDisplayKit) - -### 项目简介 - - -### 用到的算法介绍 - - -## [realm-cocoa](https://github.com/realm/realm-cocoa) - - - -## [YapDatabase](https://github.com/yapstudios/YapDatabase) - - - -## [FTCoreText](https://github.com/Ridiculous-Innovations/FTCoreText) - - - -## [Redis](https://github.com/antirez/redis) - - - -## [memcached](https://github.com/memcached/memcached) - - - -## [Nginx](https://github.com/nginx/nginx) - - - -## [Node](https://github.com/nodejs/node) - -V8引擎 - - -## [React](https://github.com/facebook/react) - - -## [react-native](https://github.com/facebook/react-native) +* [YYCache](https://github.com/ibireme/YYCache.git) +* [cocos2d-objc](https://github.com/cocos2d/cocos2d-objc) +* [AsyncDisplayKit](https://github.com/facebook/AsyncDisplayKit) +* [realm-cocoa](https://github.com/realm/realm-cocoa) +* [YapDatabase](https://github.com/yapstudios/YapDatabase) +* [FTCoreText](https://github.com/Ridiculous-Innovations/FTCoreText) +* [Redis](https://github.com/antirez/redis) +* [memcached](https://github.com/memcached/memcached) +* [Nginx](https://github.com/nginx/nginx) +* [Node](https://github.com/nodejs/node) V8引擎 +* [React](https://github.com/facebook/react) +* [react-native](https://github.com/facebook/react-native) +* ... diff --git a/开源项目中的算法/YYCache.md b/开源项目中的算法/YYCache.md new file mode 100644 index 0000000..ce89eeb --- /dev/null +++ b/开源项目中的算法/YYCache.md @@ -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指向链表的尾部,组成一个队列结构 + +