diff --git a/crates/primitives/src/integer_list.rs b/crates/primitives/src/integer_list.rs index f4dd5a6ae1..fe65ad588c 100644 --- a/crates/primitives/src/integer_list.rs +++ b/crates/primitives/src/integer_list.rs @@ -30,11 +30,26 @@ impl IntegerList { /// Creates an IntegerList from a list of integers. `usize` is safe to use since /// [`sucds::EliasFano`] restricts its compilation to 64bits. /// - /// List should be pre-sorted and not empty. + /// # Returns + /// + /// Returns an error if the list is empty or not pre-sorted. pub fn new>(list: T) -> Result { Ok(Self(EliasFano::from_ints(list.as_ref()).map_err(|_| EliasFanoError::InvalidInput)?)) } + // Creates an IntegerList from a pre-sorted list of integers. `usize` is safe to use since + /// [`sucds::EliasFano`] restricts its compilation to 64bits. + /// + /// # Panics + /// + /// Panics if the list is empty or not pre-sorted. + pub fn new_pre_sorted>(list: T) -> Self { + Self( + EliasFano::from_ints(list.as_ref()) + .expect("IntegerList must be pre-sorted and non-empty."), + ) + } + /// Serializes a [`IntegerList`] into a sequence of bytes. pub fn to_bytes(&self) -> Vec { let mut vec = Vec::with_capacity(self.0.size_in_bytes());