@@ -384,14 +384,10 @@ fn mk_flat_hashmap<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>)
384
384
// is always a power? of 2), so that all buckets are probed for a
385
385
// fixed key.
386
386
387
- fn hashl ( n : u32 ) -> u32 { ret ( n >>> 16u32 ) * 2u32 + 1u32 ; }
388
- fn hashr ( n : u32 ) -> u32 { ret 0x0000_ffff_u32 & n; }
389
- fn hash ( h : u32 , nbkts : uint , i : uint ) -> uint {
390
- ret ( ( hashl ( h) as uint ) * i + ( hashr ( h) as uint ) ) % nbkts;
391
- }
392
-
393
- fn to_u64 ( h : uint ) -> u32 {
394
- ret ( h as u32 ) ^ ( ( h >>> 16 u) as u32 ) ;
387
+ fn hashl ( n : uint ) -> uint { ret ( n >>> 16 u) * 2 u + 1 u; }
388
+ fn hashr ( n : uint ) -> uint { ret 0x0000_ffff_ u & n; }
389
+ fn hash ( h : uint , nbkts : uint , i : uint ) -> uint {
390
+ ret ( hashl ( h) * i + hashr ( h) ) % nbkts;
395
391
}
396
392
397
393
/**
@@ -402,18 +398,26 @@ fn mk_flat_hashmap<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>)
402
398
bkts : [ mutable bucket< K , V > ] ,
403
399
nbkts : uint , key : K , val : V ) -> bool {
404
400
let i: uint = 0 u;
405
- let h = to_u64 ( hasher ( key) ) ;
401
+ let h = hasher ( key) ;
406
402
while i < nbkts {
407
403
let j: uint = hash ( h, nbkts, i) ;
408
404
alt bkts[ j] {
409
405
some ( k, _) {
410
406
// Copy key to please alias analysis.
411
407
412
408
let k_ = k;
413
- if eqer ( key, k_) { bkts[ j] = some ( k_, val) ; ret false; }
409
+ if eqer ( key, k_) {
410
+ log ( "map updated" , "i" , i, "h" , h, "nbkts" , nbkts) ;
411
+ bkts[ j] = some ( k_, val) ;
412
+ ret false;
413
+ }
414
414
i += 1 u;
415
415
}
416
- _ { bkts[ j] = some ( key, val) ; ret true; }
416
+ _ {
417
+ log( "map inserted" , "i" , i, "h" , h, "nbkts" , nbkts) ;
418
+ bkts[ j] = some ( key, val) ;
419
+ ret true;
420
+ }
417
421
}
418
422
}
419
423
fail; // full table
@@ -422,17 +426,23 @@ fn mk_flat_hashmap<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>)
422
426
bkts : [ mutable bucket< K , V > ] ,
423
427
nbkts : uint , key : K ) -> option:: t < V > {
424
428
let i: uint = 0 u;
425
- let h = to_u64 ( hasher ( key) ) ;
429
+ let h = hasher ( key) ;
426
430
while i < nbkts {
427
431
let j: uint = hash ( h, nbkts, i) ;
428
432
alt bkts[ j] {
429
433
some ( k, v) {
430
434
// Copy to please alias analysis.
431
435
let k_ = k;
432
436
let v_ = v;
433
- if eqer ( key, k_) { ret option:: some ( v_) ; }
437
+ if eqer ( key, k_) {
438
+ log ( "map present" , "i" , i, "h" , h, "nbkts" , nbkts) ;
439
+ ret option:: some ( v_) ;
440
+ }
441
+ }
442
+ nil. {
443
+ log ( "map absent" , "i" , i, "h" , h, "nbkts" , nbkts) ;
444
+ ret option:: none;
434
445
}
435
- nil. { ret option :: none; }
436
446
deleted. { }
437
447
}
438
448
i += 1 u;
@@ -495,7 +505,7 @@ fn mk_flat_hashmap<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>)
495
505
}
496
506
fn remove ( key : K ) -> option:: t < V > {
497
507
let i: uint = 0 u;
498
- let h = to_u64 ( hasher ( key) ) ;
508
+ let h = hasher ( key) ;
499
509
while i < nbkts {
500
510
let j: uint = hash ( h, nbkts, i) ;
501
511
alt bkts[ j] {
0 commit comments