File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818
1919# this must match the equivalent function in qstr.c
2020def compute_hash (qstr ):
21- hash = 0
21+ hash = 5381
2222 for char in qstr :
23- hash += ord (char )
23+ hash = ( hash * 33 ) ^ ord (char )
2424 return hash & 0xffff
2525
2626def do_work (infiles ):
Original file line number Diff line number Diff line change 1818// A qstr is an index into the qstr pool.
1919// The data for a qstr contains (hash, length, data).
2020// For now we use very simple encoding, just to get the framework correct:
21- // - hash is 2 bytes (simply the sum of data bytes )
21+ // - hash is 2 bytes (see function below )
2222// - length is 2 bytes
2323// - data follows
2424// - \0 terminated (for now, so they can be printed using printf)
2828#define Q_GET_LENGTH (q ) ((q)[2] | ((q)[3] << 8))
2929#define Q_GET_DATA (q ) ((q) + 4)
3030
31+ // this must match the equivalent function in makeqstrdata.py
3132machine_uint_t qstr_compute_hash (const byte * data , uint len ) {
32- machine_uint_t hash = 0 ;
33+ // djb2 algorithm; see http://www.cse.yorku.ca/~oz/hash.html
34+ machine_uint_t hash = 5381 ;
3335 for (const byte * top = data + len ; data < top ; data ++ ) {
34- hash += * data ;
36+ hash = (( hash << 5 ) + hash ) ^ ( * data ); // hash * 33 ^ data
3537 }
3638 return hash & 0xffff ;
3739}
You can’t perform that action at this time.
0 commit comments