From 925d039b2e079cd791e4849e736b8d29ec751d69 Mon Sep 17 00:00:00 2001 From: ia7ck <23146842+ia7ck@users.noreply.github.com> Date: Wed, 12 Nov 2025 23:37:36 +0900 Subject: [PATCH 1/3] new(Vec) --- libs/zarts/src/lib.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libs/zarts/src/lib.rs b/libs/zarts/src/lib.rs index 9470ac79..8e321e92 100644 --- a/libs/zarts/src/lib.rs +++ b/libs/zarts/src/lib.rs @@ -50,7 +50,7 @@ where T: Ord, { fn from_iter>(iter: I) -> Self { - Self::new(iter) + Self::new(iter.into_iter().collect()) } } @@ -58,8 +58,7 @@ impl SortedSeq where T: Ord, { - pub fn new(values: impl IntoIterator) -> Self { - let mut values = values.into_iter().collect::>(); + pub fn new(mut values: Vec) -> Self { values.sort_unstable(); values.dedup(); Self(values) @@ -116,7 +115,7 @@ mod tests { #[test] fn index_test() { - let seq = SortedSeq::new([4, 4, 2, 5, 2, 9]); + let seq = SortedSeq::new(vec![4, 4, 2, 5, 2, 9]); // 2, 4, 5, 9 assert_eq!(seq.at(0), &2); assert_eq!(seq.at(1), &4); From c3eea6db844646c361167aa4ee4f799e4383983d Mon Sep 17 00:00:00 2001 From: ia7ck <23146842+ia7ck@users.noreply.github.com> Date: Wed, 12 Nov 2025 23:38:25 +0900 Subject: [PATCH 2/3] len, is_empty --- libs/zarts/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/zarts/src/lib.rs b/libs/zarts/src/lib.rs index 8e321e92..99ff3d47 100644 --- a/libs/zarts/src/lib.rs +++ b/libs/zarts/src/lib.rs @@ -77,9 +77,13 @@ where } /// 集合のサイズを返します - pub fn size(&self) -> usize { + pub fn len(&self) -> usize { self.0.len() } + + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } } impl Index for SortedSeq { From 5ae53cf57ff28138a0dfed18330167e4f318006c Mon Sep 17 00:00:00 2001 From: ia7ck <23146842+ia7ck@users.noreply.github.com> Date: Wed, 12 Nov 2025 23:39:08 +0900 Subject: [PATCH 3/3] move --- libs/zarts/src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/zarts/src/lib.rs b/libs/zarts/src/lib.rs index 99ff3d47..c72e915e 100644 --- a/libs/zarts/src/lib.rs +++ b/libs/zarts/src/lib.rs @@ -45,15 +45,6 @@ use std::{ /// pub struct SortedSeq(Vec); -impl FromIterator for SortedSeq -where - T: Ord, -{ - fn from_iter>(iter: I) -> Self { - Self::new(iter.into_iter().collect()) - } -} - impl SortedSeq where T: Ord, @@ -86,6 +77,15 @@ where } } +impl FromIterator for SortedSeq +where + T: Ord, +{ + fn from_iter>(iter: I) -> Self { + Self::new(iter.into_iter().collect()) + } +} + impl Index for SortedSeq { type Output = T;