#[derive(Eq, PartialEq, Hash, Debug)]
pub struct HashInstructions {
    pub seed: u64,
    pub offset: u64,
    pub read_size: u64,
    pub file_size: u64,
}

impl HashInstructions {
    pub fn work_size(&self) -> u64 {
        // offset is always smaller than file_size and block_size
        if self.offset + self.read_size > self.file_size {
            if self.offset > self.file_size {
                0
            } else {
                self.file_size - self.offset
            }
        } else {
            self.read_size
        }
    }
}

#[cfg(test)]
mod tests {
    use crate::candidate_selection::hashing::HashInstructions;

    #[test]
    fn correctly_calculates_limited_work_size() {
        let instructions = HashInstructions {
            seed: 0,
            offset: 2000,
            read_size: 16384,
            file_size: 10000,
        };

        assert_eq!(8000, instructions.work_size())
    }

    #[test]
    fn correctly_calculates_block_limited_work_size() {
        let instructions = HashInstructions {
            seed: 0,
            offset: 2000,
            read_size: 16384,
            file_size: 65536,
        };

        assert_eq!(16384, instructions.work_size())
    }
}
