From 7778adfd6089ad60574c79cfaf87839ca2680c29 Mon Sep 17 00:00:00 2001 From: Tim Fennis Date: Thu, 4 Dec 2025 06:38:19 +0100 Subject: [PATCH] Added is_empty function for maps --- ndc_lib/src/stdlib/hash_map.rs | 5 +++++ tests/programs/007_map_and_set/023_map_is_empty.ndct | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/programs/007_map_and_set/023_map_is_empty.ndct diff --git a/ndc_lib/src/stdlib/hash_map.rs b/ndc_lib/src/stdlib/hash_map.rs index 9ecb1bb5..c7afbdf8 100644 --- a/ndc_lib/src/stdlib/hash_map.rs +++ b/ndc_lib/src/stdlib/hash_map.rs @@ -48,6 +48,11 @@ mod inner { map.insert(key, Value::unit()); } + /// Returns true if the map or set contains no elements. + pub fn is_empty(map: &HashMap) -> bool { + map.is_empty() + } + #[function(name = "&=")] pub fn intersect_assign(lhs: &mut MapRepr, rhs: &mut MapRepr) { let left_map: &mut HashMap = &mut lhs diff --git a/tests/programs/007_map_and_set/023_map_is_empty.ndct b/tests/programs/007_map_and_set/023_map_is_empty.ndct new file mode 100644 index 00000000..ee59f620 --- /dev/null +++ b/tests/programs/007_map_and_set/023_map_is_empty.ndct @@ -0,0 +1,6 @@ +--PROGRAM-- +assert_eq(%{}.is_empty(), true); +assert_eq(%{1,2,3}.is_empty(), false); +print("ok"); +--EXPECT-- +ok \ No newline at end of file