Skip to content

Commit

Permalink
Get rid of max size
Browse files Browse the repository at this point in the history
It's so huge that no-one should ever reach it. A more accurate safety
net is a maximum iteration limit during PHF generation.
  • Loading branch information
sfackler committed Aug 17, 2014
1 parent 20dea1d commit 9fd8d24
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
12 changes: 0 additions & 12 deletions phf_mac/src/lib.rs
Expand Up @@ -204,12 +204,6 @@ fn parse_map(cx: &mut ExtCtxt, tts: &[TokenTree]) -> Option<Vec<Entry>> {
}
}

if entries.len() > shared::MAX_SIZE {
cx.span_err(parser.span, format!("maps with more than {} entries are not supported",
shared::MAX_SIZE).as_slice());
return None;
}

if bad {
return None;
}
Expand Down Expand Up @@ -242,12 +236,6 @@ fn parse_set(cx: &mut ExtCtxt, tts: &[TokenTree]) -> Option<Vec<Entry>> {
}
}

if entries.len() > shared::MAX_SIZE {
cx.span_err(parser.span, format!("maps with more than {} entries are not supported",
shared::MAX_SIZE).as_slice());
return None;
}

if bad {
return None;
}
Expand Down
11 changes: 4 additions & 7 deletions shared/mod.rs
@@ -1,20 +1,17 @@
use std::hash::{Hash, Hasher, Writer};
use std::hash::sip::{SipHasher, SipState};

static LOG_MAX_SIZE: uint = 21;

pub static MAX_SIZE: uint = 1 << LOG_MAX_SIZE;

pub fn displace(f1: u32, f2: u32, d1: u32, d2: u32) -> u32 {
d2 + f1 * d1 + f2
}

fn split(hash: u64) -> (u32, u32, u32) {
let mask = (MAX_SIZE - 1) as u64;
let bits = 21;
let mask = (1 << bits) - 1;

((hash & mask) as u32,
((hash >> LOG_MAX_SIZE) & mask) as u32,
((hash >> (2 * LOG_MAX_SIZE)) & mask) as u32)
((hash >> bits) & mask) as u32,
((hash >> (2 * bits)) & mask) as u32)
}

/// A trait implemented by types which can be used in PHF data structures
Expand Down

0 comments on commit 9fd8d24

Please sign in to comment.