forked from cloudflare/trie-hard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
62 lines (58 loc) · 1.53 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::{
collections::HashSet,
env,
fs::File,
io::{BufWriter, Write as _},
path::Path,
};
const HEADERS: &str = include_str!("data/headers.txt");
const SUN_RISING: &str = include_str!("data/sun-rising.txt");
fn main() {
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("codegen.rs");
let mut file = BufWriter::new(File::create(path).unwrap());
let mut headers_set = phf_codegen::Set::<&str>::new();
let headers_rev: Vec<_> = HEADERS
.lines()
.collect::<HashSet<_>>()
.into_iter()
.map(|s| s.chars().rev().collect::<String>())
.collect();
for s in &headers_rev {
headers_set.entry(s);
}
write!(
&mut file,
"static HEADERS_PHF: phf::Set<&str> = {};",
headers_set.build()
)
.unwrap();
let mut small_set = phf_codegen::Set::<&str>::new();
for s in SUN_RISING
.split(|c: char| c.is_whitespace())
.collect::<HashSet<_>>()
.into_iter()
{
small_set.entry(s);
}
write!(
&mut file,
"static SMALL_PHF: phf::Set<&str> = {};",
small_set.build()
)
.unwrap();
let mut big_set = phf_codegen::Set::<&str>::new();
const OW_1984: &str = include_str!("data/1984.txt");
for s in OW_1984
.split(|c: char| c.is_whitespace())
.collect::<HashSet<_>>()
.into_iter()
{
big_set.entry(s);
}
write!(
&mut file,
"static BIG_PHF: phf::Set<&str> = {};",
big_set.build()
)
.unwrap();
}