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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
pub trait CsvParseResult<P, T> {
    fn new(payload_inner: T) -> Self;
    fn into_payload(self) -> P;
}

pub struct CsvParseResultLeft<R> {
    pub(crate) csv_left_right_parse_result: CsvLeftRightParseResult<R>,
}

pub struct CsvParseResultRight<R> {
    pub(crate) csv_left_right_parse_result: CsvLeftRightParseResult<R>,
}

#[derive(Debug, PartialEq, Copy, Clone)]
pub enum CsvLeftRightParseResult<R> {
    Left(R),
    Right(R),
}

#[derive(Debug, PartialEq, Copy, Clone)]
pub(crate) struct RecordHash {
    pub(crate) key: u128,
    pub(crate) record_hash: u128,
}

impl RecordHash {
    #[inline]
    pub(crate) fn new(key: u128, record_hash: u128) -> Self {
        Self { key, record_hash }
    }
}

#[derive(Debug, PartialEq, Copy, Clone)]
pub struct RecordHashWithPosition {
    pub(crate) record_hash: RecordHash,
    pub(crate) pos: Position,
}

impl RecordHashWithPosition {
    #[inline]
    pub(crate) fn new(key: u128, record_hash: u128, pos: Position) -> Self {
        Self {
            record_hash: RecordHash::new(key, record_hash),
            pos,
        }
    }
    #[inline]
    pub(crate) fn key(&self) -> u128 {
        self.record_hash.key
    }
    #[inline]
    pub(crate) fn record_hash_num(&self) -> u128 {
        self.record_hash.record_hash
    }
}

pub struct CsvByteRecordWithHash {
    pub(crate) byte_record: csv::Result<csv::ByteRecord>,
    pub(crate) record_hash: RecordHash,
}

impl CsvByteRecordWithHash {
    #[inline]
    pub(crate) fn new(byte_record: csv::Result<csv::ByteRecord>, record_hash: RecordHash) -> Self {
        Self {
            byte_record,
            record_hash,
        }
    }
}

#[derive(Debug, PartialEq, Copy, Clone)]
pub(crate) struct Position {
    pub byte_offset: u64,
    pub line: u64,
}

impl Position {
    #[inline]
    pub fn new(byte_offset: u64, line: u64) -> Self {
        Self { byte_offset, line }
    }
}

#[allow(clippy::from_over_into)]
impl Into<csv::Position> for Position {
    #[inline]
    fn into(self) -> csv::Position {
        let mut csv_pos = csv::Position::new();
        std::mem::replace(
            csv_pos
                .set_byte(self.byte_offset)
                .set_line(self.line)
                .set_record(self.line - 1),
            csv::Position::new(),
        )
    }
}