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_;
#define DLOG_IF(severity, condition)
#define DCHECK_LE(val1, val2)
#define DCHECK_GE(val1, val2)
#define DCHECK(condition)
T Value(int64 index) const
ZVector(int64 min_index, int64 max_index)
void Set(int64 index, T value)
T & operator[](int64 index)
bool Reserve(int64 new_min_index, int64 new_max_index)
const T operator[](int64 index) const
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
ZVector< int64 > Int64ZVector
ZVector< uint32 > UInt32ZVector
ZVector< int8 > Int8ZVector
ZVector< int32 > Int32ZVector
ZVector< uint8 > UInt8ZVector
ZVector< uint64 > UInt64ZVector
ZVector< uint16 > UInt16ZVector
ZVector< int16 > Int16ZVector