Debian Codegraph @

third_party/rust/litemap/examples/language_names_lite_map.rs

raw
1 // This file is part of ICU4X. For terms of use, please see the file
2 // called LICENSE at the top level of the ICU4X source tree
3 // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5 // LiteMap is intended as a small and low-memory drop-in replacement for HashMap.
6 //
7 // The reader may compare this LiteMap example with the HashMap example to see analogous
8 // operations between LiteMap and HashMap.
9
10 #![no_main] // https://github.com/unicode-org/icu4x/issues/395
11
12 icu_benchmark_macros::static_setup!();
13
14 use icu_locid::subtags::{language, Language};
15 use litemap::LiteMap;
16
17 const DATA: [(Language, &str); 11] = [
18 (language!("ar"), "Arabic"),
19 (language!("bn"), "Bangla"),
20 (language!("ccp"), "Chakma"),
21 (language!("en"), "English"),
22 (language!("es"), "Spanish"),
23 (language!("fr"), "French"),
24 (language!("ja"), "Japanese"),
25 (language!("ru"), "Russian"),
26 (language!("sr"), "Serbian"),
27 (language!("th"), "Thai"),
28 (language!("tr"), "Turkish"),
29 ];
30
31 #[no_mangle]
32 fn main(_argc: isize, _argv: *const *const u8) -> isize {
33 icu_benchmark_macros::main_setup!();
34
35 let mut map = LiteMap::new_vec();
36 // https://github.com/rust-lang/rust/issues/62633 was declined :(
37 for (lang, name) in DATA.iter() {
38 map.try_append(lang, name).ok_or(()).unwrap_err();
39 }
40
41 assert_eq!(11, map.len());
42 assert_eq!(Some(&&"Thai"), map.get(&language!("th")));
43 assert_eq!(None, map.get(&language!("de")));
44
45 0
46 }