6 #ifndef TURI_UNITY_FILE_LINE_COUNT_ESTIMATOR_HPP 7 #define TURI_UNITY_FILE_LINE_COUNT_ESTIMATOR_HPP 45 file_size(file_size_in_bytes) {}
51 file_size = file_size_in_bytes;
59 accumulated_bytes += other_estimator.accumulated_bytes;
60 accumulated_lines += other_estimator.accumulated_lines;
61 num_observations += other_estimator.num_observations;
70 inline void observe(
size_t line_count,
size_t file_pos) {
76 if (file_pos != 0 && last_file_pos == 0) {
78 last_file_pos = file_pos;
79 last_buffer_size = file_pos;
80 current_lines_from_buffer += line_count;
81 }
else if (file_pos == last_file_pos) {
83 current_lines_from_buffer += line_count;
84 }
else if (file_pos != last_file_pos) {
86 accumulated_lines += current_lines_from_buffer + line_count;
87 accumulated_bytes += last_buffer_size;
89 current_lines_from_buffer = 0;
90 last_buffer_size = file_pos - last_file_pos;
91 last_file_pos = file_pos;
103 if (accumulated_lines == 0) {
104 return (
double)file_size / last_buffer_size * current_lines_from_buffer;
107 return (
double)file_size / accumulated_bytes * accumulated_lines;
115 return accumulated_lines + current_lines_from_buffer;
121 size_t file_size = 0;
124 size_t accumulated_lines = 0;
127 size_t accumulated_bytes = 0;
130 size_t current_lines_from_buffer = 0;
133 size_t last_file_pos = 0;
136 size_t last_buffer_size = 0;
141 size_t num_observations = 0;
file_line_count_estimator(size_t file_size_in_bytes)
double number_of_lines() const
size_t num_lines_observed() const
void observe(size_t line_count, size_t file_pos)
void observe(file_line_count_estimator &other_estimator)
void set_file_size(size_t file_size_in_bytes)
file_line_count_estimator()