- 博客(9)
- 收藏
- 关注
原创 Leveldb BloomFliter 解析
BloomFilter 原理布隆过滤器由巴顿布隆于1970年提出,由一个很长的bit数组以及一系列hash函数组成。bloomfilter可以用于检索一个元素是否出现在一个集合中,bloomfilter的优点是相比hash表拥有极大的空间效率,缺点是会出现一定的错误概率(False positive,一个不在集合中的元素被误认为处于集合中)。 bloomfilter 的原理是,当一个元素在加...
2018-04-28 15:26:09 1522
原创 Leveldb skiplist 实现及解析
skiplist 原理介绍skiplist 由William Pugh 在论文Skip Lists: A Probabilistic Alternative to Balanced Trees 中提出的一种数据结构,skiplist 是一种随机化存储的多层线性链表结构,插入,查找,删除的都是对数级别的时间复杂度。skiplist 和平衡树有相同的时间复杂度,但相比平衡树,skip实现起来更简单...
2018-04-27 17:55:41 1776
原创 C++ 拼接长字符串
c++ string 类型提供 opearator+= 以及 append 方法进行字符串拼接,本文探讨c++拼接长字符串执行效率最高的方法。以下是四种实现方式。实现方式operator +=使用 string 类提供重载 += 方法拼接字符串。示例:// length 参数代表拼接的字符串长度void composeLongstringWithOperator(cons...
2018-04-26 17:13:06 5834
原创 [LeetCode] 819. Most Common Word
[LeetCode]819. Most Common Word题目描述Given a paragraph and a list of banned words, return the most frequent word that is not in the list of banned words. It is guaranteed there is at least one word...
2018-04-20 16:10:55 666
原创 Leveldb varint 原理解析
varint 介绍我们知道 uint32_t 类型占用4个byte,uint64_t 占用8个byte, 但是对于比较小的数字来说,使用uint32_t 或者uint64_t 存储会比较浪费,varint 的思想是根据数字所需大小使用unsigned char* 指针存储数据,节约内存。leveldb 实现leveldb 中的varint实现原理简单,每个byte 使用最高bit的...
2018-04-17 19:59:20 825
原创 Memcached hash table 解析
介绍Memcached中实现了高性能的hashtable。其解决hash冲突的方法采用拉链法。当hashtable 中存储的item个数大于容器大小的1.5倍的时候通知线程进行hashtable 扩容,为了保证在扩容期间的读写性能,扩容线程默认每次只迁移一个bucket。设置一个变量标识当前的迁移进度,在进行读写操作时根据此变量确定是去 old_hashtable 还是 primary_has...
2018-04-10 20:17:12 708
原创 LRU Cache 解析及实现
LRU Cache 原理LRU是Least Recently Used 的缩写,是一种缓存替换算法,当系统中的缓存满时,通过删除最近最少使用的元素来填充新的内容。LRU 算法在操作系统中有广泛应用,如CPU与物理内存之间的Cache替换算法, 物理内存与硬盘之间Cache替换算法。LRU Cache 实现我们可以使用一个双向链表和hash map 实现LRU Cache,其中hash ...
2018-04-02 18:00:15 499
原创 [LeetCode] 811. Subdomain Visit Count
811. Subdomain Visit Count题目描述A website domain like “discuss.leetcode.com” consists of various subdomains. At the top level, we have “com”, at the next level, we have “leetcode.com”, and at the lo...
2018-04-02 16:33:32 293
原创 [LeetCode] 804. Unique Morse Code Words
804. Unique Morse Code Words题目描述International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: “a” maps to “.-“, “b” maps to “-…”, “c”...
2018-04-02 14:49:00 841
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人