UTIL_THROW_IF(got%entry_size,ReadSizeException,"File ended with "<<got<<" bytes, not a multiple of "<<entry_size<<".");
if(got==0){
link.Poison();
return;
}else{
link->SetValidSize(got);
}
}
}
voidPRead::Run(constChainPosition&position){
scoped_fdowner;
if(own_)owner.reset(file_);
constuint64_tsize=SizeOrThrow(file_);
UTIL_THROW_IF(size%static_cast<uint64_t>(position.GetChain().EntrySize()),ReadSizeException,"File size "<<file_<<" size is "<<size<<" not a multiple of "<<position.GetChain().EntrySize());
// Holding area for beginning of line to be placed in next block.
std::vector<char>carry;
for(Linkblock(position);;++block){
char*to=static_cast<char*>(block->Get());
char*begin=to;
char*end=to+position.GetChain().BlockSize();
std::copy(carry.begin(),carry.end(),to);
to+=carry.size();
while(to!=end){
std::size_tgot=reader.Read(to,end-to);
if(!got){
// EOF
block->SetValidSize(to-begin);
++block;
block.Poison();
return;
}
to+=got;
}
// Find the last newline.
char*newline;
for(newline=to-1;;--newline){
UTIL_THROW_IF(newline<begin,Exception,"Did not find a newline in "<<position.GetChain().BlockSize()<<" bytes of input of "<<NameFromFD(fd_)<<". Is this a text file?");
if(*newline=='\n')break;
}
// Copy everything after the last newline to the carry.
UTIL_THROW_IF(!config_.buffer_size,BadSortConfig,"Sort buffer too small");
UTIL_THROW_IF(config_.total_memory<config_.buffer_size*4,BadSortConfig,"Sorting memory "<<config_.total_memory<<" is too small for four buffers (two read and two write).");
* Constructs a new @ref util::stream::Sort "Sort" object which is stored in this @ref util::FixedArray "array".
*
* The new @ref util::stream::Sort "Sort" object is constructed using the provided @ref util::stream::SortConfig "SortConfig" and @ref Comparator "ngram comparator";
* once constructed, a new worker @ref util::stream::Thread "thread" (owned by the @ref util::stream::Chain "chain") will sort the n-gram data stored
* in the @ref util::stream::Block "blocks" of the provided @ref util::stream::Chain "chain".