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 "
98 bool Reserve(int64_t new_min_index, int64_t new_max_index) {
99 if (new_min_index > new_max_index) {
102 const uint64_t 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_t 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)
const T operator[](int64_t index) const
int64_t min_index() const
int64_t max_index() const
bool Reserve(int64_t new_min_index, int64_t new_max_index)
ZVector(int64_t min_index, int64_t max_index)
T Value(int64_t index) const
void Set(int64_t index, T value)
T & operator[](int64_t index)
Collection of objects used to extend the Constraint Solver library.
ZVector< uint8_t > UInt8ZVector
ZVector< int16_t > Int16ZVector
ZVector< uint16_t > UInt16ZVector
ZVector< int64_t > Int64ZVector
ZVector< int8_t > Int8ZVector
ZVector< int32_t > Int32ZVector
ZVector< uint32_t > UInt32ZVector
ZVector< uint64_t > UInt64ZVector