<commit_before>use std::io::Read;
use std::io::Result as IoResult;
use std::io::Error as IoError;
use std::io::ErrorKind as IoErrorKind;
use {MemReader, ReadsMemory};

pub struct MemorySlice<'a> {
  pub start: usize,
  pub end: usize,
  reader: &'a MemReader,
  mark: Option<usize>
}

impl<'a> MemorySlice<'a> {
  pub fn new(reader: &'a MemReader, start: usize, end: usize) -> Self {
    MemorySlice {
      start: start,
      end: end,
      reader: reader,
      mark: None
    }
  }
}

impl<'a> Read for MemorySlice<'a> {
  fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> {
    let start = match self.mark {
      Some(m) => m,
      None => self.start
    };
    let buf_len = buf.len();
    if start + buf_len > self.end {
      return Ok(0);
    }
    let bytes = self.reader.read_bytes(start, buf_len).map_err(|e| IoError::new(IoErrorKind::Other, e))?;
    let bytes_len = bytes.len();
    self.mark = Some(start + buf_len);
    for (i, byte) in bytes.into_iter().enumerate() {
      buf[i] = byte;
    }
    Ok(bytes_len)
  }
}
<commit_msg>refactor: make start and end fields private<commit_after>use std::io::Read;
use std::io::Result as IoResult;
use std::io::Error as IoError;
use std::io::ErrorKind as IoErrorKind;
use {MemReader, ReadsMemory};

pub struct MemorySlice<'a> {
  start: usize,
  end: usize,
  reader: &'a MemReader,
  mark: Option<usize>
}

impl<'a> MemorySlice<'a> {
  pub fn new(reader: &'a MemReader, start: usize, end: usize) -> Self {
    MemorySlice {
      start: start,
      end: end,
      reader: reader,
      mark: None
    }
  }

  /// The start address of this slice.
  pub fn start(&self) -> usize {
    self.start
  }

  /// The end address of this slice.
  pub fn end(&self) -> usize {
    self.end
  }
}

impl<'a> Read for MemorySlice<'a> {
  fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> {
    let start = match self.mark {
      Some(m) => m,
      None => self.start
    };
    let buf_len = buf.len();
    if start + buf_len > self.end {
      return Ok(0);
    }
    let bytes = self.reader.read_bytes(start, buf_len).map_err(|e| IoError::new(IoErrorKind::Other, e))?;
    let bytes_len = bytes.len();
    self.mark = Some(start + buf_len);
    for (i, byte) in bytes.into_iter().enumerate() {
      buf[i] = byte;
    }
    Ok(bytes_len)
  }
}

{'fraction_non_alphanumeric': 0.15714285714285714, 'fraction_numerical': 0.0017316017316017316, 'mean_word_length': 2.884033613445378, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2915172', 'n_tokens_mistral': 841, 'n_tokens_neox': 860, 'n_words': 226}