mirror of https://gitee.com/bigwinds/arangodb
updated vpack library
This commit is contained in:
parent
d24b46bb71
commit
2552c3493b
|
@ -110,16 +110,20 @@ class Builder {
|
|||
// at position base, also determine the length len of the attribute.
|
||||
// This takes into account the different possibilities for the format
|
||||
// of attribute names:
|
||||
static uint8_t const* findAttrName(uint8_t const* base, uint64_t& len);
|
||||
static uint8_t const* findAttrName(uint8_t const* base, uint64_t& len,
|
||||
Options const*);
|
||||
|
||||
static void sortObjectIndexShort(uint8_t* objBase,
|
||||
std::vector<ValueLength>& offsets);
|
||||
std::vector<ValueLength>& offsets,
|
||||
Options const*);
|
||||
|
||||
static void sortObjectIndexLong(uint8_t* objBase,
|
||||
std::vector<ValueLength>& offsets);
|
||||
std::vector<ValueLength>& offsets,
|
||||
Options const*);
|
||||
|
||||
static void sortObjectIndex(uint8_t* objBase,
|
||||
std::vector<ValueLength>& offsets);
|
||||
std::vector<ValueLength>& offsets,
|
||||
Options const*);
|
||||
|
||||
public:
|
||||
Options const* options;
|
||||
|
|
|
@ -42,8 +42,8 @@ std::string Builder::toString() const {
|
|||
|
||||
void Builder::doActualSort(std::vector<SortEntry>& entries) {
|
||||
VELOCYPACK_ASSERT(entries.size() > 1);
|
||||
std::sort(entries.begin(), entries.end(),
|
||||
[](SortEntry const& a, SortEntry const& b) {
|
||||
std::sort(entries.begin(), entries.end(), [](SortEntry const& a,
|
||||
SortEntry const& b) {
|
||||
// return true iff a < b:
|
||||
uint8_t const* pa = a.nameStart;
|
||||
uint64_t sizea = a.nameSize;
|
||||
|
@ -56,7 +56,8 @@ void Builder::doActualSort(std::vector<SortEntry>& entries) {
|
|||
});
|
||||
};
|
||||
|
||||
uint8_t const* Builder::findAttrName(uint8_t const* base, uint64_t& len) {
|
||||
uint8_t const* Builder::findAttrName(uint8_t const* base, uint64_t& len,
|
||||
Options const* options) {
|
||||
uint8_t const b = *base;
|
||||
if (b >= 0x40 && b <= 0xbe) {
|
||||
// short UTF-8 string
|
||||
|
@ -72,11 +73,15 @@ uint8_t const* Builder::findAttrName(uint8_t const* base, uint64_t& len) {
|
|||
}
|
||||
return base + 1 + 8; // string starts here
|
||||
}
|
||||
throw Exception(Exception::NotImplemented, "Invalid Object key type");
|
||||
|
||||
// translate attribute name
|
||||
Slice s(base, options);
|
||||
return findAttrName(s.makeKey().start(), len, options);
|
||||
}
|
||||
|
||||
void Builder::sortObjectIndexShort(uint8_t* objBase,
|
||||
std::vector<ValueLength>& offsets) {
|
||||
std::vector<ValueLength>& offsets,
|
||||
Options const* options) {
|
||||
auto cmp = [&](ValueLength a, ValueLength b) -> bool {
|
||||
uint8_t const* aa = objBase + a;
|
||||
uint8_t const* bb = objBase + b;
|
||||
|
@ -88,8 +93,8 @@ void Builder::sortObjectIndexShort(uint8_t* objBase,
|
|||
} else {
|
||||
uint64_t lena;
|
||||
uint64_t lenb;
|
||||
aa = findAttrName(aa, lena);
|
||||
bb = findAttrName(bb, lenb);
|
||||
aa = findAttrName(aa, lena, options);
|
||||
bb = findAttrName(bb, lenb, options);
|
||||
uint64_t m = (std::min)(lena, lenb);
|
||||
int c = memcmp(aa, bb, m);
|
||||
return (c < 0 || (c == 0 && lena < lenb));
|
||||
|
@ -99,7 +104,8 @@ void Builder::sortObjectIndexShort(uint8_t* objBase,
|
|||
}
|
||||
|
||||
void Builder::sortObjectIndexLong(uint8_t* objBase,
|
||||
std::vector<ValueLength>& offsets) {
|
||||
std::vector<ValueLength>& offsets,
|
||||
Options const* options) {
|
||||
// on some platforms we can use a thread-local vector
|
||||
#if __llvm__ == 1
|
||||
// nono thread local
|
||||
|
@ -116,7 +122,7 @@ void Builder::sortObjectIndexLong(uint8_t* objBase,
|
|||
for (ValueLength i = 0; i < offsets.size(); i++) {
|
||||
SortEntry e;
|
||||
e.offset = offsets[i];
|
||||
e.nameStart = findAttrName(objBase + e.offset, e.nameSize);
|
||||
e.nameStart = findAttrName(objBase + e.offset, e.nameSize, options);
|
||||
entries.push_back(e);
|
||||
}
|
||||
VELOCYPACK_ASSERT(entries.size() == offsets.size());
|
||||
|
@ -129,11 +135,12 @@ void Builder::sortObjectIndexLong(uint8_t* objBase,
|
|||
}
|
||||
|
||||
void Builder::sortObjectIndex(uint8_t* objBase,
|
||||
std::vector<ValueLength>& offsets) {
|
||||
std::vector<ValueLength>& offsets,
|
||||
Options const* options) {
|
||||
if (offsets.size() > 32) {
|
||||
sortObjectIndexLong(objBase, offsets);
|
||||
sortObjectIndexLong(objBase, offsets, options);
|
||||
} else {
|
||||
sortObjectIndexShort(objBase, offsets);
|
||||
sortObjectIndexShort(objBase, offsets, options);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -304,7 +311,7 @@ void Builder::close() {
|
|||
if (!options->sortAttributeNames) {
|
||||
_start[tos] = 0x0f; // unsorted
|
||||
} else if (index.size() >= 2 && options->sortAttributeNames) {
|
||||
sortObjectIndex(_start + tos, index);
|
||||
sortObjectIndex(_start + tos, index, options);
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < index.size(); i++) {
|
||||
|
@ -376,7 +383,7 @@ bool Builder::hasKey(std::string const& key) const {
|
|||
}
|
||||
for (size_t i = 0; i < index.size(); ++i) {
|
||||
Slice s(_start + tos + index[i], options);
|
||||
if (s.isString() && s.isEqualString(key)) {
|
||||
if (s.makeKey().isEqualString(key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -398,10 +405,7 @@ Slice Builder::getKey(std::string const& key) const {
|
|||
}
|
||||
for (size_t i = 0; i < index.size(); ++i) {
|
||||
Slice s(_start + tos + index[i], options);
|
||||
if (!s.isString()) {
|
||||
s = s.makeKey();
|
||||
}
|
||||
if (s.isString() && s.isEqualString(key)) {
|
||||
if (s.makeKey().isEqualString(key)) {
|
||||
return Slice(s.start() + s.byteSize(), options);
|
||||
}
|
||||
}
|
||||
|
@ -742,6 +746,7 @@ void Builder::checkAttributeUniqueness(Slice const& obj) const {
|
|||
std::unordered_set<std::string> keys;
|
||||
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
// note: keyAt() already translates integer attributes
|
||||
Slice key = obj.keyAt(i);
|
||||
if (!key.isString()) {
|
||||
throw Exception(Exception::BuilderUnexpectedType,
|
||||
|
|
|
@ -48,10 +48,6 @@ std::ostream& operator<<(std::ostream& stream, HexDump const* hexdump) {
|
|||
for (uint8_t it : hexdump->slice) {
|
||||
if (current != 0) {
|
||||
stream << hexdump->separator;
|
||||
}
|
||||
|
||||
stream << HexDump::toHex(it);
|
||||
++current;
|
||||
|
||||
if (hexdump->valuesPerLine > 0 && current == hexdump->valuesPerLine) {
|
||||
stream << std::endl;
|
||||
|
@ -59,6 +55,10 @@ std::ostream& operator<<(std::ostream& stream, HexDump const* hexdump) {
|
|||
}
|
||||
}
|
||||
|
||||
stream << HexDump::toHex(it);
|
||||
++current;
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
|
|
@ -214,7 +214,9 @@ unsigned int const Slice::FirstSubMap[32] = {
|
|||
|
||||
// translates an integer key into a string
|
||||
Slice Slice::translate() const {
|
||||
VELOCYPACK_ASSERT(isSmallInt() || isUInt());
|
||||
if (!isSmallInt() && !isUInt()) {
|
||||
throw Exception(Exception::NeedAttributeTranslator);
|
||||
}
|
||||
uint64_t id = getUInt();
|
||||
|
||||
if (options->attributeTranslator == nullptr) {
|
||||
|
@ -287,7 +289,7 @@ Slice Slice::get(std::string const& attribute) const {
|
|||
if (!key.isEqualString(attribute)) {
|
||||
return Slice();
|
||||
}
|
||||
} else if (key.isInteger()) {
|
||||
} else if (key.isSmallInt() || key.isUInt()) {
|
||||
// translate key
|
||||
if (!key.translate().isEqualString(attribute)) {
|
||||
return Slice();
|
||||
|
@ -435,7 +437,7 @@ Slice Slice::getFromCompactObject(std::string const& attribute) const {
|
|||
if (key.isEqualString(attribute)) {
|
||||
return Slice(key.start() + key.byteSize(), options);
|
||||
}
|
||||
} else if (key.isInteger()) {
|
||||
} else if (key.isSmallInt() || key.isUInt()) {
|
||||
if (key.translate().isEqualString(attribute)) {
|
||||
return Slice(key.start() + key.byteSize(), options);
|
||||
}
|
||||
|
@ -536,7 +538,7 @@ Slice Slice::makeKey() const {
|
|||
if (isString()) {
|
||||
return *this;
|
||||
}
|
||||
if (isInteger()) {
|
||||
if (isSmallInt() || isUInt()) {
|
||||
return translate();
|
||||
}
|
||||
|
||||
|
@ -580,7 +582,7 @@ Slice Slice::searchObjectKeyLinear(std::string const& attribute,
|
|||
if (!key.isEqualString(attribute)) {
|
||||
continue;
|
||||
}
|
||||
} else if (key.isInteger()) {
|
||||
} else if (key.isSmallInt() || key.isUInt()) {
|
||||
// translate key
|
||||
if (!key.translate().isEqualString(attribute)) {
|
||||
continue;
|
||||
|
@ -618,7 +620,7 @@ Slice Slice::searchObjectKeyBinary(std::string const& attribute,
|
|||
int res;
|
||||
if (key.isString()) {
|
||||
res = key.compareString(attribute);
|
||||
} else if (key.isInteger()) {
|
||||
} else if (key.isSmallInt() || key.isUInt()) {
|
||||
// translate key
|
||||
res = key.translate().compareString(attribute);
|
||||
} else {
|
||||
|
|
|
@ -47,12 +47,9 @@ int fpconv_dtoa(double fp, char dest[24]);
|
|||
|
||||
static uint64_t tens[] = {
|
||||
10000000000000000000U, 1000000000000000000U, 100000000000000000U,
|
||||
10000000000000000U, 1000000000000000U, 100000000000000U,
|
||||
10000000000000U, 1000000000000U, 100000000000U,
|
||||
10000000000U, 1000000000U, 100000000U,
|
||||
10000000U, 1000000U, 100000U,
|
||||
10000U, 1000U, 100U,
|
||||
10U, 1U};
|
||||
10000000000000000U, 1000000000000000U, 100000000000000U, 10000000000000U,
|
||||
1000000000000U, 100000000000U, 10000000000U, 1000000000U, 100000000U,
|
||||
10000000U, 1000000U, 100000U, 10000U, 1000U, 100U, 10U, 1U};
|
||||
|
||||
static inline uint64_t get_dbits(double d) {
|
||||
union {
|
||||
|
|
Loading…
Reference in New Issue