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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.

use crate::errors::Result;
use crate::properties::DecodeProperties;
use crate::range::Range;
use std::ops::Deref;

pub trait TablePropertiesExt {
    type TablePropertiesCollection: TablePropertiesCollection<
        Self::TablePropertiesCollectionIter,
        Self::TablePropertiesKey,
        Self::TableProperties,
        Self::UserCollectedProperties,
    >;
    type TablePropertiesCollectionIter: TablePropertiesCollectionIter<
        Self::TablePropertiesKey,
        Self::TableProperties,
        Self::UserCollectedProperties,
    >;
    type TablePropertiesKey: TablePropertiesKey;
    type TableProperties: TableProperties<Self::UserCollectedProperties>;
    type UserCollectedProperties: UserCollectedProperties;

    fn get_properties_of_tables_in_range(
        &self,
        cf: &str,
        ranges: &[Range],
    ) -> Result<Self::TablePropertiesCollection>;

    fn get_range_properties_cf(
        &self,
        cfname: &str,
        start_key: &[u8],
        end_key: &[u8],
    ) -> Result<Self::TablePropertiesCollection> {
        let range = Range::new(start_key, end_key);
        self.get_properties_of_tables_in_range(cfname, &[range])
    }
}

pub trait TablePropertiesCollection<I, PKey, P, UCP>
where
    I: TablePropertiesCollectionIter<PKey, P, UCP>,
    PKey: TablePropertiesKey,
    P: TableProperties<UCP>,
    UCP: UserCollectedProperties,
{
    fn iter(&self) -> I;

    fn len(&self) -> usize;

    fn is_empty(&self) -> bool {
        self.len() == 0
    }
}

pub trait TablePropertiesCollectionIter<PKey, P, UCP>: Iterator<Item = (PKey, P)>
where
    PKey: TablePropertiesKey,
    P: TableProperties<UCP>,
    UCP: UserCollectedProperties,
{
}

pub trait TablePropertiesKey: Deref<Target = str> {}

pub trait TableProperties<UCP>
where
    UCP: UserCollectedProperties,
{
    fn num_entries(&self) -> u64;

    fn user_collected_properties(&self) -> UCP;
}

pub trait UserCollectedProperties: DecodeProperties {
    fn get(&self, index: &[u8]) -> Option<&[u8]>;

    fn len(&self) -> usize;

    fn is_empty(&self) -> bool {
        self.len() == 0
    }
}