Skip to content

Commit

Permalink
Make publishable on crates.io
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Nov 27, 2014
1 parent 6e3a54d commit 4ad2bb2
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 16 deletions.
6 changes: 4 additions & 2 deletions phf/Cargo.toml
Expand Up @@ -10,8 +10,10 @@ name = "phf"
path = "src/lib.rs"
test = false

[dependencies]
xxhash = "*"
[dependencies.phf_shared]
path = "../phf_shared"
version = "0.0.1"

[dev_dependencies.phf_mac]
path = "../phf_mac"
version = "0.0.1"
5 changes: 2 additions & 3 deletions phf/src/lib.rs
Expand Up @@ -9,8 +9,9 @@

#[phase(plugin, link)]
extern crate core;
extern crate phf_shared;

pub use shared::PhfHash;
pub use phf_shared::PhfHash;
#[doc(inline)]
pub use map::Map;
#[doc(inline)]
Expand All @@ -20,8 +21,6 @@ pub use ordered_map::OrderedMap;
#[doc(inline)]
pub use ordered_set::OrderedSet;

#[path="../../shared/mod.rs"]
mod shared;
pub mod map;
pub mod set;
pub mod ordered_map;
Expand Down
6 changes: 3 additions & 3 deletions phf/src/map.rs
Expand Up @@ -4,8 +4,8 @@ use core::borrow::BorrowFrom;
use core::iter;
use core::slice;
use core::fmt;
use shared;
use shared::PhfHash;
use PhfHash;
use phf_shared;

/// An immutable map constructed at compile time.
///
Expand Down Expand Up @@ -94,7 +94,7 @@ impl<K, V> Map<K, V> {
where T: Eq + PhfHash + BorrowFrom<K> {
let (g, f1, f2) = key.phf_hash(self.key);
let (d1, d2) = self.disps[(g % (self.disps.len() as u32)) as uint];
let entry = &self.entries[(shared::displace(f1, f2, d1, d2) % (self.entries.len() as u32))
let entry = &self.entries[(phf_shared::displace(f1, f2, d1, d2) % (self.entries.len() as u32))
as uint];
if BorrowFrom::borrow_from(&entry.0) == key {
Some((&entry.0, &entry.1))
Expand Down
4 changes: 2 additions & 2 deletions phf/src/ordered_map.rs
Expand Up @@ -6,7 +6,7 @@ use core::slice;
use core::iter;

use PhfHash;
use shared;
use phf_shared;

/// An order-preserving immutable map constructed at compile time.
///
Expand Down Expand Up @@ -112,7 +112,7 @@ impl<K, V> OrderedMap<K, V> {
where T: Eq + PhfHash + BorrowFrom<K> {
let (g, f1, f2) = key.phf_hash(self.key);
let (d1, d2) = self.disps[(g % (self.disps.len() as u32)) as uint];
let idx = self.idxs[(shared::displace(f1, f2, d1, d2) % (self.idxs.len() as u32)) as uint];
let idx = self.idxs[(phf_shared::displace(f1, f2, d1, d2) % (self.idxs.len() as u32)) as uint];
let entry = &self.entries[idx];

if BorrowFrom::borrow_from(&entry.0) == key {
Expand Down
2 changes: 1 addition & 1 deletion phf/src/set.rs
Expand Up @@ -3,7 +3,7 @@ use core::prelude::*;
use core::borrow::BorrowFrom;
use core::fmt;

use shared::PhfHash;
use PhfHash;
use map;
use Map;

Expand Down
5 changes: 4 additions & 1 deletion phf_mac/Cargo.toml
Expand Up @@ -13,6 +13,9 @@ path = "src/lib.rs"
plugin = true
test = false

[dependencies.phf_shared]
path = "../phf_shared"
version = "0.0.1"

[dependencies]
xxhash = "*"
time = "*"
3 changes: 1 addition & 2 deletions phf_mac/src/lib.rs
Expand Up @@ -10,6 +10,7 @@ extern crate rand;
extern crate syntax;
extern crate time;
extern crate rustc;
extern crate phf_shared;

use std::collections::HashMap;
use std::collections::hash_map::{Occupied, Vacant};
Expand All @@ -27,8 +28,6 @@ use rustc::plugin::Registry;
use util::{Entry, Key};
use util::{generate_hash, create_map, create_set, create_ordered_map, create_ordered_set};

#[path="../../shared/mod.rs"]
mod shared;
pub mod util;

#[plugin_registrar]
Expand Down
4 changes: 2 additions & 2 deletions phf_mac/src/util.rs
Expand Up @@ -11,7 +11,7 @@ use syntax::parse::token::InternedString;
use syntax::ptr::P;
use rand::{Rng, SeedableRng, XorShiftRng};

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

use time;

Expand Down Expand Up @@ -165,7 +165,7 @@ pub fn try_generate_hash(entries: &[Entry], rng: &mut XorShiftRng) -> Option<Has
generation += 1;

for &key in bucket.keys.iter() {
let idx = (::shared::displace(hashes[key].f1, hashes[key].f2, d1, d2)
let idx = (phf_shared::displace(hashes[key].f1, hashes[key].f2, d1, d2)
% (table_len as u32)) as uint;
if map[idx].is_some() || try_map[idx] == generation {
continue 'disps;
Expand Down
14 changes: 14 additions & 0 deletions phf_shared/Cargo.toml
@@ -0,0 +1,14 @@
[package]
name = "phf_shared"
authors = ["Steven Fackler <sfackler@gmail.com>"]
version = "0.0.1"
license = "MIT"
description = "Support code shared by phf and phf_mac"

[lib]
name = "phf_shared"
path = "src/lib.rs"
test = false

[dependencies]
xxhash = "*"
2 changes: 2 additions & 0 deletions shared/mod.rs → phf_shared/src/lib.rs
@@ -1,3 +1,5 @@
#![feature(macro_rules)]

extern crate xxhash;
extern crate core;

Expand Down

0 comments on commit 4ad2bb2

Please sign in to comment.