Skip to content

Commit f01f9ac

Browse files
Implement Readable/Writeable for HashSet
To be used in upcoming commits for MPP ID storage
1 parent 0659a75 commit f01f9ac

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lightning/src/util/ser.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,34 @@ impl<K, V> Readable for HashMap<K, V>
528528
}
529529
}
530530

531+
// HashSet
532+
impl<T> Writeable for HashSet<T>
533+
where T: Writeable + Eq + Hash
534+
{
535+
#[inline]
536+
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
537+
(self.len() as u16).write(w)?;
538+
for item in self.iter() {
539+
item.write(w)?;
540+
}
541+
Ok(())
542+
}
543+
}
544+
545+
impl<T> Readable for HashSet<T>
546+
where T: Readable + Eq + Hash
547+
{
548+
#[inline]
549+
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
550+
let len: u16 = Readable::read(r)?;
551+
let mut ret = HashSet::with_capacity(len as usize);
552+
for _ in 0..len {
553+
ret.insert(T::read(r)?);
554+
}
555+
Ok(ret)
556+
}
557+
}
558+
531559
// Vectors
532560
impl Writeable for Vec<u8> {
533561
#[inline]

0 commit comments

Comments
 (0)