phxrpc使用了协程(ucontext)和IO复用技术(epoll)来实现网络通信。定时器在其中起到了非常重要的作用。下面我们就来分析一下phxrpc的timer.[h|cpp]
中的代码 …
void heapify(vector<int>& vec) {
int n = vec.size();
for (int a = 0, b = 1; b - 1 < n; a = b, b <<= 1) {
nth_element(vec.begin() + a, vec.begin() + b, vec.end());
}
}
You can implement a "heapify" by only four lines of code. And the time complexity is O(n)
.
Linkedin (or other social networks, such as Facebook and G+) use the "social graph information" to show the social relationship between you and other members.
Such as, "You and Mr.Obama share 10 mutual friends" or "You have 1,000 second-degree connections".
This feature is very common for a …
more ...用C++实现一个尽可能通用的sort函数
一个通用的sort函数应该包含以下要点:
Implementation
(n, m) = map(int, raw_input().split())
res = []
for i in xrange(n):
if i % 2 == 0:
res.append('#' * m)
elif (i / 2) % 2 == 0:
res.append('.' * (m - 1) + '#')
else:
res.append('#' + '.' * (m - 1))
for line in res:
print line
DFS …
more ...Simulation.
n = int(raw_input())
g = [[1 for i in xrange(n)] for j in xrange(n)]
for i in xrange(1, n):
for j in xrange(1, n):
g[i][j] = g[i - 1][j] + g[i][j - 1]
print g[n - 1][n - 1]