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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
//! Module contains a dimension estimator for [`CompactTable`]
//!
//! [`CompactTable`]: crate::tables::CompactTable
use crate::grid::dimension::{Dimension, Estimate};
/// A constant size dimension or a value dimension.
#[derive(Debug, Clone, Copy)]
pub struct ConstDimension<const COLUMNS: usize, const ROWS: usize> {
height: ConstSize<ROWS>,
width: ConstSize<COLUMNS>,
}
impl<const COLUMNS: usize, const ROWS: usize> ConstDimension<COLUMNS, ROWS> {
/// Returns a new dimension object with a given estimates.
pub const fn new(width: ConstSize<COLUMNS>, height: ConstSize<ROWS>) -> Self {
Self { width, height }
}
}
impl<const COLUMNS: usize, const ROWS: usize> Dimension for ConstDimension<COLUMNS, ROWS> {
fn get_width(&self, column: usize) -> usize {
match self.width {
ConstSize::List(list) => list[column],
ConstSize::Value(val) => val,
}
}
fn get_height(&self, row: usize) -> usize {
match self.height {
ConstSize::List(list) => list[row],
ConstSize::Value(val) => val,
}
}
}
impl<const COLUMNS: usize, const ROWS: usize> From<ConstDimension<COLUMNS, ROWS>>
for (ConstSize<COLUMNS>, ConstSize<ROWS>)
{
fn from(value: ConstDimension<COLUMNS, ROWS>) -> Self {
(value.width, value.height)
}
}
impl<R, D, const COLUMNS: usize, const ROWS: usize> Estimate<R, D>
for ConstDimension<COLUMNS, ROWS>
{
fn estimate(&mut self, _: R, _: &D) {}
}
/// Const size represents either a const array values or a single value which responsible for the whole list.
#[derive(Debug, Clone, Copy)]
pub enum ConstSize<const N: usize> {
/// A constant array of estimates.
List([usize; N]),
/// A value which act as a single estimate for all entries.
Value(usize),
}
impl From<usize> for ConstSize<0> {
fn from(value: usize) -> Self {
ConstSize::Value(value)
}
}
impl<const N: usize> From<[usize; N]> for ConstSize<N> {
fn from(value: [usize; N]) -> Self {
ConstSize::List(value)
}
}
|