vortex_layout/
context.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use vortex_array::aliases::hash_map::HashMap;

use crate::encoding::{LayoutEncodingRef, LayoutId};
use crate::layouts::chunked::ChunkedLayout;
use crate::layouts::flat::FlatLayout;
use crate::layouts::struct_::StructLayout;

#[derive(Debug, Clone)]
pub struct LayoutContext {
    layout_refs: HashMap<LayoutId, LayoutEncodingRef>,
}

pub type LayoutContextRef = std::sync::Arc<LayoutContext>;

impl LayoutContext {
    pub fn new(layout_refs: HashMap<LayoutId, LayoutEncodingRef>) -> Self {
        Self { layout_refs }
    }

    pub fn lookup_layout(&self, id: LayoutId) -> Option<LayoutEncodingRef> {
        self.layout_refs.get(&id).cloned()
    }
}

impl Default for LayoutContext {
    fn default() -> Self {
        Self::new(
            [
                &ChunkedLayout as LayoutEncodingRef,
                &FlatLayout,
                &StructLayout,
            ]
            .into_iter()
            .map(|l| (l.id(), l))
            .collect(),
        )
    }
}