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;
}
bool check(data_buffer& buffer, index123_type& index123)
{
  size_t buffer_size = std::distance(buffer.begin(), buffer.end());
  size_t buffer2_size = buffer.count();
  size_t index_size = index123.size();
  size_t index2_size = std::distance(index123.begin(), index123.end());
  bool size_check_fail = (buffer_size != index_size || buffer2_size != index2_size || buffer2_size != index_size);
  if ( size_check_fail )
  {
    std::cout << std::endl << "buffer/index size check failed!" << std::endl;
    std::cout << "buffer_size " << buffer_size << std::endl;
    std::cout << "index_size " << index_size << std::endl;
    return false;
  }

  if ( index123.size() < 2 )
  {
    return true;
  }
  
  cmp123 cmp(buffer);
  index123_type::iterator itr1 = index123.begin();
  index123_type::iterator itr2 = itr1 + 1;
  for ( ;itr2!=index123.end(); ++itr1, ++itr2)
  {
    if ( cmp(*itr1, *itr2) )
    {
      continue;
    }
    if ( !cmp(*itr2, *itr1) )
    {
      continue;
    }

    std::cout << std::endl << "comparator failed!" << std::endl;
    return false;
  }

  return true;
}
 cmp123(const data_buffer& b)
   : left(b.end())
   , right(b.end())
 {}