vortex_vector/bool/mod.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4//! Definition and implementation of [`BoolVector`] and [`BoolVectorMut`].
5//!
6//! # Examples
7//!
8//! ## Extending and appending
9//!
10//! ```
11//! use vortex_vector::bool::BoolVectorMut;
12//! use vortex_vector::VectorMutOps;
13//!
14//! let mut vec1 = BoolVectorMut::from_iter([true, false].map(Some));
15//! let vec2 = BoolVectorMut::from_iter([true, true].map(Some)).freeze();
16//!
17//! // Extend from another vector.
18//! vec1.extend_from_vector(&vec2);
19//! assert_eq!(vec1.len(), 4);
20//!
21//! // Append null values.
22//! vec1.append_nulls(2);
23//! assert_eq!(vec1.len(), 6);
24//! ```
25//!
26//! ## Splitting and unsplitting
27//!
28//! ```
29//! use vortex_vector::bool::BoolVectorMut;
30//! use vortex_vector::VectorMutOps;
31//!
32//! let mut vec = BoolVectorMut::from_iter([true, false, true, false, true].map(Some));
33//!
34//! // Split the vector at index 3.
35//! let mut second_half = vec.split_off(3);
36//! assert_eq!(vec.len(), 3);
37//! assert_eq!(second_half.len(), 2);
38//!
39//! // Rejoin the vectors.
40//! vec.unsplit(second_half);
41//! assert_eq!(vec.len(), 5);
42//! ```
43//!
44//! ## Converting to immutable
45//!
46//! ```
47//! use vortex_vector::bool::BoolVectorMut;
48//! use vortex_vector::{VectorMutOps, VectorOps};
49//!
50//! let mut vec = BoolVectorMut::from_iter([true, false, true].map(Some));
51//!
52//! // Freeze into an immutable vector.
53//! let immutable = vec.freeze();
54//! assert_eq!(immutable.len(), 3);
55//! ```
56
57mod vector;
58pub use vector::BoolVector;
59
60mod vector_mut;
61pub use vector_mut::BoolVectorMut;
62
63mod scalar;
64pub use scalar::BoolScalar;
65
66mod iter;
67
68use crate::{Vector, VectorMut};
69
70impl From<BoolVector> for Vector {
71 fn from(v: BoolVector) -> Self {
72 Self::Bool(v)
73 }
74}
75
76impl From<BoolVectorMut> for VectorMut {
77 fn from(v: BoolVectorMut) -> Self {
78 Self::Bool(v)
79 }
80}