-
-
Notifications
You must be signed in to change notification settings - Fork 599
/
Copy pathidentifiers.rs
56 lines (44 loc) · 1.1 KB
/
identifiers.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
// Sonic
//
// Fast, lightweight and schema-less search backend
// Copyright: 2019, Valerian Saliou <[email protected]>
// License: Mozilla Public License v2.0 (MPL v2.0)
use std::hash::Hasher;
use twox_hash::XxHash32;
pub type StoreObjectIID = u32;
pub type StoreObjectOID<'a> = &'a str;
pub type StoreTermHashed = u32;
pub struct StoreTermHash;
pub enum StoreMetaKey {
IIDIncr,
}
pub enum StoreMetaValue {
IIDIncr(StoreObjectIID),
}
impl StoreMetaKey {
pub fn as_u32(&self) -> u32 {
match self {
StoreMetaKey::IIDIncr => 0,
}
}
}
impl StoreTermHash {
pub fn from(term: &str) -> StoreTermHashed {
let mut hasher = XxHash32::with_seed(0);
hasher.write(term.as_bytes());
hasher.finish() as u32
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_converts_meta_key_to_u32() {
assert_eq!(StoreMetaKey::IIDIncr.as_u32(), 0);
}
#[test]
fn it_hashes_term() {
assert_eq!(StoreTermHash::from("hash:1"), 3637660813);
assert_eq!(StoreTermHash::from("hash:2"), 3577985381);
}
}