Skip to content

Commit

Permalink
resize condition graphs completed #11
Browse files Browse the repository at this point in the history
  • Loading branch information
petergarnaes committed Jun 5, 2014
1 parent 7f81e14 commit 4053837
Show file tree
Hide file tree
Showing 39 changed files with 632 additions and 57 deletions.
Binary file modified hashmap/.mod.rs.swp
Binary file not shown.
58 changes: 56 additions & 2 deletions hashmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub mod raw_table;


//ADD_RANGE -
pub static ADD_RANGE: uint = 256;
pub static ADD_RANGE: uint = 512;
pub static VIRTUAL_BUCKET_CAPACITY: uint = 32;

#[deriving(Clone)]
Expand Down Expand Up @@ -249,7 +249,61 @@ fn get_sec_keys(&mut self, index_addr:uint,mfd:uint, free_distance:&uint, mask:u
self.resize();
self.insert(key.clone(), data.clone())
}

pub fn insert_resize(&mut self, key:K, data:V,add_range:uint)-> bool{
if self.check_key(&key) {
return false;
}
let new_hash = self.hasher.hash(&key);
//println!("Insert hashes to: {}",new_hash)
let mask = self.raw_table.capacity()-1;
let index_addr = mask & (new_hash as uint);
//let mut info = self.get_insert_bucket_info(index_addr,mask);
//let mut info = self.raw_table.get_bucket(index_addr).hop_info.clone();
let mut free_distance = 0u;
let mut val = 1;
//for i in range(1, ADD_RANGE){
// if (info & 1) == 0 {
// break;
// }
// info = info >> 1;
// let b_info = self.raw_table.get_bucket((index_addr+i) & mask).hop_info.clone();
// info = info | b_info;
// //println!("info in insert: {}",info);
// free_distance += 1;
//}
for i in range(0,add_range){
if !self.raw_table.get_key_option((index_addr+i) & mask) {
break;
}
free_distance += 1;
}
//println!("free_distance in insert: {}",free_distance);
if free_distance < add_range {
while val != 0 {
if free_distance < VIRTUAL_BUCKET_CAPACITY {
//assert!(start_info & (1<<free_distance) != 0);
//println!("info:{}",info);
//println!("index address:{}",index_addr);
//println!("free distance at insert:{}",free_distance);
self.raw_table.get_bucket(index_addr).hop_info |= (1<<free_distance);
//println!("address:{}",(index_addr + free_distance) & mask);
self.raw_table.get_bucket((index_addr + free_distance) &
mask).hash = new_hash;
self.raw_table.insert_key((index_addr + free_distance) &
mask, key.clone());
self.raw_table.insert_val((index_addr + free_distance) &
mask, data.clone());
self.size += 1;
return true;

}
//println!("free distance before closer bucket:{}",free_distance);
self.find_closer_bucket(&mut free_distance, index_addr, &mut val, mask);
//println!("free distance after closer bucket:{}",free_distance);
}
}
false
}
pub fn resize(&mut self){
println!("Resize!!!");
let new_capacity = self.raw_table.capacity() << 1;
Expand Down
Binary file not shown.
Binary file modified test/benchmark-files/bench-60lookup-20insert-20remove
Binary file not shown.
18 changes: 12 additions & 6 deletions test/benchmark-files/bench-60lookup-20insert-20remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ mod raw_table;
#[path="../hashers.rs"]
mod hashers;

static HASHMAP_CAPACITY:uint = 32768;
//static HASHMAP_CAPACITY:uint = 32768;
//static HASHMAP_CAPACITY:uint = 4096;
static HASHMAP_CAPACITY:uint = 16384;
static OPERATIONS:uint = 500;
static AVG_SIZE:u64 = 10;

Expand Down Expand Up @@ -53,9 +55,11 @@ fn insert_lookup_remove_hopscotch(load:uint,ops:uint)->u64{

fn main(){
// datapoints are the loads 0.3,0.4,0.5,0.6,0.7,0.8,0.9 calculated with 131072
let data_point:Vec<uint> = vec!(9830,11469,13107,14746,16384,18022,19660,21299,22937,24576,26214);
let mut result_hopscotch:Vec<u64> = Vec::with_capacity(12);
let mut result_robin:Vec<u64> = Vec::with_capacity(12);
//let data_point:Vec<uint> = vec!(9830,11469,13107,14746,16384,18022,19660,21299,22937,24576,26214);
//let data_point:Vec<uint> = vec!(1229,1434,1638,1843,2048,2253,2458,2662,2867,3072,3277);
let data_point:Vec<uint> = vec!(4915,5734,6554,7373,8192,9011,9830,10649,11469,12288,13107);
let mut result_hopscotch:Vec<f64> = Vec::with_capacity(12);
let mut result_robin:Vec<f64> = Vec::with_capacity(12);
let load_factor = vec!(0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8);
let mut it = 0;
for i in data_point.iter(){
Expand All @@ -64,13 +68,15 @@ fn main(){
for _ in range(0,AVG_SIZE){
sum += insert_lookup_remove_hopscotch(*i,OPERATIONS);
}
let time_hopscotch = sum/AVG_SIZE;
let sum_milli = (sum as f64)/1000000f64;
let time_hopscotch = (OPERATIONS as f64)/(sum_milli/(AVG_SIZE as f64));
result_hopscotch.push(time_hopscotch);
let mut sum2 = 0u64;
for _ in range(0,AVG_SIZE){
sum2 += insert_lookup_remove_robin(*i,OPERATIONS);
}
let time_robin = sum2/AVG_SIZE;
let sum_milli2 = (sum2 as f64)/1000000f64;
let time_robin = (OPERATIONS as f64)/(sum_milli2/(AVG_SIZE as f64));
result_robin.push(time_robin);
it += 1;
}
Expand Down
Binary file modified test/benchmark-files/bench-90lookup-5insert-5remove
Binary file not shown.
28 changes: 17 additions & 11 deletions test/benchmark-files/bench-90lookup-5insert-5remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ mod raw_table;
#[path="../hashers.rs"]
mod hashers;

static HASHMAP_CAPACITY:uint = 32768;
static OPERATIONS:uint = 500;
//static HASHMAP_CAPACITY:uint = 32768;
//static HASHMAP_CAPACITY:uint = 4096;
static HASHMAP_CAPACITY:uint = 16384;
static OPERATIONS:u64 = 500;
static AVG_SIZE:u64 = 10;

fn insert_lookup_remove_robin(load:uint,ops:uint)->u64{
fn insert_lookup_remove_robin(load:uint,ops:u64)->u64{
let mut m = HashMap::with_capacity(HASHMAP_CAPACITY);
for i in range(1,load){
m.insert(i,i+1);
}
let start = precise_time_ns();
for i in range(load,load+ops){
for i in range(load,load+(ops as uint)){
m.insert(i,i+1);
for _ in range(0,18){
m.find(&i);
Expand All @@ -34,13 +36,13 @@ fn insert_lookup_remove_robin(load:uint,ops:uint)->u64{
let end = precise_time_ns();
end - start
}
fn insert_lookup_remove_hopscotch(load:uint,ops:uint)->u64{
fn insert_lookup_remove_hopscotch(load:uint,ops:u64)->u64{
let mut m = hopscotch::HashMap::with_capacity(HASHMAP_CAPACITY);
for i in range(1,load){
m.insert(i,i+1);
}
let start = precise_time_ns();
for i in range(load,load+ops){
for i in range(load,load+(ops as uint)){
m.insert(i,i+1);
for _ in range(0,18){
m.lookup(i);
Expand All @@ -53,9 +55,11 @@ fn insert_lookup_remove_hopscotch(load:uint,ops:uint)->u64{

fn main(){
// datapoints are the loads 0.3,0.4,0.5,0.6,0.7,0.8,0.9 calculated with 131072
let data_point:Vec<uint> = vec!(9830,11469,13107,14746,16384,18022,19660,21299,22937,24576,26214);
let mut result_hopscotch:Vec<u64> = Vec::with_capacity(12);
let mut result_robin:Vec<u64> = Vec::with_capacity(12);
//let data_point:Vec<uint> = vec!(9830,11469,13107,14746,16384,18022,19660,21299,22937,24576,26214);
//let data_point:Vec<uint> = vec!(1229,1434,1638,1843,2048,2253,2458,2662,2867,3072,3277);
let data_point:Vec<uint> = vec!(4915,5734,6554,7373,8192,9011,9830,10649,11469,12288,13107);
let mut result_hopscotch:Vec<f64> = Vec::with_capacity(12);
let mut result_robin:Vec<f64> = Vec::with_capacity(12);
let load_factor = vec!(0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8);
let mut it = 0;
for i in data_point.iter(){
Expand All @@ -64,13 +68,15 @@ fn main(){
for _ in range(0,AVG_SIZE){
sum += insert_lookup_remove_hopscotch(*i,OPERATIONS);
}
let time_hopscotch = sum/AVG_SIZE;
let sum_milli = (sum as f64)/1000000f64;
let time_hopscotch = (OPERATIONS as f64)/(sum_milli/(AVG_SIZE as f64));
result_hopscotch.push(time_hopscotch);
let mut sum2 = 0u64;
for _ in range(0,AVG_SIZE){
sum2 += insert_lookup_remove_robin(*i,OPERATIONS);
}
let time_robin = sum2/AVG_SIZE;
let sum_milli2 = (sum2 as f64)/1000000f64;
let time_robin = (OPERATIONS as f64)/(sum_milli2/(AVG_SIZE as f64));
result_robin.push(time_robin);
it += 1;
}
Expand Down
Binary file added test/benchmark-files/bench-resize-conditions80
Binary file not shown.
80 changes: 80 additions & 0 deletions test/benchmark-files/bench-resize-conditions80.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#![feature(default_type_params)]
extern crate rand;
extern crate time;
extern crate collections;

use collections::HashMap;
use time::precise_time_ns;
use std::io::File;

#[path="../../hashmap/mod.rs"]
mod hopscotch;
#[path="../../hashmap/raw_table/mod.rs"]
mod raw_table;
#[path="../hashers.rs"]
mod hashers;

fn resize_test(load:uint,table_size:uint,add_range:uint)->bool{
let mut m = hopscotch::HashMap::with_capacity(table_size);
for i in range(1,load){
if !m.insert_resize(i,i+1,add_range) {
return true;
}
}
false
}

fn main(){
let mut size_4096 = Vec::with_capacity(4);
let mut size_8192 = Vec::with_capacity(4);
let mut size_16384 = Vec::with_capacity(4);
let mut size_32768 = Vec::with_capacity(4);
let add_ranges = vec!(128,256,512);

for ar in add_ranges.iter(){
let mut res = 0;
for i in range(0,100){
if resize_test(3277,4096,*ar){
res += 1;
}
}
size_4096.push(res);
}
for ar in add_ranges.iter(){
let mut res = 0;
for i in range(0,100){
if resize_test(6554,8192,*ar){
res += 1;
}
}
size_8192.push(res);
}
for ar in add_ranges.iter(){
let mut res = 0;
for i in range(0,100){
if resize_test(13107,16384,*ar){
res += 1;
}
}
size_16384.push(res);
}
for ar in add_ranges.iter(){
let mut res = 0;
for i in range(0,100){
if resize_test(26214,32768,*ar){
res += 1;
}
}
size_32768.push(res);
}
let mut file = File::create(&Path::new("output-files/bench-resize-conditions80"));
for i in range(0u,3u){
let label = add_ranges.get(i).to_str().append(" ");
let s4096 = size_4096.get(i).to_str().append(" ");
let s8192 = size_8192.get(i).to_str().append(" ");
let s16384 = size_16384.get(i).to_str().append(" ");
let s32768 = size_32768.get(i).to_str().append("\n");
let line = label.into_bytes()+s4096.into_bytes()+s8192.into_bytes()+s16384.into_bytes()+s32768.into_bytes();
file.write(line.as_slice());
}
}
80 changes: 80 additions & 0 deletions test/benchmark-files/bench-resize-conditions80.rs~
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#![feature(default_type_params)]
extern crate rand;
extern crate time;
extern crate collections;

use collections::HashMap;
use time::precise_time_ns;
use std::io::File;

#[path="../../hashmap/mod.rs"]
mod hopscotch;
#[path="../../hashmap/raw_table/mod.rs"]
mod raw_table;
#[path="../hashers.rs"]
mod hashers;

fn resize_test(load:uint,table_size:uint,add_range:uint)->bool{
let mut m = hopscotch::HashMap::with_capacity(table_size);
for i in range(1,load){
if !m.insert_resize(i,i+1,add_range) {
return true;
}
}
false
}

fn main(){
let mut size_4096 = Vec::with_capacity(4);
let mut size_8192 = Vec::with_capacity(4);
let mut size_16384 = Vec::with_capacity(4);
let mut size_32768 = Vec::with_capacity(4);
let add_ranges = vec!(128,256,512);

for ar in add_ranges.iter(){
let mut res = 0;
for i in range(0,100){
if resize_test(3277,4096,*ar){
res += 1;
}
}
size_4096.push(res);
}
for ar in add_ranges.iter(){
let mut res = 0;
for i in range(0,100){
if resize_test(6554,8192,*ar){
res += 1;
}
}
size_8192.push(res);
}
for ar in add_ranges.iter(){
let mut res = 0;
for i in range(0,100){
if resize_test(13107,16384,*ar){
res += 1;
}
}
size_16384.push(res);
}
for ar in add_ranges.iter(){
let mut res = 0;
for i in range(0,100){
if resize_test(26214,32768,*ar){
res += 1;
}
}
size_32768.push(res);
}
let mut file = File::create(&Path::new("output-files/bench-resize-conditions80"));
for i in range(0u,3u){
let label = add_ranges.get(i).to_str().append(" ");
let s4096 = size_4096.get(i).to_str().append(" ");
let s8192 = size_8192.get(i).to_str().append(" ");
let s16384 = size_16384.get(i).to_str().append(" ");
let s32768 = size_32768.get(i).to_str().append("\n");
let line = label.into_bytes()+s4096.into_bytes()+s8192.into_bytes()+s16384.into_bytes()+s32768.into_bytes();
file.write(line.as_slice());
}
}
Binary file added test/benchmark-files/bench-resize-conditions85
Binary file not shown.
Loading

0 comments on commit 4053837

Please sign in to comment.