- added better hashing function for flonums and bignums.

This commit is contained in:
Abdulaziz Ghuloum 2008-10-31 23:53:15 -04:00
parent 671eba4990
commit 74a1d302ec
2 changed files with 16 additions and 4 deletions

View File

@ -1 +1 @@
1656
1657

View File

@ -2124,11 +2124,23 @@ ikrt_exact_bignum_sqrt(ikptr bn, ikpcb* pcb){
ikptr
ikrt_flonum_hash(ikptr x /*, ikpcb* pcb */) {
return fix(0);
short* buf = (short*)(x+off_flonum_data);
return fix(((long)buf[0]) ^
((long)buf[1] << 3) ^
((long)buf[3] << 7) ^
((long)buf[2] << 11));
}
ikptr
ikrt_bignum_hash(ikptr x /*, ikpcb* pcb */) {
return fix(0);
ikrt_bignum_hash(ikptr bn /*, ikpcb* pcb */) {
ikptr fst = ref(bn, -vector_tag);
long int limb_count = bnfst_limb_count(fst);
long h = (long)fst;
mp_limb_t* dat = (mp_limb_t*)(bn+off_bignum_data);
long i;
for (i=0; i<limb_count; i++){
h = (h^dat[i]) << 3;
}
return fix(h);
}