From: Mikko Rasa Date: Sat, 18 Sep 2021 00:21:18 +0000 (+0300) Subject: Use the standard fixed-size integer types directly X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=commitdiff_plain;h=b116e161e377da0e4e52f07745ecb2d22f962ae9 Use the standard fixed-size integer types directly --- diff --git a/source/core/hash.cpp b/source/core/hash.cpp index fe5e339..aed9ed1 100644 --- a/source/core/hash.cpp +++ b/source/core/hash.cpp @@ -10,7 +10,7 @@ http://en.wikipedia.org/wiki/Fowler-Noll-Vo_hash_function http://www.isthe.com/chongo/tech/comp/fnv/index.html */ -UInt32 hash32(const void *data, unsigned size, unsigned bits) +uint32_t hash32(const void *data, unsigned size, unsigned bits) { if(bits==0 || bits>32) throw invalid_argument("hash32"); @@ -28,15 +28,15 @@ UInt32 hash32(const void *data, unsigned size, unsigned bits) return result; } -UInt64 hash64(const void *data, unsigned size, unsigned bits) +uint64_t hash64(const void *data, unsigned size, unsigned bits) { if(bits==0 || bits>64) throw invalid_argument("hash64"); - static const UInt64 prime = 1099511628211ULL; - static const UInt64 offset = 14695981039346656037ULL; + static const uint64_t prime = 1099511628211ULL; + static const uint64_t offset = 14695981039346656037ULL; - UInt64 result = offset; + uint64_t result = offset; for(unsigned i=0; i(data)+i))*prime; diff --git a/source/core/hash.h b/source/core/hash.h index d696cae..85ee5dd 100644 --- a/source/core/hash.h +++ b/source/core/hash.h @@ -1,8 +1,8 @@ #ifndef MSP_CORE_HASH_H_ #define MSP_CORE_HASH_H_ +#include #include -#include "inttypes.h" namespace Msp { @@ -11,7 +11,7 @@ Computes a 32-bit Fowler-Noll-Vo (FNV-1a) hash. The number of bits can be limited to less than 32, in which case XOR-folding is used to reduce the hash size. */ -UInt32 hash32(const void *, unsigned, unsigned = 32); +std::uint32_t hash32(const void *, unsigned, unsigned = 32); /** Convenience function to compute a 32-bit hash of a string. @@ -23,18 +23,18 @@ inline unsigned hash32(const std::string &s, unsigned b = 32) Computes a 64-bit Fowler-Noll-Vo (FNV-1a) hash. Note that even if bits is limited to 32 or less, this does not produce the same result as hash32. */ -UInt64 hash64(const void *, unsigned, unsigned = 64); +std::uint64_t hash64(const void *, unsigned, unsigned = 64); /** Convenience function to compute a 64-bit hash of a string. */ -inline UInt64 hash64(const std::string &s, unsigned b = 64) +inline std::uint64_t hash64(const std::string &s, unsigned b = 64) { return hash64(s.data(), s.size(), b); } -inline UInt32 fold32(UInt64 hash) +inline std::uint32_t fold32(std::uint64_t hash) { return hash^(hash>>32); } -inline UInt16 fold16(UInt64 hash) +inline std::uint16_t fold16(std::uint64_t hash) { return hash^(hash>>16)^(hash>>32)^(hash>>48); } } // namespace Msp diff --git a/source/fs/stat.h b/source/fs/stat.h index 3f056a5..e2400ed 100644 --- a/source/fs/stat.h +++ b/source/fs/stat.h @@ -1,8 +1,8 @@ #ifndef MSP_FS_STAT_H_ #define MSP_FS_STAT_H_ +#include #include -#include #include #include "path.h" @@ -17,7 +17,7 @@ enum FileType SYMLINK }; -typedef UInt64 FileSize; +typedef uint64_t FileSize; /** Holds file information. diff --git a/source/io/seekable.h b/source/io/seekable.h index f0170b4..99915d8 100644 --- a/source/io/seekable.h +++ b/source/io/seekable.h @@ -1,8 +1,8 @@ #ifndef MSP_IO_SEEKABLE_H_ #define MSP_IO_SEEKABLE_H_ +#include #include -#include #include "base.h" namespace Msp { @@ -10,7 +10,7 @@ namespace IO { class Handle; -typedef Int64 SeekOffset; +typedef std::int64_t SeekOffset; enum SeekType { diff --git a/source/strings/lexicalcast.cpp b/source/strings/lexicalcast.cpp index 2c867b2..2b84d9b 100644 --- a/source/strings/lexicalcast.cpp +++ b/source/strings/lexicalcast.cpp @@ -1,6 +1,6 @@ #include +#include #include -#include #include "format.h" #include "lexicalcast.h" @@ -557,7 +557,7 @@ void operator<<(LexicalConverter &c, const char *s) { c.result(str_to_str(s, c.get_fmt())); } void operator<<(LexicalConverter &c, const void *p) -{ c.result(int_to_str(reinterpret_cast(p), c.get_fmt())); } +{ c.result(int_to_str(reinterpret_cast(p), c.get_fmt())); } /*** operator>> ***/ diff --git a/source/time/rawtime.h b/source/time/rawtime.h index 1af7956..46b3e4d 100644 --- a/source/time/rawtime.h +++ b/source/time/rawtime.h @@ -1,12 +1,12 @@ #ifndef MSP_TIME_RAWTIME_H_ #define MSP_TIME_RAWTIME_H_ -#include +#include namespace Msp { namespace Time { -typedef Int64 RawTime; +typedef std::int64_t RawTime; } // namespace Time } // namespace Msp