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
99
100
101
102
crate::ix!();

#[derive(Default,Serialize,Deserialize)]
pub struct BlockFileInfo {

    /**
      | number of blocks stored in file
      |
      */
    pub n_blocks:       u32,

    /**
      | number of used bytes of block file
      |
      */
    pub n_size:         u32,

    /**
      | number of used bytes in the undo file
      |
      */
    pub n_undo_size:    u32,

    /**
      | lowest height of block in file
      |
      */
    pub n_height_first: u32,

    /**
      | highest height of block in file
      |
      */
    pub n_height_last:  u32,

    /**
      | earliest time of block in file
      |
      */
    pub n_time_first:   u64,

    /**
      | latest time of block in file
      |
      */
    pub n_time_last:    u64,
}

impl BlockFileInfo {

    pub fn set_null(&mut self)  {
        
        self.n_blocks       = 0;
        self.n_size         = 0;
        self.n_undo_size    = 0;
        self.n_height_first = 0;
        self.n_height_last  = 0;
        self.n_time_first   = 0;
        self.n_time_last    = 0;
    }
    
    /**
      | update statistics (does not update
      | nSize)
      |
      */
    pub fn add_block(&mut self, 
        n_height_in: u32,
        n_time_in:   u64)  {
        
        if self.n_blocks == 0 || self.n_height_first > n_height_in {
            self.n_height_first = n_height_in;
        }

        if self.n_blocks == 0 || self.n_time_first > n_time_in {
            self.n_time_first = n_time_in;
        }

        self.n_blocks += 1;

        if n_height_in > self.n_height_last {
            self.n_height_last = n_height_in;
        }

        if n_time_in > self.n_time_last {
            self.n_time_last = n_time_in;
        }
    }

    pub fn to_string(&self) -> String {

        format!(
            "BlockFileInfo(blocks={}, size={}, heights={}...{}, time={}...{})",
            self.n_blocks,
            self.n_size,
            self.n_height_first,
            self.n_height_last,
            format_iso8601date(self.n_time_first.try_into().unwrap()),
            format_iso8601date(self.n_time_last.try_into().unwrap())
        )
    }
}