Repository: qdrant/qdrant
File: lib/segment/src/index/field_index/immutable_point_to_values.rs (Rust)

Code before:
            .iter()
            .filter(|values| values.len() != 1)
            .fold(0, |acc, values| acc + values.len());
        let mut values_container = Vec::with_capacity(container_capacity);

        for values in src {
            if values.len() == 1 {
                // Single value — store inline, skip container entirely.
                let value = values.into_iter().next().expect("length checked above");
                point_entries.push(PointValueEntry::Single(value));
            } else {
                // Zero or multiple values — store in container, record slice location.
                let start = values_container.len() as u32;
                let count = values.len() as u32;
                point_entries.push(PointValueEntry::Slice { start, count });
                values_container.extend(values);
            }
        }

        Self {
            point_entries,
            values_container,
        }
    }

    pub fn check_values_any(&self, idx: PointOffsetType, check_fn: impl FnMut(&N) -> bool) -> bool {
        let Some(entry) = self.point_entries.get(idx as usize) else {
            return false;
        };

        match entry {
            PointValueEntry::Single(v) => std::iter::once(v).any(check_fn),
            PointValueEntry::Slice { start, count } => {
                let range = *start as usize..(*start + *count) as usize;
                if let Some(values) = self.values_container.get(range) {
                    values.iter().any(check_fn)
                } else {
                    false
                }
            }
        }
    }

    pub fn get_values(&self, idx: PointOffsetType) -> Option<impl Iterator<Item = &N> + '_> {
        let entry = self.point_entries.get(idx as usize)?;
        match entry {
            PointValueEntry::Single(v) => Some(std::slice::from_ref(v).iter()),
            PointValueEntry::Slice { start, count } => {
                let range = *start as usize..(*start + *count) as usize;
                Some(self.values_container[range].iter())
            }

Review comment (suggestion):
I think it'd be worth to handle the case of 0 values explicitly:

```suggestion
        for values in src {
            match values.len() {
                // Zero values — store inline
                0 => {
                    point_entries.push(PointValueEntry::default());
                }
                // Single value — store inline, skip container entirely
                1 => {
                    let value = values.into_iter().next().expect("length checked above");
                    point_entries.push(PointValueEntry::Single(value));
                }
                // Multiple values — store in container, record slice location
                2.. => {
                    let start = values_container.len() as u32;
                    let count = values.len() as u32;
                    point_entries.push(PointValueEntry::Slice { start, count });
                    values_container.extend(values);
                }
            }
        }
```

While business logic remains the same, we now have a simpler branch for this case that always uses `start:0, count:0`.

Code after:
            .iter()
            .map(|values| values.len())
            .filter(|&size| size > 1)
            .sum();
        let mut values_container = Vec::with_capacity(container_capacity);

        for values in src {
            match values.len() {
                // Zero values — store inline
                0 => {
                    point_entries.push(PointValueEntry::default());
                }
                // Single value — store inline, skip container entirely
                1 => {
                    let value = values.into_iter().next().expect("length checked above");
                    point_entries.push(PointValueEntry::Single(value));
                }
                // Multiple values — store in container, record slice location
                2.. => {
                    let start = values_container.len() as u32;
                    let count = values.len() as u32;
                    point_entries.push(PointValueEntry::Slice { start, count });
                    values_container.extend(values);
                }
            }
        }

        Self {
            point_entries,
            values_container,
        }
    }

    pub fn check_values_any(
        &self,
        idx: PointOffsetType,
        mut check_fn: impl FnMut(&N) -> bool,
    ) -> bool {
        let Some(entry) = self.point_entries.get(idx as usize) else {
            return false;
        };

        match entry {
            PointValueEntry::Single(v) => check_fn(v),
            PointValueEntry::Slice { start, count } => {
                let range = *start as usize..(*start + *count) as usize;
                if let Some(values) = self.values_container.get(range) {
                    values.iter().any(check_fn)
                } else {
                    false
                }