Skip to content

Commit

Permalink
Fix for upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Jan 3, 2015
1 parent 4f5902c commit 2b4863f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion phf/src/lib.rs
Expand Up @@ -4,7 +4,7 @@
//! literals, or any of the fixed-size integral types.
#![doc(html_root_url="https://sfackler.github.io/doc")]
#![warn(missing_docs)]
#![feature(macro_rules, phase, globs)]
#![feature(macro_rules, phase, globs, old_orphan_check)]
#![no_std]

#[phase(plugin, link)]
Expand Down
1 change: 1 addition & 0 deletions phf/src/map.rs
@@ -1,6 +1,7 @@
//! An immutable map constructed at compile time.
use core::prelude::*;
use core::borrow::BorrowFrom;
use core::ops::Index;
use core::slice;
use core::fmt;
use PhfHash;
Expand Down
2 changes: 2 additions & 0 deletions phf/src/ordered_map.rs
@@ -1,6 +1,8 @@
//! An order-preserving immutable map constructed at compile time.
use core::prelude::*;
use core::borrow::BorrowFrom;
use core::iter::RandomAccessIterator;
use core::ops::Index;
use core::fmt;
use core::slice;

Expand Down
1 change: 1 addition & 0 deletions phf/src/ordered_set.rs
@@ -1,6 +1,7 @@
//! An order-preserving immutable set constructed at compile time.
use core::prelude::*;
use core::borrow::BorrowFrom;
use core::iter::RandomAccessIterator;
use core::fmt;
use ordered_map;
use {PhfHash, OrderedMap};
Expand Down
7 changes: 5 additions & 2 deletions phf/tests/test.rs
Expand Up @@ -145,15 +145,15 @@ mod map {

#[test]
fn test_array_vals() {
static MAP: phf::Map<&'static str, [u8, ..3]> = phf_map!(
static MAP: phf::Map<&'static str, [u8; 3]> = phf_map!(
"a" => [0u8, 1, 2],
);
assert_eq!(Some(&[0u8, 1, 2]), MAP.get(&("a")));
}

#[test]
fn test_array_keys() {
static MAP: phf::Map<[u8, ..2], int> = phf_map!(
static MAP: phf::Map<[u8; 2], int> = phf_map!(
[0u8, 1] => 0,
[2, 3u8] => 1,
[4, 5] => 2,
Expand Down Expand Up @@ -271,6 +271,8 @@ mod set {
}

mod ordered_map {
use std::iter::RandomAccessIterator;

use phf;

#[allow(dead_code)]
Expand Down Expand Up @@ -372,6 +374,7 @@ mod ordered_map {
}

mod ordered_set {
use std::iter::RandomAccessIterator;
use phf;

#[allow(dead_code)]
Expand Down
4 changes: 2 additions & 2 deletions phf_mac/src/lib.rs
Expand Up @@ -2,7 +2,7 @@
//!
//! See the documentation for the `phf` crate for more details.
#![doc(html_root_url="http://sfackler.github.io/doc")]
#![feature(plugin_registrar, quote, default_type_params, macro_rules)]
#![feature(plugin_registrar, quote, default_type_params, macro_rules, old_orphan_check)]
#![allow(unknown_features)]

extern crate rand;
Expand All @@ -13,7 +13,7 @@ extern crate phf_shared;

use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use syntax::ast::{mod, TokenTree, LitStr, LitBinary, LitByte, LitChar, Expr, ExprLit, ExprVec};
use syntax::ast::{self, TokenTree, LitStr, LitBinary, LitByte, LitChar, Expr, ExprLit, ExprVec};
use syntax::codemap::{Span, Spanned};
use syntax::ext::base::{DummyResult,
ExtCtxt,
Expand Down
20 changes: 11 additions & 9 deletions phf_mac/src/util.rs
@@ -1,7 +1,7 @@
use std::os;
use std::rc::Rc;
use std::hash;
use std::hash::Hash;
use std::hash::{self, Hash};
use std::iter::repeat;

use syntax::ast::Expr;
use syntax::codemap::Span;
Expand All @@ -11,15 +11,15 @@ use syntax::parse::token::InternedString;
use syntax::ptr::P;
use rand::{Rng, SeedableRng, XorShiftRng};

use phf_shared::{mod, PhfHash};
use phf_shared::{self, PhfHash};

use time;

const DEFAULT_LAMBDA: uint = 5;

const FIXED_SEED: [u32, ..4] = [3141592653, 589793238, 462643383, 2795028841];
const FIXED_SEED: [u32; 4] = [3141592653, 589793238, 462643383, 2795028841];

#[deriving(PartialEq, Eq, Clone)]
#[derive(PartialEq, Eq, Clone)]
pub enum Key {
Str(InternedString),
Binary(Rc<Vec<u8>>),
Expand Down Expand Up @@ -130,7 +130,9 @@ pub fn try_generate_hash(entries: &[Entry], rng: &mut XorShiftRng) -> Option<Has
}).collect();

let buckets_len = (entries.len() + DEFAULT_LAMBDA - 1) / DEFAULT_LAMBDA;
let mut buckets = Vec::from_fn(buckets_len, |i| Bucket { idx: i, keys: vec![] });
let mut buckets = range(0, buckets_len)
.map(|i| Bucket { idx: i, keys: vec![] })
.collect::<Vec<_>>();

for (i, hash) in hashes.iter().enumerate() {
buckets[(hash.g % (buckets_len as u32)) as uint].keys.push(i);
Expand All @@ -140,8 +142,8 @@ pub fn try_generate_hash(entries: &[Entry], rng: &mut XorShiftRng) -> Option<Has
buckets.sort_by(|a, b| a.keys.len().cmp(&b.keys.len()).reverse());

let table_len = entries.len();
let mut map = Vec::from_elem(table_len, None);
let mut disps = Vec::from_elem(buckets_len, (0u32, 0u32));
let mut map = repeat(None).take(table_len).collect::<Vec<_>>();
let mut disps = repeat((0u32, 0u32)).take(buckets_len).collect::<Vec<_>>();

// store whether an element from the bucket being placed is
// located at a certain position, to allow for efficient overlap
Expand All @@ -150,7 +152,7 @@ pub fn try_generate_hash(entries: &[Entry], rng: &mut XorShiftRng) -> Option<Has
// if this is legitimately full by checking that the generations
// are equal. (A u64 is far too large to overflow in a reasonable
// time for current hardware.)
let mut try_map = Vec::from_elem(table_len, 0u64);
let mut try_map = repeat(0u64).take(table_len).collect::<Vec<_>>();
let mut generation = 0u64;

// the actual values corresponding to the markers above, as
Expand Down
4 changes: 2 additions & 2 deletions phf_shared/src/lib.rs
Expand Up @@ -5,7 +5,7 @@ extern crate core;
use core::slice::AsSlice;
use core::str::StrExt;
use core::hash::Writer;
use core::hash::sip::{mod, SipState};
use core::hash::sip::{self, SipState};
use core::kinds::Sized;

#[inline]
Expand Down Expand Up @@ -84,7 +84,7 @@ sip_impl!(bool);

macro_rules! array_impl(
($t:ty, $n:expr) => (
impl PhfHash for [$t, ..$n] {
impl PhfHash for [$t; $n] {
#[inline]
fn phf_hash(&self, seed: u64) -> (u32, u32, u32) {
split(sip::hash_with_keys(seed, 0, self.as_slice()))
Expand Down

0 comments on commit 2b4863f

Please sign in to comment.