11// SPDX-License-Identifier: Apache-2.0
22// SPDX-FileCopyrightText: Copyright the Vortex contributors
33
4+ //! Filter implementations for vector types.
5+ //!
6+ //! This module provides [`Filter`] trait implementations for all vector types with three distinct
7+ //! patterns optimized for different ownership scenarios:
8+ //!
9+ //! ### 1. Reference Implementation (`&Vector`)
10+ //!
11+ //! Filters by allocating new memory and copying selected elements. Returns a new owned vector.
12+ //! This is the base implementation that all other patterns can fall back to.
13+ //!
14+ //! ### 2. Mutable Reference Implementation (`&mut VectorMut`)
15+ //!
16+ //! Filters in-place when exclusive mutable access is available, avoiding allocation. Returns `()`
17+ //! as the vector is modified directly. This is the most efficient when you already have a mutable
18+ //! vector (it is only less efficient if the vector is very small and the output vector is already
19+ //! in the L1 cache).
20+ //!
21+ //! ### 3. Owned Implementation (`Vector`)
22+ //!
23+ //! Uses [`VectorOps::try_into_mut`] to check for exclusive ownership. If successful, performs
24+ //! in-place filtering via the mutable implementation and calls [`VectorMutOps::freeze`] to convert
25+ //! back. Otherwise, delegates to the reference implementation and makes an allocation.
26+ //!
27+ //! ## Breaking Recursive Trait Bounds
28+ //!
29+ //! To allow all vector types to implement filter generically over a "mask" type `M`, we must break
30+ //! the recursive trait bounds (e.g. from [`StructVector`] requiring `Vector: Filter<M>` for its
31+ //! fields) by manually implementing [`Filter`] for [`Vector`] and [`VectorMut`] for each concrete
32+ //! mask type in this file.
33+
434use vortex_buffer:: BitView ;
535use vortex_mask:: Mask ;
636use vortex_vector:: { Vector , VectorMut , match_each_vector, match_each_vector_mut} ;
@@ -18,9 +48,8 @@ mod primitive;
1848mod pvector;
1949mod struct_;
2050
21- // To allow all vector types to implement filter generically over `M`, we must break the recursive
22- // trait bounds (e.g. from StructVector requiring Vector: Filter<M> for its fields) by manually
23- // implementing Filter for Vector and VectorMut for each concrete mask type here.
51+ // We manually implement Filter for Vector and VectorMut for each concrete mask type here to break
52+ // the recursive trait bounds.
2453
2554impl Filter < Mask > for & Vector {
2655 type Output = Vector ;
0 commit comments