14 #ifndef OR_TOOLS_UTIL_ZVECTOR_H_
15 #define OR_TOOLS_UTIL_ZVECTOR_H_
17 #if (defined(__APPLE__) || defined(__FreeBSD__)) && defined(__GNUC__)
18 #include <machine/endian.h>
19 #elif !defined(_MSC_VER)
48 : base_(nullptr), min_index_(0), max_index_(-1), size_(0), storage_() {}
51 : base_(nullptr), min_index_(0), max_index_(-1), size_(0), storage_() {
53 LOG(DFATAL) <<
"Could not reserve memory for indices ranging from "
99 if (new_min_index > new_max_index) {
102 const uint64 new_size = new_max_index - new_min_index + 1;
103 if (base_ !=
nullptr) {
104 if (new_min_index >= min_index_ && new_max_index <= max_index_) {
105 min_index_ = new_min_index;
106 max_index_ = new_max_index;
109 }
else if (new_min_index > min_index_ || new_max_index < max_index_) {
113 T* new_storage =
new T[new_size];
114 if (new_storage ==
nullptr) {
118 T*
const new_base = new_storage - new_min_index;
119 if (base_ !=
nullptr) {
120 T*
const destination = new_base + min_index_;
121 memcpy(destination, storage_.get(), size_ *
sizeof(*base_));
126 min_index_ = new_min_index;
127 max_index_ = new_max_index;
128 storage_.reset(new_storage);
135 <<
"Trying to set values to uninitialized vector.";
136 for (
int64 i = 0; i < size_; ++i) {
137 base_[min_index_ + i] =
value;
155 std::unique_ptr<T[]> storage_;
170 #endif // OR_TOOLS_UTIL_ZVECTOR_H_