diff --git a/ortools/base/bitmap.cc b/ortools/base/bitmap.cc index 8d83274111..f5ef95878d 100644 --- a/ortools/base/bitmap.cc +++ b/ortools/base/bitmap.cc @@ -19,13 +19,13 @@ namespace operations_research { -void Bitmap::Resize(uint32 size, bool fill) { - const uint32 new_array_size = internal::BitLength64(size); - const uint32 old_max_size = max_size_; +void Bitmap::Resize(uint32_t size, bool fill) { + const uint32_t new_array_size = internal::BitLength64(size); + const uint32_t old_max_size = max_size_; if (new_array_size <= array_size_) { max_size_ = size; } else { - const uint32 old_array_size = array_size_; + const uint32_t old_array_size = array_size_; array_size_ = new_array_size; max_size_ = size; uint64_t* new_map = new uint64_t[array_size_]; @@ -34,7 +34,7 @@ void Bitmap::Resize(uint32 size, bool fill) { map_ = new_map; } // TODO(user) : optimize next loop. - for (uint32 index = old_max_size; index < size; ++index) { + for (uint32_t index = old_max_size; index < size; ++index) { Set(index, fill); } } diff --git a/ortools/base/bitmap.h b/ortools/base/bitmap.h index 67654f9106..70aa9082e4 100644 --- a/ortools/base/bitmap.h +++ b/ortools/base/bitmap.h @@ -37,9 +37,9 @@ inline void ClearBit64(uint64_t* const bitset, uint64_t pos) { class Bitmap { public: - // Constructor : This allocates on a uint32 boundary. + // Constructor : This allocates on a uint32_t boundary. // fill: true = initialize with 1's, false = initialize with 0's. - explicit Bitmap(uint32 size, bool fill = false) + explicit Bitmap(uint32_t size, bool fill = false) : max_size_(size), array_size_(internal::BitLength64(size)), map_(new uint64_t[array_size_]) { @@ -53,13 +53,13 @@ class Bitmap { // Resizes the bitmap. // If size < bits(), the extra bits will be discarded. // If size > bits(), the extra bits will be filled with the fill value. - void Resize(uint32 size, bool fill = false); + void Resize(uint32_t size, bool fill = false); - bool Get(uint32 index) const { + bool Get(uint32_t index) const { assert(max_size_ == 0 || index < max_size_); return internal::IsBitSet64(map_, index); } - void Set(uint32 index, bool value) { + void Set(uint32_t index, bool value) { assert(max_size_ == 0 || index < max_size_); if (value) { internal::SetBit64(map_, index); @@ -77,8 +77,8 @@ class Bitmap { void Clear() { SetAll(false); } private: - uint32 max_size_; // the upper bound of the bitmap - uint32 array_size_; + uint32_t max_size_; // the upper bound of the bitmap + uint32_t array_size_; uint64_t* map_; // the bitmap }; diff --git a/ortools/base/hash.h b/ortools/base/hash.h index 4f38dede2c..de27517395 100644 --- a/ortools/base/hash.h +++ b/ortools/base/hash.h @@ -25,7 +25,7 @@ namespace operations_research { // 32 bit version. -static inline void mix(uint32& a, uint32& b, uint32& c) { // NOLINT +static inline void mix(uint32_t& a, uint32_t& b, uint32_t& c) { // NOLINT a -= b; a -= c; a ^= (c >> 13); @@ -94,8 +94,8 @@ static inline void mix(uint64_t& a, uint64_t& b, uint64_t& c) { // NOLINT c -= b; c ^= (b >> 22); } -inline uint32 Hash32NumWithSeed(uint32 num, uint32 c) { - uint32 b = 0x9e3779b9UL; // The golden ratio; an arbitrary value. +inline uint32_t Hash32NumWithSeed(uint32_t num, uint32_t c) { + uint32_t b = 0x9e3779b9UL; // The golden ratio; an arbitrary value. operations_research::mix(num, b, c); return c; } @@ -115,7 +115,7 @@ struct hash> { size_t h1 = hash()(p.first); size_t h2 = hash()(p.second); // The decision below is at compile time - return (sizeof(h1) <= sizeof(uint32)) + return (sizeof(h1) <= sizeof(uint32_t)) ? // NOLINT operations_research::Hash32NumWithSeed(h1, h2) : operations_research::Hash64NumWithSeed(h1, h2); diff --git a/ortools/base/int_type.h b/ortools/base/int_type.h index dd21976053..c5eaf58836 100644 --- a/ortools/base/int_type.h +++ b/ortools/base/int_type.h @@ -16,7 +16,7 @@ // as native integer types, but which prevent assignment, construction, and // other operations from other similar integer-like types. Essentially, the // template class IntType (where ValueType assumes -// valid scalar types such as int, uint, int32, etc) has the additional +// valid scalar types such as int, uint, int32_t, etc) has the additional // property that it cannot be assigned to or constructed from other IntTypes // or native integer types of equal or implicitly convertible type. // @@ -67,7 +67,7 @@ // GetGlobalDoc(global); <-- Fails to compile! // GetGlobalDoc(local); <-- Fails to compile! // -// void GetLocalDoc(int32 local) { ... +// void GetLocalDoc(int32_t local) { ... // GetLocalDoc(global); <-- Fails to compile! // GetLocalDoc(local); <-- Fails to compile! // diff --git a/ortools/base/logging.cc b/ortools/base/logging.cc index ce4bb40990..155232fe1f 100644 --- a/ortools/base/logging.cc +++ b/ortools/base/logging.cc @@ -302,7 +302,7 @@ static const char* GetAnsiColorCode(GLogColor color) { #endif // !_MSC_VER // Safely get max_log_size, overriding to 1 if it somehow gets defined as 0 -static int32 MaxLogSize() { +static int32_t MaxLogSize() { return (absl::GetFlag(FLAGS_max_log_size) > 0 ? absl::GetFlag(FLAGS_max_log_size) : 1); @@ -389,7 +389,7 @@ class LogFileObject : public base::Logger { // It is the actual file length for the system loggers, // i.e., INFO, ERROR, etc. - virtual uint32 LogSize() { + virtual uint32_t LogSize() { absl::MutexLock l(&lock_); return file_length_; } @@ -400,7 +400,7 @@ class LogFileObject : public base::Logger { void FlushUnlocked(); private: - static const uint32 kRolloverAttemptFrequency = 0x20; + static const uint32_t kRolloverAttemptFrequency = 0x20; absl::Mutex lock_; bool base_filename_selected_; @@ -409,9 +409,9 @@ class LogFileObject : public base::Logger { string filename_extension_; // option users can specify (eg to add port#) FILE* file_; LogSeverity severity_; - uint32 bytes_since_flush_; - uint32 dropped_mem_length_; - uint32 file_length_; + uint32_t bytes_since_flush_; + uint32_t dropped_mem_length_; + uint32_t file_length_; unsigned int rollover_attempt_; int64_t next_flush_time_; // cycle count at which to flush log @@ -1023,8 +1023,8 @@ void LogFileObject::Write(bool force_flush, time_t timestamp, if (absl::GetFlag(FLAGS_drop_log_memory) && file_length_ >= (3 << 20)) { // Don't evict the most recent 1-2MiB so as not to impact a tailer // of the log file and to avoid page rounding issue on linux < 4.7 - uint32 total_drop_length = (file_length_ & ~((1 << 20) - 1)) - (1 << 20); - uint32 this_drop_length = total_drop_length - dropped_mem_length_; + uint32_t total_drop_length = (file_length_ & ~((1 << 20) - 1)) - (1 << 20); + uint32_t this_drop_length = total_drop_length - dropped_mem_length_; if (this_drop_length >= (2 << 20)) { // Only advise when >= 2MiB to drop posix_fadvise(fileno(file_), dropped_mem_length_, this_drop_length, diff --git a/ortools/base/logging.h b/ortools/base/logging.h index 9fa32a6e20..0da24cefc2 100644 --- a/ortools/base/logging.h +++ b/ortools/base/logging.h @@ -1403,7 +1403,7 @@ class GOOGLE_GLOG_DLL_DECL Logger { // Get the current LOG file size. // The returned value is approximate since some // logged data may not have been flushed to disk yet. - virtual uint32 LogSize() = 0; + virtual uint32_t LogSize() = 0; }; // Get the logger for the specified severity level. The logger diff --git a/ortools/base/logging_utilities.cc b/ortools/base/logging_utilities.cc index 059d056ca7..e5c6cba63b 100644 --- a/ortools/base/logging_utilities.cc +++ b/ortools/base/logging_utilities.cc @@ -232,8 +232,8 @@ int64_t CycleClock_Now() { return absl::ToUnixMicros(absl::Now()); } int64_t UsecToCycles(int64_t usec) { return usec; } -static int32 g_main_thread_pid = getpid(); -int32 GetMainThreadPid() { return g_main_thread_pid; } +static int32_t g_main_thread_pid = getpid(); +int32_t GetMainThreadPid() { return g_main_thread_pid; } const char* const_basename(const char* filepath) { const char* base = strrchr(filepath, '/'); diff --git a/ortools/base/logging_utilities.h b/ortools/base/logging_utilities.h index 20dd282d9f..6a7c6fdb46 100644 --- a/ortools/base/logging_utilities.h +++ b/ortools/base/logging_utilities.h @@ -32,7 +32,7 @@ int64_t CycleClock_Now(); int64_t UsecToCycles(int64_t usec); -int32 GetMainThreadPid(); +int32_t GetMainThreadPid(); unsigned int GetTID(); diff --git a/ortools/base/random.cc b/ortools/base/random.cc index 30668fbf0a..853f15c8ac 100644 --- a/ortools/base/random.cc +++ b/ortools/base/random.cc @@ -33,11 +33,11 @@ namespace operations_research { -uint32 ACMRandom::Next() { - return absl::uniform_int_distribution(0, kuint32max)(generator_); +uint32_t ACMRandom::Next() { + return absl::uniform_int_distribution(0, kuint32max)(generator_); } -uint32 ACMRandom::Uniform(uint32 n) { return n == 0 ? 0 : Next() % n; } +uint32_t ACMRandom::Uniform(uint32_t n) { return n == 0 ? 0 : Next() % n; } uint64_t ACMRandom::Next64() { return absl::uniform_int_distribution(0, kuint64max)(generator_); @@ -48,47 +48,47 @@ uint64_t ACMRandom::operator()(uint64_t val_max) { } namespace { -static inline uint32 Word32At(const char* ptr) { - return ((static_cast(ptr[0])) + (static_cast(ptr[1]) << 8) + - (static_cast(ptr[2]) << 16) + - (static_cast(ptr[3]) << 24)); +static inline uint32_t Word32At(const char* ptr) { + return ((static_cast(ptr[0])) + (static_cast(ptr[1]) << 8) + + (static_cast(ptr[2]) << 16) + + (static_cast(ptr[3]) << 24)); } } // namespace -int32 ACMRandom::HostnamePidTimeSeed() { - char name[PATH_MAX + 20]; // need 12 bytes for 3 'empty' uint32's - assert(sizeof(name) - PATH_MAX > sizeof(uint32) * 3); +int32_t ACMRandom::HostnamePidTimeSeed() { + char name[PATH_MAX + 20]; // need 12 bytes for 3 'empty' uint32_t's + assert(sizeof(name) - PATH_MAX > sizeof(uint32_t) * 3); if (gethostname(name, PATH_MAX) != 0) { strcpy(name, "default-hostname"); // NOLINT } const int namelen = strlen(name); - for (size_t i = 0; i < sizeof(uint32) * 3; ++i) { + for (size_t i = 0; i < sizeof(uint32_t) * 3; ++i) { name[namelen + i] = '\0'; // so we mix 0's once we get to end-of-string } #if defined(__GNUC__) - uint32 a = getpid(); + uint32_t a = getpid(); struct timeval tv; gettimeofday(&tv, NULL); - uint32 b = static_cast((tv.tv_sec + tv.tv_usec) & 0xffffffff); + uint32_t b = static_cast((tv.tv_sec + tv.tv_usec) & 0xffffffff); #elif defined(_MSC_VER) - uint32 a = GetCurrentProcessId(); - uint32 b = GetTickCount(); + uint32_t a = GetCurrentProcessId(); + uint32_t b = GetTickCount(); #else // Do not know what to do, returning 0. return 0; #endif - uint32 c = 0; - for (int i = 0; i < namelen; i += sizeof(uint32) * 3) { + uint32_t c = 0; + for (int i = 0; i < namelen; i += sizeof(uint32_t) * 3) { a += Word32At(name + i); - b += Word32At(name + i + sizeof(uint32)); - c += Word32At(name + i + sizeof(uint32) + sizeof(uint32)); + b += Word32At(name + i + sizeof(uint32_t)); + c += Word32At(name + i + sizeof(uint32_t) + sizeof(uint32_t)); mix(a, b, c); } c += namelen; // one final mix mix(a, b, c); - return static_cast(c); // I guess the seed can be negative + return static_cast(c); // I guess the seed can be negative } -int32 ACMRandom::DeterministicSeed() { return 0; } +int32_t ACMRandom::DeterministicSeed() { return 0; } } // namespace operations_research diff --git a/ortools/base/random.h b/ortools/base/random.h index b840e7dbab..84cd57bf0f 100644 --- a/ortools/base/random.h +++ b/ortools/base/random.h @@ -25,22 +25,22 @@ namespace operations_research { // A wrapper around std::mt19937. Called ACMRandom for historical reasons. class ACMRandom { public: - explicit ACMRandom(int32 seed) : generator_(seed) {} + explicit ACMRandom(int32_t seed) : generator_(seed) {} // Unbounded generators. - uint32 Next(); + uint32_t Next(); uint64_t Next64(); uint64_t Rand64() { return Next64(); } uint64_t operator()() { return Next64(); } // Bounded generators. - uint32 Uniform(uint32 n); + uint32_t Uniform(uint32_t n); uint64_t operator()(uint64_t val_max); // Seed management. - void Reset(int32 seed) { generator_.seed(seed); } - static int32 HostnamePidTimeSeed(); - static int32 DeterministicSeed(); + void Reset(int32_t seed) { generator_.seed(seed); } + static int32_t HostnamePidTimeSeed(); + static int32_t DeterministicSeed(); // C++11 goodies. typedef int64_t difference_type; @@ -54,7 +54,7 @@ class ACMRandom { class MTRandom : public ACMRandom { public: - explicit MTRandom(int32 seed) : ACMRandom(seed) {} + explicit MTRandom(int32_t seed) : ACMRandom(seed) {} // MTRandom also supports a std::string seed. explicit MTRandom(const std::string& str_seed) : ACMRandom(GenerateInt32SeedFromString(str_seed)) {} @@ -62,13 +62,13 @@ class MTRandom : public ACMRandom { MTRandom() : ACMRandom(ACMRandom::HostnamePidTimeSeed()) {} private: - int32 GenerateInt32SeedFromString(const std::string& str) { - uint32 seed = 1234567; + int32_t GenerateInt32SeedFromString(const std::string& str) { + uint32_t seed = 1234567; for (size_t i = 0; i < str.size(); ++i) { seed *= 1000003; // prime - seed += static_cast(str[i]); + seed += static_cast(str[i]); } - return seed >> 1; // Will fit into an int32. + return seed >> 1; // Will fit into an int32_t. } }; diff --git a/ortools/base/strong_vector.h b/ortools/base/strong_vector.h index b73f44a003..4719ca910c 100644 --- a/ortools/base/strong_vector.h +++ b/ortools/base/strong_vector.h @@ -35,19 +35,19 @@ // // EXAMPLES -------------------------------------------------------------------- // -// DEFINE_INT_TYPE(PhysicalChildIndex, int32); +// DEFINE_INT_TYPE(PhysicalChildIndex, int32_t); // absl::StrongVector vec; // // PhysicalChildIndex physical_index; // vec[physical_index] = ...; <-- index type match: compiles properly. // vec.at(physical_index) = ...; <-- index type match: compiles properly. // -// int32 physical_index; +// int32_t physical_index; // vec[physical_index] = ...; <-- fails to compile. // vec.at(physical_index) = ...; <-- fails to compile. // -// DEFINE_INT_TYPE(LogicalChildIndex, int32); -// int32 logical_index; +// DEFINE_INT_TYPE(LogicalChildIndex, int32_t); +// int32_t logical_index; // vec[logical_index] = ...; <-- fails to compile. // vec.at(logical_index) = ...; <-- fails to compile. // diff --git a/ortools/base/vlog_is_on.cc b/ortools/base/vlog_is_on.cc index 6a96d0e478..3fc7d4b53d 100644 --- a/ortools/base/vlog_is_on.cc +++ b/ortools/base/vlog_is_on.cc @@ -87,7 +87,7 @@ GOOGLE_GLOG_DLL_DECL bool SafeFNMatch_(const char* pattern, size_t patt_len, using logging_internal::SafeFNMatch_; -int32 kLogSiteUninitialized = 1000; +int32_t kLogSiteUninitialized = 1000; // List of per-module log levels from absl::GetFlag(FLAGS_vmodule). // Once created each element is never deleted/modified @@ -98,7 +98,7 @@ int32 kLogSiteUninitialized = 1000; // when it's safe to delete/update it: other threads need to use it w/o locks. struct VModuleInfo { string module_pattern; - mutable int32 vlog_level; // Conceptually this is an AtomicWord, but it's + mutable int32_t vlog_level; // Conceptually this is an AtomicWord, but it's // too much work to use AtomicWord type here // w/o much actual benefit. const VModuleInfo* next; @@ -183,8 +183,8 @@ int SetVLOGLevel(const char* module_pattern, int log_level) { // NOTE: Individual VLOG statements cache the integer log level pointers. // NOTE: This function must not allocate memory or require any locks. -bool InitVLOG3__(int32** site_flag, int32* site_default, const char* fname, - int32 verbose_level) { +bool InitVLOG3__(int32_t** site_flag, int32_t* site_default, const char* fname, + int32_t verbose_level) { absl::MutexLock l(&vmodule_lock); bool read_vmodule_flag = inited_vmodule; if (!read_vmodule_flag) { @@ -196,7 +196,7 @@ bool InitVLOG3__(int32** site_flag, int32* site_default, const char* fname, int old_errno = errno; // site_default normally points to absl::GetFlag(FLAGS_v) - int32* site_flag_value = site_default; + int32_t* site_flag_value = site_default; // Get basename for file const char* base = strrchr(fname, '/'); diff --git a/ortools/base/vlog_is_on.h b/ortools/base/vlog_is_on.h index 501f503768..38fea75e9e 100644 --- a/ortools/base/vlog_is_on.h +++ b/ortools/base/vlog_is_on.h @@ -28,8 +28,8 @@ namespace google { // parsing of --vmodule flag and/or SetVLOGLevel calls. #define VLOG_IS_ON(verboselevel) \ __extension__({ \ - static int32* vlocal__ = &google::kLogSiteUninitialized; \ - int32 verbose_level__ = (verboselevel); \ + static int32_t* vlocal__ = &google::kLogSiteUninitialized; \ + int32_t verbose_level__ = (verboselevel); \ (*vlocal__ >= verbose_level__) && \ ((vlocal__ != &google::kLogSiteUninitialized) || \ (google::InitVLOG3__(&vlocal__, &absl::GetFlag(FLAGS_v), __FILE__, \ @@ -58,7 +58,7 @@ extern GOOGLE_GLOG_DLL_DECL int SetVLOGLevel(const char* module_pattern, // initialized. We make this a large value, so the common-case check // of "*vlocal__ >= verbose_level__" in VLOG_IS_ON definition // passes in such cases and InitVLOG3__ is then triggered. -extern int32 kLogSiteUninitialized; +extern int32_t kLogSiteUninitialized; // Helper routine which determines the logging info for a particalur VLOG site. // site_flag is the address of the site-local pointer to the controlling @@ -68,10 +68,10 @@ extern int32 kLogSiteUninitialized; // verbose_level is the argument to VLOG_IS_ON // We will return the return value for VLOG_IS_ON // and if possible set *site_flag appropriately. -extern GOOGLE_GLOG_DLL_DECL bool InitVLOG3__(int32** site_flag, - int32* site_default, +extern GOOGLE_GLOG_DLL_DECL bool InitVLOG3__(int32_t** site_flag, + int32_t* site_default, const char* fname, - int32 verbose_level); + int32_t verbose_level); } // namespace google