Removed dummy assert in compare functor.

This commit is contained in:
vng 2014-08-06 17:45:25 +03:00 committed by Alex Zolotarev
parent 107bf6c28e
commit 341a8f73cb
2 changed files with 28 additions and 18 deletions

View file

@ -22,6 +22,13 @@ template <class TSink> void Write(TSink & sink, FilesContainerBase::Info const &
WriteVarUint(sink, i.m_size);
}
string DebugPrint(FilesContainerBase::Info const & info)
{
ostringstream ss;
ss << "{ " << info.m_tag << ", " << info.m_offset << ", " << info.m_size << " }";
return ss.str();
}
/////////////////////////////////////////////////////////////////////////////
// FilesContainerBase
/////////////////////////////////////////////////////////////////////////////
@ -95,17 +102,23 @@ void FilesContainerW::Open(FileWriter::Op op)
case FileWriter::OP_WRITE_EXISTING:
{
{
// read an existing service info
FileReader reader(m_name);
ReadInfo(reader);
}
// Important: in append mode we should sort info-vector by offsets
sort(m_info.begin(), m_info.end(), LessOffset());
break;
// read an existing service info
FileReader reader(m_name);
ReadInfo(reader);
}
// Important: in append mode we should sort info-vector by offsets
sort(m_info.begin(), m_info.end(), LessOffset());
// Check that all offsets are unique
#ifdef DEBUG
for (size_t i = 1; i < m_info.size(); ++i)
ASSERT(m_info[i-1].m_offset < m_info[i].m_offset ||
m_info[i-1].m_size == 0 ||
m_info[i].m_size == 0, ());
#endif
break;
default:
ASSERT ( false, ("Unsupported options") );
break;

View file

@ -5,6 +5,7 @@
#include "../std/vector.hpp"
#include "../std/string.hpp"
class FilesContainerBase
{
public:
@ -18,6 +19,8 @@ public:
Info() {}
Info(Tag const & tag, uint64_t offset) : m_tag(tag), m_offset(offset) {}
friend string DebugPrint(Info const & info);
};
protected:
@ -36,19 +39,12 @@ protected:
return (t1 < t2.m_tag);
}
};
struct LessOffset
{
bool operator() (Info const & t1, Info const & t2) const
{
if (t1.m_offset == t2.m_offset)
{
// Element with nonzero size should be the last one,
// for correct append writer mode (FilesContainerW::GetWriter).
ASSERT ( t1.m_size == 0 || t2.m_size == 0, (t1.m_size, t2.m_size) );
return (t1.m_size < t2.m_size);
}
else
return (t1.m_offset < t2.m_offset);
return (t1.m_offset < t2.m_offset);
}
bool operator() (Info const & t1, uint64_t const & t2) const
{
@ -59,6 +55,7 @@ protected:
return (t1 < t2.m_offset);
}
};
class EqualTag
{
Tag const & m_tag;