precomputed_map/
macros.rs1#[macro_export]
2macro_rules! define {
3 ( $vis:vis const $name:ident: &[u8; $n:expr] = include $path:literal ) => {
4 $vis struct $name;
5
6 impl $crate::store::AsData for $name {
7 type Data = [u8; $n];
8
9 fn as_data() -> &'static Self::Data {
10 const VALUE: &[u8; $n] = include_bytes!($path);
11 VALUE
12 }
13 }
14 };
15 ( $vis:vis const $name:ident: &[u8 align $unit:ty; $n:expr] = include $path:literal ) => {
16 $vis struct $name;
17
18 impl $crate::store::AsData for $name {
19 type Data = [u8; $n];
20
21 fn as_data() -> &'static Self::Data {
22 static VALUE: &$crate::aligned::AlignedBytes<$n, $unit> = &$crate::aligned::AlignedBytes {
23 align: [],
24 bytes: *include_bytes!($path)
25 };
26
27 &VALUE.bytes
28 }
29 }
30 };
31 ( $vis:vis const searchable $name:ident: &[$unit:ty; $n:expr] = $v:expr ) => {
32 $crate::define!($vis const $name: &[$unit; $n] = $v );
33
34 impl $crate::store::Searchable for $name {
35 fn search<Q>(query: &Q)
36 -> Option<Self::Value>
37 where
38 Q: $crate::equivalent::Comparable<Self::Key> + ?Sized
39 {
40 let values = $name.as_slice();
41 values.binary_search_by(|k| query.compare(k).reverse()).ok()
42 }
43 }
44 };
45 ( $vis:vis const $name:ident: &[$unit:ty; $n:expr] = $v:expr ) => {
46 $vis struct $name;
47
48 impl $name {
49 fn as_slice(&self) -> &[$unit] {
50 static VALUE: &[$unit; $n] = $v;
51 VALUE
52 }
53 }
54
55 impl $crate::store::AccessSeq for $name {
56 type Item = $unit;
57 const LEN: usize = $n;
58
59 fn index(index: usize) -> Option<Self::Item> {
60 $name.as_slice().get(index).copied()
61 }
62 }
63 }
64}