This is my code:

use hashbrown::HashMap;
use memchr::memchr;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::str::from_utf8;

const CHUNKSIZE: usize = 16;
const VALUE: [u64; 256] = {
    let mut array = [0u64; 256];
    array[b'A' as usize] = 1;
    array[b'T' as usize] = 1;
    array[b'a' as usize] = 1;
    array[b't' as usize] = 1;
    array[b'G' as usize] = 1 << 32;
    array[b'C' as usize] = 1 << 32;
    array[b'g' as usize] = 1 << 32;
    array[b'c' as usize] = 1 << 32;
    array
};

fn chromsize(f: &str) -> HashMap<String, u64> {
    let file = File::open(f).unwrap();
    let mut reader = BufReader::new(file);

    let mut totals = 0u64;
    let mut line = Vec::with_capacity(100);
    let mut acc = HashMap::new();
    let mut chr = String::new();

    loop {
        if reader.read_until(b'\n', &mut line).unwrap() == 0 {
            break;
        }

        if line[0] == b'>' && chr.is_empty() {
            chr = from_utf8(&line[1..memchr(b'\n', &line).unwrap()])
                .unwrap()
                .trim()
                .to_string();
            line.clear();
            continue;
        } else if line[0] == b'>' {
            let at = totals & 0xFFFFFFFF;
            let gc = totals >> 32;
            acc.insert(chr.clone(), at + gc);
            chr = from_utf8(&line[1..memchr(b'\n', &line).unwrap()])
                .unwrap()
                .trim()
                .to_string();
            totals = 0;
            line.clear();
            continue;
        }

        let mut chunker = line.chunks_exact(CHUNKSIZE);

        while let Some(chars) = chunker.next() {
            totals += chars.iter().map(|b| VALUE[*b as usize]).sum::<u64>();
        }

        for c in chunker.remainder() {
            totals += VALUE[*c as usize];
        }

        line.clear();
    }

    let at = totals & 0xFFFFFFFF;
    let gc = totals >> 32;
    acc.insert(chr, at + gc);
    acc
}


Calculates the chromosome sizes for any fasta file. While testing it I have found that it provides a lower number than the real chrom size. For example, these are the chromosome sizes for the dog (some):

chr1	123313939
chr2	86187811
chr3	92870237
chr4	89007665
chr5	89573405
chr6	78268176
chr7	81039452
chr8	75260524
chr9	62002293
chr10	70361000
chr11	75541347
chr12	73497294
chr13	64037277
chr14	61043064
chr15	65200600
chr16	62021213
chr17	65471548
chr18	56883407
chr19	55265241
chr20	58896461
chr21	52140716
chr22	62106979

and this the output of my script:

{"chr7": 81039342, "chr3": 92870100, "chr8": 73921396, "chr9": 61929633, "chr35": 26942191, "chr17": 65440191, "chr24": 48802617, "chr14": 61042990, "chr11": 75386814, "chr19": 55256708, "chr18": 56594491, "chr21": 51922883, "chr32": 39023683, "chr38": 24101997, "chr6": 78204522, "chr29": 42046805, "chr1": 123307686, "chr33": 31647250, "chr2": 85957698, "chr5": 89515376, "chr10": 70359141, "chr12": 73497104, "chr20": 58896357, "chr34": 42257750, "chr36": 31065124, "chr25": 51924583, "chr22": 62084727, "chr30": 40411010, "chr16": 61696563, "chr23": 53282759, "chr28": 41862034, "chr37": 30932345, "chr31": 39518897, "chr13": 63838305, "chr4": 89007539, "chr15": 65194537, "chr26": 39293700, "chr27": 46247080, "chrX": 122508213}

check for example chr1:

expected: chr1	123313939
obtained: "chr1": 123307686

a difference of 6253 nucleotides. Could you explain why this is happening and how should I fix it?