pub fn delete (&mut self, locations: &Vec<Location>) -> Result<(),Error> {
    let mut by_block: HashMap<u64,Vec<u32>> = HashMap::new();
    for (block,index) in locations {
      if *block == 0 { continue } // staging block
      match by_block.get_mut(&(*block-1)) {
        Some(indexes) => {
          indexes.push(*index);
        },
        None => {
          by_block.insert(*block-1, vec![*index]);
        },
      }
    }
    for (block,indexes) in by_block.iter() {
      let max_i = match indexes.iter().max() {
        Some(i) => *i as u64,
        None => bail!["indexes is an empty array"],
      };
      let len = 7 + max_i/8; // indexes start at 0, unlike lengths
      ensure![len <= self.store.len()?-block,
        "index length past the end of the block"];
      let mut header = self.store.read(*block, len)?;
      let block_size = u32::from_bytes(&header[0..])?.1 as u64;
      let bitfield_len = u16::from_bytes(&header[4..])?.1;
      ensure![len <= (bitfield_len as u64) + 6,
        "read length {} from index {} past expected bitfield length {} \
        for block size {} at offset {}",
        len, max_i, bitfield_len, block_size, *block
      ];
      ensure![len <= block_size, "data block is too small"];
      for index in indexes.iter() {
        let i = *index as usize;
        header[6+i/8] &= 0xff - (1<<(i%8));
      }
      self.store.write(block+6, &header[6..])?;
      match self.list_cache.get_mut(block) {
        Some(rows) => {
          rows.retain(|row| !indexes.contains(&((row.2).1)));
        },
        None => {},
      }
    }
    Ok(())
  }
// todo: replace() similar to delete but with an additional array of
// replacement candidates
replace() similar to delete but with an additional array of
replacement candidates
replace () similar to delete but with an additional array of replacement candidates
pub fn delete (&mut self, locations: &Vec<Location>) -> Result<(),Error> {
    let mut by_block: HashMap<u64,Vec<u32>> = HashMap::new();
    for (block,index) in locations {
      if *block == 0 { continue } // staging block
      match by_block.get_mut(&(*block-1)) {
        Some(indexes) => {
          indexes.push(*index);
        },
        None => {
          by_block.insert(*block-1, vec![*index]);
        },
      }
    }
    for (block,indexes) in by_block.iter() {
      let max_i = match indexes.iter().max() {
        Some(i) => *i as u64,
        None => bail!["indexes is an empty array"],
      };
      let len = 7 + max_i/8; // indexes start at 0, unlike lengths
      ensure![len <= self.store.len()?-block,
        "index length past the end of the block"];
      let mut header = self.store.read(*block, len)?;
      let block_size = u32::from_bytes(&header[0..])?.1 as u64;
      let bitfield_len = u16::from_bytes(&header[4..])?.1;
      ensure![len <= (bitfield_len as u64) + 6,
        "read length {} from index {} past expected bitfield length {} \
        for block size {} at offset {}",
        len, max_i, bitfield_len, block_size, *block
      ];
      ensure![len <= block_size, "data block is too small"];
      for index in indexes.iter() {
        let i = *index as usize;
        header[6+i/8] &= 0xff - (1<<(i%8));
      }
      self.store.write(block+6, &header[6..])?;
      match self.list_cache.get_mut(block) {
        Some(rows) => {
          rows.retain(|row| !indexes.contains(&((row.2).1)));
        },
        None => {},
      }
    }
    Ok(())
  }
pub fn delete ( & mut self , locations : & Vec < Location > ) -> Result < ( ) , Error > { let mut by_block : HashMap < u64 , Vec < u32 > > = HashMap :: new ( ) ; for ( block , index ) in locations { if * block == 0 { continue } // staging block match by_block . get_mut ( & ( * block - 1 ) ) { Some ( indexes ) => { indexes . push ( * index ) ; } , None => { by_block . insert ( * block - 1 , vec ! [ index ] ) ; } , } } for ( block , indexes ) in by_block . iter ( ) { let max_i = match indexes . iter ( ) . max ( ) { Some ( i ) => * i as u64 , None => bail ! [ " " ] , } ; let len = 7 + max_i / 8 ; // indexes start at 0, unlike lengths ensure ! [ len self store len ( ) block " " ] ; let mut header = self . store . read ( * block , len ) ? ; let block_size = u32 :: from_bytes ( & header [ 0 .. ] ) ? . 1 as u64 ; let bitfield_len = u16 :: from_bytes ( & header [ 4 .. ] ) ? . 1 ; ensure ! [ len ( bitfield_len as u64 ) 6 " \
 " len max_i bitfield_len block_size block ] ; ensure ! [ len block_size " " ] ; for index in indexes . iter ( ) { let i = * index as usize ; header [ 6 + i / 8 ] &= 0xff - ( 1 << ( i % 8 ) ) ; } self . store . write ( block + 6 , & header [ 6 .. ] ) ? ; match self . list_cache . get_mut ( block ) { Some ( rows ) => { rows . retain ( | row | ! indexes . contains ( & ( ( row . 2 ) . 1 ) ) ) ; } , None => { } , } } Ok ( ( ) ) }
todo: replace() similar to delete but with an additional array of
replacement candidates
todo : replace () similar to delete but with an additional array of replacement candidates
&mut self
locations
&Vec<Location>
&mut self
locations
&Vec<Location>