inline void PackedVector::resize(size_t new_size) { if (new_size < filled) { size_t shrink_capacity = vec.size() / (factor * factor); if (new_size < shrink_capacity) { sdsl::int_vector<> tmp; tmp.width(vec.width()); tmp.resize(new_size); for (size_t i = 0; i < new_size; i++) { tmp[i] = vec[i]; } vec = std::move(tmp); } } else if (new_size > vec.size()) { size_t new_capacity = std::max<size_t>(size_t(vec.size() * factor) + 1, new_size); sdsl::int_vector<> tmp; tmp.width(vec.width()); tmp.resize(new_capacity); for (size_t i = 0; i < filled; i++) { tmp[i] = vec[i]; } vec = std::move(tmp); } filled = new_size; }
inline void PackedVector::reserve(const size_t& future_size) { if (future_size > vec.size()) { sdsl::int_vector<> tmp; tmp.width(vec.width()); tmp.resize(future_size); for (size_t i = 0; i < filled; i++) { tmp[i] = vec[i]; } vec = std::move(tmp); } }
inline void PackedVector::set(const size_t& i, const uint64_t& value) { assert(i < filled); uint8_t width = vec.width(); uint64_t mask = std::numeric_limits<uint64_t>::max() << width; while (mask & value) { width++; mask = std::numeric_limits<uint64_t>::max() << width; } if (width > vec.width()) { sdsl::int_vector<> wider_vec; wider_vec.width(width); wider_vec.resize(vec.size()); for (size_t i = 0; i < filled; i++) { wider_vec[i] = vec[i]; } vec = std::move(wider_vec); } vec[i] = value; }
inline void PackedVector::clear() { vec.resize(0); vec.width(1); filled = 0; }