diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:25 +0000 |
commit | 5363f350887b1e5b5dd21a86f88c8af9d7fea6da (patch) | |
tree | 35ca005eb6e0e9a1ba3bb5dbc033209ad445dc17 /vendor/litemap/examples | |
parent | Adding debian version 1.66.0+dfsg1-1. (diff) | |
download | rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.tar.xz rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.zip |
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/litemap/examples')
-rw-r--r-- | vendor/litemap/examples/language_names_hash_map.rs | 47 | ||||
-rw-r--r-- | vendor/litemap/examples/language_names_lite_map.rs | 47 |
2 files changed, 94 insertions, 0 deletions
diff --git a/vendor/litemap/examples/language_names_hash_map.rs b/vendor/litemap/examples/language_names_hash_map.rs new file mode 100644 index 000000000..d34af7665 --- /dev/null +++ b/vendor/litemap/examples/language_names_hash_map.rs @@ -0,0 +1,47 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +// LiteMap is intended as a small and low-memory drop-in replacement for HashMap. +// +// This example does not use LiteMap. The reader may compare this HashMap example to the +// LiteMap example to showcase analogous operations between HashMap and LiteMap. + +#![no_main] // https://github.com/unicode-org/icu4x/issues/395 + +icu_benchmark_macros::static_setup!(); + +use icu_locid::subtags::Language; +use icu_locid::subtags_language as language; +use std::collections::HashMap; + +const DATA: [(Language, &str); 11] = [ + (language!("ar"), "Arabic"), + (language!("bn"), "Bangla"), + (language!("ccp"), "Chakma"), + (language!("en"), "English"), + (language!("es"), "Spanish"), + (language!("fr"), "French"), + (language!("ja"), "Japanese"), + (language!("ru"), "Russian"), + (language!("sr"), "Serbian"), + (language!("th"), "Thai"), + (language!("tr"), "Turkish"), +]; + +#[no_mangle] +fn main(_argc: isize, _argv: *const *const u8) -> isize { + icu_benchmark_macros::main_setup!(); + + let mut map = HashMap::new(); + // https://github.com/rust-lang/rust/issues/62633 was declined :( + for (lang, name) in DATA.iter() { + map.insert(lang, name).ok_or(()).unwrap_err(); + } + + assert_eq!(11, map.len()); + assert_eq!(Some(&&"Thai"), map.get(&language!("th"))); + assert_eq!(None, map.get(&language!("de"))); + + 0 +} diff --git a/vendor/litemap/examples/language_names_lite_map.rs b/vendor/litemap/examples/language_names_lite_map.rs new file mode 100644 index 000000000..28b4ee807 --- /dev/null +++ b/vendor/litemap/examples/language_names_lite_map.rs @@ -0,0 +1,47 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +// LiteMap is intended as a small and low-memory drop-in replacement for HashMap. +// +// The reader may compare this LiteMap example with the HashMap example to see analogous +// operations between LiteMap and HashMap. + +#![no_main] // https://github.com/unicode-org/icu4x/issues/395 + +icu_benchmark_macros::static_setup!(); + +use icu_locid::subtags::Language; +use icu_locid::subtags_language as language; +use litemap::LiteMap; + +const DATA: [(Language, &str); 11] = [ + (language!("ar"), "Arabic"), + (language!("bn"), "Bangla"), + (language!("ccp"), "Chakma"), + (language!("en"), "English"), + (language!("es"), "Spanish"), + (language!("fr"), "French"), + (language!("ja"), "Japanese"), + (language!("ru"), "Russian"), + (language!("sr"), "Serbian"), + (language!("th"), "Thai"), + (language!("tr"), "Turkish"), +]; + +#[no_mangle] +fn main(_argc: isize, _argv: *const *const u8) -> isize { + icu_benchmark_macros::main_setup!(); + + let mut map = LiteMap::new_vec(); + // https://github.com/rust-lang/rust/issues/62633 was declined :( + for (lang, name) in DATA.iter() { + map.try_append(lang, name).ok_or(()).unwrap_err(); + } + + assert_eq!(11, map.len()); + assert_eq!(Some(&&"Thai"), map.get(&language!("th"))); + assert_eq!(None, map.get(&language!("de"))); + + 0 +} |