Exemplo n.º 1
0
bool erase_one(data_buffer& buffer, index123_type& index123)
{
  size_t buffer_size = std::distance(buffer.begin(), buffer.end());
  data_pointer ptr = buffer.begin() + (buffer_size > 0 ? rand()%buffer_size : 0);
  offset_t offset = ptr.get_offset();
  
  auto lower = index123.lower_bound(offset);
  auto upper = index123.upper_bound(offset);
  if (std::distance(lower,upper)!=1 )
  {
    std::cout << ptr->data1 << "," << ptr->data2 << ", " << ptr->data3 << std::endl;
    std::cout << "std::distance(lower,upper): "  << std::distance(lower,upper) << std::endl;
    return false;
  }
  
  index123.erase( offset );
  buffer.deallocate(ptr, 1);
  size_t buffer_size2 = std::distance(buffer.begin(), buffer.end());
  if ( (buffer_size - buffer_size2) != 1)
  {
    std::cout  << "Buffer size check failed - " << (buffer_size-1) << "!=" << buffer_size2 << std::endl;
    return false;
  }
  
  return true;
}
Exemplo n.º 2
0
bool erase_begin(data_buffer& buffer, index123_type& index123)
{
  data_pointer ptr = buffer.begin();
  auto itr = index123.find( ptr.get_offset() /*static_cast<offset_t>( static_cast<size_t>(ptr) )*/);
  index123.erase(itr);
  buffer.deallocate(ptr, 1);
  return true;
}
Exemplo n.º 3
0
bool create(data_buffer& buffer, index123_type& index123)
{
  data_pointer ptr = buffer.allocate(1);
  *ptr = generate();
  auto itr = index123.find( ptr.get_offset() );
  if (itr == index123.end())
  {
    index123.insert( ptr.get_offset() );
  }
  else
  {
    buffer.deallocate(ptr, 1);
  }

  return itr == index123.end();
}