本文整理汇总了C++中PackedVector::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ PackedVector::resize方法的具体用法?C++ PackedVector::resize怎么用?C++ PackedVector::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PackedVector
的用法示例。
在下文中一共展示了PackedVector::resize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resize
inline void PagedVector::resize(const size_t& new_size) {
if (new_size < filled) {
// shrink down to the number of pages we would need
size_t num_pages = new_size == 0 ? 0 : (new_size - 1) / page_size + 1;
anchors.resize(num_pages);
pages.resize(num_pages);
}
else if (new_size > filled) {
// make sure we capacity for this many elements
reserve(new_size);
}
filled = new_size;
}
示例2: resize
inline void PagedVector::resize(size_t new_size) {
// how many pages does this require?
size_t num_pages = new_size > 0 ? (new_size - 1) / page_size + 1 : 0;
anchors.resize(num_pages);
// add pages if necessary
while (num_pages > pages.size()) {
pages.emplace_back();
pages.back().resize(page_size);
}
// remove pages if necessary
pages.resize(num_pages);
filled = new_size;
}
示例3: reserve
inline void PagedVector::reserve(const size_t& future_size) {
if (future_size > pages.size() * page_size) {
// how many pages does this require?
size_t num_pages = (future_size - 1) / page_size + 1;
// note: we don't need to worry about underflow b/c previous condition
// implies future_size > 0
// expand anchor and pages vectors out to the capacity of the number of pages
anchors.reserve(num_pages);
pages.reserve(num_pages);
// add the anchors and fixed-width pages in this
anchors.resize(num_pages);
while (num_pages > pages.size()) {
pages.emplace_back();
pages.back().resize(page_size);
}
}
}