Пример #1
0
void SequentialFile::erase( offset_t offset )
{
  ASSERT_TRUE(isWritable());

  Record* target = offset2record( offset );
  ASSERT_TRUE(target->isValid());
  offset_t end_offset = offset + target->GetRecordSize();

  char* target_end = (char*)target->getEndOfRecord();
  for (char* wiper = (char*)target; wiper < target_end; wiper++) {
    *wiper = 0;
  }

  // fix next_write_offset if it is the last record
  if (end_offset == next_write_offset) {
    iterator i = at(end_offset);
    i.GetPrevious();

    if (!i.IsValid()) {
      next_write_offset = 8;
    } else {
      next_write_offset = record2offset((Record*)i.GetRecord()->getEndOfRecord());
    }
  }
}
Пример #2
0
void SequentialFile::moveRecord( offset_t at, offset_t to )
{
  Record* source = offset2record( at );
  unsigned int size = source->GetRecordSize();

  void* dest = offset2record( to );

  memmove( dest, source, size );

  if( to > at ) // move right, overlap or no overlap
    memset( source, 0, (size_t)(to - at) );

  else if( to + size < at ) // move left, no overlap
    memset( source, 0, size );

  else // move left, overlap
    memset( offset2record( to + size ), 0, (size_t)(at - to) );
}