Skip to content

Commit

Permalink
Improving compatibility with Visual Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Sep 19, 2016
1 parent 4803575 commit 27c2d8d
Show file tree
Hide file tree
Showing 9 changed files with 1,366 additions and 27 deletions.
4 changes: 4 additions & 0 deletions headers/codecfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ static inline CodecMap initializefactory() {
new CompositeCodec<SIMDOPTPFor<4, Simple16<false>>, VariableByte>());
map["varint"] = std::shared_ptr<IntegerCODEC>(new VariableByte());
map["vbyte"] = std::shared_ptr<IntegerCODEC>(new VByte());
#if !(defined(_MSC_VER)) // todo: port to Visual Studio
map["maskedvbyte"] = std::shared_ptr<IntegerCODEC>(new MaskedVByte());
#endif
#if !(defined(_MSC_VER)) // todo: streamvbyte needs to be ported to Visual Studio
map["streamvbyte"] = std::shared_ptr<IntegerCODEC>(new StreamVByte());
#endif
#if !defined(_MSC_VER) || (_MSC_VER != 1900)
map["varintgb"] = std::shared_ptr<IntegerCODEC>(new VarIntGB<>());
#endif
Expand Down
2 changes: 1 addition & 1 deletion headers/memutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ template <class T, size_t alignment> class AlignedSTLAllocator {

// return maximum number of elements that can be allocated
size_type max_size() const throw() {
return std::numeric_limits<std::size_t>::max() / sizeof(T);
return (std::numeric_limits<std::size_t>::max)() / sizeof(T);
}

/*
Expand Down
6 changes: 5 additions & 1 deletion headers/simdvariablebyte.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

#ifndef SIMDVARIABLEBYTE_H_
#define SIMDVARIABLEBYTE_H_

#if ! defined(_MSC_VER) // code relies on compound literals which Visual Studio fails to support. TODO: code a workaround


#include "common.h"
#include "codecs.h"

Expand Down Expand Up @@ -93,5 +97,5 @@ class MaskedVByte : public FastPForLib::IntegerCODEC {

std::string name() const { return "MaskedVByte"; }
};

#endif
#endif /* SIMDVARIABLEBYTE_H_ */
38 changes: 17 additions & 21 deletions headers/simple8b.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ template <bool MarkLength> class Simple8b : public IntegerCODEC {
static bool tryme(const uint32_t *n, size_t len) {
if (log1 >= 32)
return true;
const uint32_t min =
const uint32_t minv =
(static_cast<uint32_t>(len) < num1) ? static_cast<uint32_t>(len) : num1;
for (uint32_t i = 0; i < min; i++) {
for (uint32_t i = 0; i < minv; i++) {
if (n[i] >= (1U << (log1 % 32)))
return false;
}
Expand Down Expand Up @@ -115,10 +115,6 @@ template <bool MarkLength> class Simple8b : public IntegerCODEC {
}
++in;
}

private:
// for clarity
static uint32_t min(uint32_t a, uint32_t b) { return a < b ? a : b; }
};

template <bool MarkLength>
Expand Down Expand Up @@ -583,49 +579,49 @@ const uint32_t *Simple8b<MarkLength>::decodeArray(const uint32_t *in,
#endif
switch (which(in64)) {
case 0:
carefulunpack<0>(min(static_cast<uint32_t>(end - out), 240), out, in64);
carefulunpack<0>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 240), out, in64);
break;
case 1:
carefulunpack<0>(min(static_cast<uint32_t>(end - out), 120), out, in64);
carefulunpack<0>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 120), out, in64);
break;
case 2:
carefulunpack<1>(min(static_cast<uint32_t>(end - out), 60), out, in64);
carefulunpack<1>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 60), out, in64);
break;
case 3:
carefulunpack<2>(min(static_cast<uint32_t>(end - out), 30), out, in64);
carefulunpack<2>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 30), out, in64);
break;
case 4:
carefulunpack<3>(min(static_cast<uint32_t>(end - out), 20), out, in64);
carefulunpack<3>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 20), out, in64);
break;
case 5:
carefulunpack<4>(min(static_cast<uint32_t>(end - out), 15), out, in64);
carefulunpack<4>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 15), out, in64);
break;
case 6:
carefulunpack<5>(min(static_cast<uint32_t>(end - out), 12), out, in64);
carefulunpack<5>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 12), out, in64);
break;
case 7:
carefulunpack<6>(min(static_cast<uint32_t>(end - out), 10), out, in64);
carefulunpack<6>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 10), out, in64);
break;
case 8:
carefulunpack<7>(min(static_cast<uint32_t>(end - out), 8), out, in64);
carefulunpack<7>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 8), out, in64);
break;
case 9:
carefulunpack<8>(min(static_cast<uint32_t>(end - out), 7), out, in64);
carefulunpack<8>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 7), out, in64);
break;
case 10:
carefulunpack<10>(min(static_cast<uint32_t>(end - out), 6), out, in64);
carefulunpack<10>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 6), out, in64);
break;
case 11:
carefulunpack<12>(min(static_cast<uint32_t>(end - out), 5), out, in64);
carefulunpack<12>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 5), out, in64);
break;
case 12:
carefulunpack<15>(min(static_cast<uint32_t>(end - out), 4), out, in64);
carefulunpack<15>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 4), out, in64);
break;
case 13:
carefulunpack<20>(min(static_cast<uint32_t>(end - out), 3), out, in64);
carefulunpack<20>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 3), out, in64);
break;
case 14:
carefulunpack<30>(min(static_cast<uint32_t>(end - out), 2), out, in64);
carefulunpack<30>(std::min<uint32_t>(static_cast<uint32_t>(end - out), 2), out, in64);
break;
case 15:
carefulunpack<60>(1, out, in64);
Expand Down
5 changes: 4 additions & 1 deletion headers/streamvariablebyte.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
* (c) Daniel Lemire, http://lemire.me/en/
*/



#ifndef _STREAMVARIABLEBYTE_
#define _STREAMVARIABLEBYTE_

#if !(defined(_MSC_VER)) // todo : need to be ported to Visual Studio
#include "common.h"
#include "codecs.h"

Expand Down Expand Up @@ -75,3 +77,4 @@ class StreamVByte : public IntegerCODEC {
};
}
#endif
#endif
Loading

0 comments on commit 27c2d8d

Please sign in to comment.