1. IR-book 经典教材中的思路 # Faster postings list intersection via skip pointers 通过跳指针,实现更快的 posting list 求交 https://nlp.stanford.edu/IR-book/html/htmledition/faster-postings-list-intersection-via-skip-pointers-1.html
一,简介 # jump consistent hash是一种一致性哈希算法, 此算法零内存消耗,均匀分配,快速,并且只有5行代码。
此算法适合使用在分shard的分布式存储系统中 。
此算法的作者是 Google 的 John Lamping 和 Eric Veach,论文原文在 http://arxiv.org/ftp/arxiv/papers/1406/1406.2294.pdf
完整代码:
int32_t JumpConsistentHash(uint64_t key, int32_t num_buckets) { int64_t b = -1, j = 0; while (j < num_buckets) { b = j; key = key * 2862933555777941757ULL + 1; j = (b + 1) * (double(1LL << 31) / double((key >> 33) + 1)); } return b; } 输入是一个64位的key,和桶的数量(一般对应服务器的数量),输出是一个桶的编号。
这是前几天笔试时,考场上想出来的算法,但是算了两次都不一样,最后只好蒙了一个选项,悲催!
问题如下:
给定一个整数序列,例如 4,2,6,3,7,1 ,该序列有多少个递增子序列?