- 博客(87)
- 资源 (25)
- 收藏
- 关注
原创 JavaScript function expression vs function declaration
在Javascript中创建function有两种方式:function expression 和function declaration。它们的定义分别是:FunctionDeclaration: FunctionIdentifier(formatParameterListOpt) { FunctionBody}FunctionExpression:
2015-01-10 18:59:01
951
翻译 为什么有序数组比无序数组快呢?
来自stackoverflow的题目Why is processing a sorted array faster than an unsorted array?
2014-10-12 14:44:28
1286
原创 关于fork()
Fork()是linux下常用的系统API,通过系统调用创建一个与原来进程几乎完全相同的进程,也就是两个进程可以做完全相同的事情;也可由于参数的不同,或代码不同分支做完全不相同的事情。fork调用的一个奇妙之处就是它仅仅被调用一次,却能够返回两次,它可能有三种不同的返回值: 1)在父进程中,fork返回新创建子进程的进程ID; 2)在子进程中,fork返回0; 3
2014-09-08 14:28:32
590
原创 Javascript中Function declarations 理解
Javascript 中function declaration在ECMA5与ECMA6不同定义之理解。
2014-08-13 14:06:11
1222
转载 ThreadSanitizer AddressSanitizer MemorySanitizer
Thread-sanitizer=======ThreadSanitizer (aka TSan) is a data race detector for C/C++. Data races are one of the most common and hardest to debug types of bugs in concurrent systems. A data race
2014-07-04 19:46:28
2430
原创 yield in Python
To understand what yield does, you must understand what generators are. And before generators come iterables.
2014-06-05 19:39:35
794
原创 两个数组的元素之和最大的前k项
题目:两个数组,从每个数组中取一个数相加,求最大的前k个和 数组A:1,2,3 数组B:4,5,6 则最大的前2个和:9,8。
2014-05-06 20:10:14
3409
转载 If advanced algorithms and data structures are never used in industry, then why learn them?
Here is one question from Quora. Just record it here...I and people I know have never used any advanced algorithms or data structures in industry and some of us have 20 years of experience in indust
2014-05-06 11:03:44
978
原创 Is Python call-by-value or call-by-reference?
First of all, here are two pieces of codes:
2014-04-20 10:29:35
1833
转载 Static method vs class method in Python
Pyhon中@static method和@class method对于刚接触的人而言,有很多迷茫的地方。随之,
2014-04-14 19:50:47
3021
原创 Single Number题解整理
Q: Given an array of integers, every elementappears three times except for one. Find that single one. 如果是其余元素均出现两次,这个题目很容易解决,我们直接可以用xor,把所有的数异或之后的结果,便是出现一次的数字。但是这个题目其余元素出现的次数是三次,如果数组中的元素都是三个三个出现的,
2014-04-08 20:50:04
555
原创 使用windbg检测内存泄漏
使用windbg检测内存泄漏缘起:作为C++程序员,检测内存泄漏是非常痛苦的事情。尤其是看着程序的内存在一直增长,你却无能为力。此时,windbg可以用来检测内存泄漏。配置windbg:1. 配置symbol文件路径: “SRV*d:\symbols*http://msdl.microsoft.com/download/symbols”.2. 增加测
2014-03-24 16:58:05
9053
原创 从游戏中看循环不变量
罐中红球与蓝球问题:假设罐中有红球与蓝球若干,从罐中取球,规则是: while (# of marbles inthe jar > 1) { choose (any) twomarbles from the jar; if (the two marblesare of the same color) { toss them asid
2014-02-28 09:24:08
928
原创 Loop Invariant 循环不变量
循环不变量(loop invariant)是一个不变量,被用来证明循环的特点,更多地,算法使用循环 (usually 正确性)。非正式的说,一个循环不变量是指在循环开始和循环中每一次迭代时永远为真的量,这意味着在循环中和循环结束时循环不变量和循环终止条件必须同时成立。以二分法为例:已知 A[1..n] 是单调递增的数列,求 A 中所有大于或等于target的值中,最小的那一个的序号。int
2014-02-25 14:21:57
2507
原创 socket相关知识
1. Blocking/Non-blocking vs Sync/Async- Blocking I/O means that thecalling system does not return control to the caller until the operation isfinished. As a result, the caller is blocked and
2013-12-20 10:26:36
615
原创 Hash 函数
Hashing H(key)= key %MLinear probe Slot = (home+i)%M Homeis index to which the key originally mapped by the hash function
2013-10-30 09:17:28
588
转载 Polay定理总结
polya定理主要就是解决一类着色问题,或者说是同构计数问题。对Ω的n个目标用m种颜色着色的图象集种类数。定理的内容:Pólya定理:设G={p1,p2,…,pg}是Ω上的一个置换群,C(pk)是置换pk的循环的个数,用M中的颜色对Ω中的元素着色,着色方案数为 l = 1/|G|*[c1(p1)+c1(p2)+c1(p3)+...c1(p[g])]=1/|G|*[m^c(p1)+m
2013-10-02 19:10:29
1875
原创 雾里看花集锦
有的code咋看起来,感觉没啥问题,typedef bitset mybit;int _tmain(int argc, _TCHAR* argv[]){ mybit test_bs; test_bs.set(1, true); myprintf("%s", test_bs.to_string());}void myprintf(...){}上述的code有时候运行没
2013-08-14 22:38:51
806
转载 最大最小堆介绍
最大最小堆1. 定义:最小最大堆是一棵完全二叉树,且其中每个元素有一个key数据成员。树的各层交替为最小层和最大层。根结点在最小层。设x是最小最大堆的任意结点。若x在最小(最大)层上,则x中的元素的key值在以x为根的子树的所有元素中是最小(最大)的。位于最小(最大)层的结点称为最小(最大)结点。2. 特征:(1) 插入一个具有任意key值的元素(2) 删除ke
2013-07-19 09:26:32
1822
原创 Map-reduce 矩阵
来自微博的题目: Map Reduce 矩阵。新的矩阵的值,是原来矩阵附近8个临近节点的均值。python代码实现:# input: element is the key value pair of matrix# type: [row, column, value, totle_row, totle_column]def mapper(elem):
2013-07-11 10:32:57
695
原创 蓄水池算法简介
从N个元素中随机抽取k个元素,但是N不定。每个元素抽取的概率是k/N。先选中前k个,从k+1到最后一个元素,以1/i (i = k+1, k+2, ... N)的概率选中第i个元素,并且随机替换一个原来选中的元素。 1 from random import Random 2 3 def RandomSelect(knum, rand=None): 4 selec
2013-07-04 10:51:29
933
原创 忘我之乘积的解答
Q: Given array a [n], Get array b [n] b [i] = a [0] * a [1] ... a [n-2] * a [n-1] / a [i] Requirements can not be used to divide In addition to traverse the counter with a [N] b [N], do not use
2013-07-04 10:45:11
605
原创 最长公共子字符串 (Longest Common Substring)
问题:字符串 "ABABC", "BABCA" 最长公共子字符串是 "ABC"?solution1: suffix tree建立suffix tree时间复杂度是O(N), 查找公共子字符串的代价是O(m+n), m和n分别是两个字符串的长度。关于suffix tree请参考http://mila.cs.technion.ac.il/~yona/suffix_tree/
2013-06-21 18:14:51
1231
原创 BOP - 1的数目
文章后面的扩展问题:对于二进制,统计1的数目。f(1) = 1f(10) = 10f(11) = 100…What is f(n)? Analysis: by different bit n (binary) f(n) (decimal sum by column)
2013-05-21 15:22:11
803
原创 MongoDB 简介
MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。他支持的数据结构非常松散,是 类似json的bson格式,因此可以存储比较复杂的数据类型。Mongo最大的特点是他支持的查询语言非常强大,其语法有点类似于面向对象的查询语 言,几乎可以实现类似关系数据库单表查询的绝大部分功能,而且还支持对数据建立索引。基本术语Do
2013-03-29 09:57:27
1003
原创 理解JavaScript Closure
援引StackOverflow上的一个帖子:http://stackoverflow.com/questions/12930272/javascript-closures-vs-anonymous-functions关于closure,一个经典的错误实例如下:for(var i = 0; i < 10; i++) { setTimeout(function() {
2013-03-26 19:05:38
870
原创 几个 JavaScript Questions
Javascript 本身就有很多独特的语言特性。由此,相关的问题也很有意思。接下来,我列举几个,并简单分析一下。我是在chrome下测试的。。。var a = 1, b = function a(x) { x && a(--x); };alert(a);Answer: 1.Analyze: functiona() just anonymous f
2013-03-18 19:05:11
800
原创 MongoDB中group() mapReduce() aggregate()之比较
对于SQL而言,如果从users表里查询每个team所有成员的number,查询语句如下:SELECT team, no FROM users GROUP BY team (1)但是对于Mongodb而言,实现这样的功能,则比较复杂。从mongodb2.2之后,有了三个function可以实现这个功能,他们按照产生的顺序,
2013-03-13 19:26:20
9928
原创 二分搜索的应用
Binary Search 总所周知,在处理一些实际问题中也有很好的应用。举例如下:问题:一个数组是由一个递减数列左移若干位形成的,比如{4,3,2,1,6,5} 是由{6,5,4,3,2,1}左移两位形成的,在这种数组中查找某一个数。 答案: 二分解决。注意到a[0]5 /** 6 * @func: the binary search fur descendin
2012-12-11 14:47:11
1120
原创 关于C++构造函数抛出异常
The code like this is inherently vulnerable to memory leaks(if the constructor failed)?class Foo{public: Foo() : a(new int), b(new int) {} ~Foo() { delete a;
2012-12-10 15:50:49
591
原创 XOR Linked List
An ordinary doubly linked list stores addresses of the previousand next list items in each list node, requiring two address fields: ... A B C D E ... –>
2012-11-16 11:05:02
897
原创 凑钱问题
Q: 有足够量的2分、5分、1分硬币,请问凑齐1元钱有多少种方法?我们从简单情况开始分析,假如有足够量的1分硬币,请问凑齐1分钱有多少种方法?毫无疑问,答案是1。然后,凑齐2分钱有多少种方法?凑齐n分钱有多少种方法?答案均是1。接下来,假如有足够量的1分硬币和2分硬币,凑齐n分钱有多少种方法?对于1分硬币,凑齐任意n分钱都只有1种方法;那么只用1分钱凑齐n-2分钱,有1种方法;只用1分
2012-11-15 19:46:32
1229
原创 VC++在release下对return的优化
编译环境 VS2008, release模式。今天,对于如下的code进行debug,单步运行。此时index的值是1,我们一般会认为code走到36行,然后退出。但是,实际上,code走到38行,当时我们就凌乱了,难道code中if语句有问题,看了又看。茫然。。。。。。忽然想到,VS在release模式下,对于code有优化。。。看看汇编code吧,果然,VS
2012-09-03 19:27:35
614
轻松搞定XML(PDF)
2010-04-25
C安全编码标准(实现C安全编程的权威指南)
2010-01-05
程序员面试攻略-(第2版)
2009-12-29
Linux内核阅读心得
2009-12-23
The Linux® Networking Architecture: Design and Implementation of Network Protocols in the Linux Kernel
2009-09-02
Understanding the Linux Kernel, 3rd Edition
2009-09-02
windows核心编程
2009-08-01
SQL Bible-Alex Kriegel and Boris M
2009-08-01
MySql5权威指南(英文版)
2009-05-04
十分钟学会SQL--SAM
2009-05-01
C++ Standard Library: A Tutorial and Reference
2008-08-27
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人