Numbers Programmers Should Know About Hash

There is a hash table:

  • It has b buckets.
  • It has n keys stored in it.
  • We assume that the hash function distributes keys uniformly.
  • A bucket can contain more than 1 keys.

If n b, the hash table would look like this:

  • 37% buckets are empty.
  • 37% buckets contain 1 key.
  • 26% buckets contain more than 1 key, which means collision occurs.

The following chart created by program simulation shows distribution of 20 keys over 20 buckets.

continue reading>>

Vim-tabbar: Simple, stupid and fast tab-bar for VIM

Simple, stupid and fast tab-bar for VIM.

continue reading>>

1% 慢请求优化

1个客户端同时向服务器发出100个请求,等待所有的请求都返回才算成功。
99%的请求10ms返回,1%的请求1000ms返回.

假设慢请求的概率是 ,请求总数是 . 能快速(10ms)返回的概率有多少?如何优化?

continue reading>>

Some useful resources

Google HTML CSS 代码风格指南

A Note About Git Commit Messages

Google’s Python Class

continue reading>>

jobq.py -- Queue processing engine

jobq.py processes serial of input elements with several functions concurrently and sequentially.

Check out on github: jobq.

Example:

import jobq

def add1( args ):
    return args + 1

def multi2( args ):
    return args * 2

def printarg( args ):
    print args

jobq.run( [ 0, 1, 2 ], [ add1, printarg ] )
# > 1
# > 2
# > 3

jobq.run( ( 0, 1, 2 ), [ add1, multi2, printarg ] )
# > 2
# > 4
# > 6
continue reading>>