Revert some disputable changes from 7eec8f600244fe5fed9e2d254bfb447261812b28.

This commit is contained in:
vng 2015-03-18 17:04:57 +03:00 committed by Alex Zolotarev
parent 288e8af7c9
commit bab27e4533
5 changed files with 18 additions and 26 deletions

View file

@ -6,8 +6,6 @@
#include "../base/assert.hpp"
#include "../base/bits.hpp"
#include "../std/limits.hpp"
vector<uint32_t> FreqsToDistrTable(vector<uint32_t> const & origFreqs)
{
uint64_t freqLowerBound = 0;
@ -21,10 +19,8 @@ vector<uint32_t> FreqsToDistrTable(vector<uint32_t> const & origFreqs)
for (uint32_t i = 0; i < origFreqs.size(); ++i)
{
uint32_t freq = origFreqs[i];
if (freq > 0 && freq < minFreq)
minFreq = freq;
if (freq > 0 && freq < freqLowerBound)
freq = static_cast<uint32_t>(freqLowerBound);
if (freq > 0 && freq < minFreq) minFreq = freq;
if (freq > 0 && freq < freqLowerBound) freq = freqLowerBound;
freqs.push_back(freq);
sum += freq;
result.push_back(sum);
@ -93,8 +89,7 @@ vector<uint8_t> ArithmeticEncoder::Finalize()
void ArithmeticEncoder::PropagateCarry()
{
ASSERT(m_output.size() > 0, ());
int i = static_cast<int>(m_output.size() - 1);
int i = m_output.size() - 1;
while (i >= 0 && m_output[i] == 0xFF)
{
m_output[i] = 0;
@ -117,8 +112,7 @@ ArithmeticDecoder::ArithmeticDecoder(Reader & reader, vector<uint32_t> const & d
uint32_t ArithmeticDecoder::Decode()
{
ASSERT(m_distrTable.size() <= numeric_limits<uint32_t>::max(), ());
uint32_t l = 0, r = static_cast<uint32_t>(m_distrTable.size()), m = 0;
uint32_t l = 0, r = m_distrTable.size(), m = 0;
uint32_t shiftedSize = m_size >> DISTR_SHIFT;
while (r - l > 1)
{

View file

@ -38,8 +38,8 @@ uint64_t BlobIndexer::AddBlob(string const & blob)
if (m_currentChunk.size() + blob.size() > m_maxUncompressedChunkSize)
FlushChunk();
m_blobChunkAndOffset.push_back(static_cast<uint32_t>(
(m_chunkOffset.size() << BITS_IN_CHUNK_SIZE) + m_currentChunk.size()));
m_blobChunkAndOffset.push_back(
(m_chunkOffset.size() << BITS_IN_CHUNK_SIZE) + m_currentChunk.size());
m_currentChunk.insert(m_currentChunk.end(), blob.begin(), blob.end());
@ -55,7 +55,7 @@ void BlobIndexer::FlushChunk()
m_writer.Write(compressedChunk.data(), compressedChunk.size());
WriteToSink(m_writer, static_cast<uint32_t>(m_currentChunk.size()));
uint32_t const chunkPrevOffset = (m_chunkOffset.empty() ? 0 : m_chunkOffset.back());
m_chunkOffset.push_back(static_cast<uint32_t>(compressedChunk.size() + 4 + chunkPrevOffset));
m_chunkOffset.push_back(compressedChunk.size() + 4 + chunkPrevOffset);
m_currentChunk.clear();
}
}

View file

@ -16,7 +16,7 @@ namespace {
vector<uint32_t> SerialFreqsToDistrTable(Reader & reader, uint64_t & decodeOffset, uint64_t cnt)
{
vector<uint32_t> freqs;
for (uint64_t i = 0; i < cnt; ++i) freqs.push_back(static_cast<uint32_t>(VarintDecode(reader, decodeOffset)));
for (uint64_t i = 0; i < cnt; ++i) freqs.push_back(VarintDecode(reader, decodeOffset));
return FreqsToDistrTable(freqs);
}
}
@ -383,12 +383,12 @@ vector<uint32_t> DecodeCompressedBitVector(Reader & reader) {
bool is_empty = (header & 4) != 0;
if (!is_empty)
{
posOnes.push_back(static_cast<uint32_t>(header >> 3));
posOnes.push_back(header >> 3);
prevOnePos = posOnes.back();
}
while (decodeOffset < serialSize)
{
posOnes.push_back(static_cast<uint32_t>(prevOnePos + VarintDecode(reader, decodeOffset) + 1));
posOnes.push_back(prevOnePos + VarintDecode(reader, decodeOffset) + 1);
prevOnePos = posOnes.back();
}
}
@ -412,7 +412,7 @@ vector<uint32_t> DecodeCompressedBitVector(Reader & reader) {
uint32_t bitsUsed = bitsUsedVec[i];
uint64_t diff = 0;
if (bitsUsed > 0) diff = ((uint64_t(1) << (bitsUsed - 1)) | bitReader.Read(bitsUsed - 1)) + 1; else diff = 1;
posOnes.push_back(static_cast<uint32_t>(prevOnePos + diff));
posOnes.push_back(prevOnePos + diff);
prevOnePos += diff;
}
decodeOffset = serialSize;
@ -431,8 +431,7 @@ vector<uint32_t> DecodeCompressedBitVector(Reader & reader) {
if (!isFirstOne) zerosRangeSize = VarintDecode(reader, decodeOffset) + 1; else isFirstOne = false;
uint64_t onesRangeSize = VarintDecode(reader, decodeOffset) + 1;
sum += zerosRangeSize;
for (uint64_t i = sum; i < sum + onesRangeSize; ++i)
posOnes.push_back(static_cast<uint32_t>(i));
for (uint64_t i = sum; i < sum + onesRangeSize; ++i) posOnes.push_back(i);
sum += onesRangeSize;
}
}
@ -476,7 +475,7 @@ vector<uint32_t> DecodeCompressedBitVector(Reader & reader) {
if (bitsUsed > 0) onesRangeSize = ((uint64_t(1) << (bitsUsed - 1)) | bitReader.Read(bitsUsed - 1)) + 1; else onesRangeSize = 1;
++i1;
sum += zerosRangeSize;
for (uint64_t j = sum; j < sum + onesRangeSize; ++j) posOnes.push_back(static_cast<uint32_t>(j));
for (uint64_t j = sum; j < sum + onesRangeSize; ++j) posOnes.push_back(j);
sum += onesRangeSize;
}
CHECK(i0 == cntElements0 && i1 == cntElements1, ());

View file

@ -105,8 +105,7 @@ CompressedVarnumVectorReader::CompressedVarnumVectorReader(Reader & reader)
m_supportSums = VarintDecode(m_reader, offset) != 0;
vector<uint32_t> sizesFreqs;
uint64_t freqsCnt = VarintDecode(m_reader, offset);
for (uint32_t i = 0; i < freqsCnt; ++i)
sizesFreqs.push_back(static_cast<uint32_t>(VarintDecode(m_reader, offset)));
for (uint32_t i = 0; i < freqsCnt; ++i) sizesFreqs.push_back(VarintDecode(m_reader, offset));
m_distrTable = FreqsToDistrTable(sizesFreqs);
m_numsEncodedOffset = offset;

View file

@ -56,7 +56,7 @@ void VectorBuilder::AddNum(uint64_t num)
if (m_numsCount % m_numElemPerTableEntry == 0)
{
TableEntry tableEntry;
tableEntry.pos = static_cast<uint32_t>(m_serialNums.size());
tableEntry.pos = m_serialNums.size();
tableEntry.sum = m_sum;
m_selectTable.push_back(tableEntry);
}
@ -143,7 +143,7 @@ void Vector::FindByIndex(uint64_t index, uint32_t & serialPos, uint64_t & sumBef
uint64_t num = VarintDecode(m_reader, numOffset);
sum += num;
}
serialPos = static_cast<uint32_t>(numOffset - m_serialNumsOffset);
serialPos = numOffset - m_serialNumsOffset;
sumBefore = sum;
}
@ -191,7 +191,7 @@ void Vector::FindBySum(uint64_t sum, uint32_t & serialPos, uint64_t & sumBefore,
++countBefore;
}
serialPos = static_cast<uint32_t>(numOffset - m_serialNumsOffset);
serialPos = numOffset - m_serialNumsOffset;
sumBefore = numsSum;
}
@ -201,7 +201,7 @@ void Vector::Read(uint32_t & serialPos, uint64_t & num)
uint64_t numOffset = m_serialNumsOffset + serialPos;
num = VarintDecode(m_reader, numOffset);
serialPos = static_cast<uint32_t>(numOffset - m_serialNumsOffset);
serialPos = numOffset - m_serialNumsOffset;
}
}