明 光 大 正

pintos学习笔记1

    pintos     pintos

1,实现一个哈希函数

1
2
3
4
// HASH_SIZE 哈希参数
hashcode("abcd") = (ascii(a) * 333 + ascii(b) * 332 + ascii(c) *33 + ascii(d)) % HASH_SIZE
= (97* 333 + 98 * 332 + 99 * 33 +100) % HASH_SIZE
= 3595978 % HASH_SIZE

  • 注意超界——模运算
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    //(a+b)%c=(a%c+b%c)%c
    //(a*b)%c=(a%c*b%c)%c
    int hashCode(string str,int HASH_SIZE) {
    int leng = str.length();
    long sum = 0;
    long args = 1;
    for(int i = leng-1;i >= 0;i--)
    {
    sum += (str[i]*args%HASH_SIZE);
    args = args*33%HASH_SIZE;
    }
    return sum%HASH_SIZE;
    }

2,一个vector的基本用法
3,最多的点过直线


本来打算今天看thread的,被叫去打撸了。。。。

今天看了《我是路人甲》,没什么感觉。

页阅读量:  ・  站访问量:  ・  站访客数: