Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 919 Bytes

README.md

File metadata and controls

38 lines (28 loc) · 919 Bytes

Rust-PHF

Build Status

Rust-PHF is a library to generate efficient lookup tables at compile time using perfect hash functions.

It currently uses the CHD algorithm and can generate a 100,000 entry map in roughly .4 seconds.

Documentation is available at https://sfackler.github.io/doc/phf

Example

#![feature(phase)]

#[phase(plugin)]
extern crate phf_mac;
extern crate phf;

use phf::PhfMap;

static KEYWORDS: PhfMap<&'static str, Keyword> = phf_map! {
    "loop" => LOOP,
    "continue" => CONTINUE,
    "break" => BREAK,
    "fn" => FN,
    "extern" => EXTERN,
};

pub fn parse_keyword(keyword: &str) -> Option<Keyword> {
    KEYWORDS.find_equiv(keyword).map(|t| t.clone())
}