forked from mindspore-Ecosystem/mindspore
commit
42a11b2a45
|
@ -23,15 +23,12 @@ template <typename K, typename V, typename A, typename C, typename T>
|
|||
typename BPlusTree<K, V, A, C, T>::IndexRc BPlusTree<K, V, A, C, T>::InnerNode::Sort() {
|
||||
// Build an inverse map. Basically it means keys[i] should be relocated to keys[inverse[i]];
|
||||
slot_allocator alloc(this->alloc_);
|
||||
slot_type *inverse = nullptr;
|
||||
try {
|
||||
inverse = alloc.allocate(traits::kInnerSlots);
|
||||
} catch (std::bad_alloc &e) {
|
||||
return IndexRc::kOutOfMemory;
|
||||
} catch (std::exception &e) {
|
||||
return IndexRc::kUnexpectedError;
|
||||
}
|
||||
|
||||
// We use a unique_ptr will custom deleter to ensure the memory will be released when this
|
||||
// function returns.
|
||||
std::unique_ptr<slot_type[], std::function<void(slot_type *)>> memGuard(
|
||||
alloc.allocate(traits::kInnerSlots), [&alloc](slot_type *p) { alloc.deallocate(p, traits::kInnerSlots); });
|
||||
slot_type *inverse = memGuard.get();
|
||||
for (slot_type i = 0; i < slotuse_; i++) {
|
||||
inverse[slot_dir_[i]] = i;
|
||||
}
|
||||
|
@ -53,11 +50,12 @@ typename BPlusTree<K, V, A, C, T>::IndexRc BPlusTree<K, V, A, C, T>::InnerNode::
|
|||
}
|
||||
slot_dir_[i] = i;
|
||||
}
|
||||
if (inverse != nullptr) {
|
||||
alloc.deallocate(inverse, traits::kInnerSlots);
|
||||
inverse = nullptr;
|
||||
}
|
||||
return IndexRc::kOk;
|
||||
} catch (std::bad_alloc &e) {
|
||||
return IndexRc::kOutOfMemory;
|
||||
} catch (std::exception &e) {
|
||||
return IndexRc::kUnexpectedError;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename K, typename V, typename A, typename C, typename T>
|
||||
|
@ -117,15 +115,12 @@ template <typename K, typename V, typename A, typename C, typename T>
|
|||
typename BPlusTree<K, V, A, C, T>::IndexRc BPlusTree<K, V, A, C, T>::LeafNode::Sort() {
|
||||
// Build an inverse map. Basically it means keys[i] should be relocated to keys[inverse[i]];
|
||||
slot_allocator alloc(this->alloc_);
|
||||
slot_type *inverse = nullptr;
|
||||
try {
|
||||
inverse = alloc.allocate(traits::kLeafSlots);
|
||||
} catch (std::bad_alloc &e) {
|
||||
return IndexRc::kOutOfMemory;
|
||||
} catch (std::exception &e) {
|
||||
return IndexRc::kUnexpectedError;
|
||||
}
|
||||
|
||||
// We use a unique_ptr will custom deleter to ensure the memory will be released when this
|
||||
// function returns.
|
||||
std::unique_ptr<slot_type[], std::function<void(slot_type *)>> memGuard(
|
||||
alloc.allocate(traits::kLeafSlots), [&alloc](slot_type *p) { alloc.deallocate(p, traits::kLeafSlots); });
|
||||
slot_type *inverse = memGuard.get();
|
||||
for (slot_type i = 0; i < slotuse_; i++) {
|
||||
inverse[slot_dir_[i]] = i;
|
||||
}
|
||||
|
@ -147,11 +142,12 @@ typename BPlusTree<K, V, A, C, T>::IndexRc BPlusTree<K, V, A, C, T>::LeafNode::S
|
|||
}
|
||||
slot_dir_[i] = i;
|
||||
}
|
||||
if (inverse != nullptr) {
|
||||
alloc.deallocate(inverse, traits::kLeafSlots);
|
||||
inverse = nullptr;
|
||||
}
|
||||
return IndexRc::kOk;
|
||||
} catch (std::bad_alloc &e) {
|
||||
return IndexRc::kOutOfMemory;
|
||||
} catch (std::exception &e) {
|
||||
return IndexRc::kUnexpectedError;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename K, typename V, typename A, typename C, typename T>
|
||||
|
|
Loading…
Reference in New Issue