diff --git a/include/consthash/cityhash128.hxx b/include/consthash/cityhash128.hxx index 0ee9ebe..026ac7c 100644 --- a/include/consthash/cityhash128.hxx +++ b/include/consthash/cityhash128.hxx @@ -199,6 +199,10 @@ constexpr uint128_t city128(const char *s, size_t len) { return __detail::CityHash128(s, len); } +constexpr uint128_t city128(const char *s) { + return __detail::CityHash128(s, __detail::str_len(s)); +} + constexpr uint128_t city128_seed(const char *s, size_t len, uint128_t seed) { return __detail::CityHash128WithSeed(s, len, seed); } diff --git a/include/consthash/cityhash32.hxx b/include/consthash/cityhash32.hxx index 195fdab..4968386 100644 --- a/include/consthash/cityhash32.hxx +++ b/include/consthash/cityhash32.hxx @@ -93,6 +93,10 @@ constexpr uint32_t city32(const char* s, size_t len) { return __detail::city32impl(s, len); } +constexpr uint32_t city32(const char* s) { + return __detail::city32impl(s, __detail::str_len(s)); +} + CONSTHASH_NAMESPACE_END; #endif // _CONSTHASH_CITYHASH32_HXX diff --git a/include/consthash/cityhash64.hxx b/include/consthash/cityhash64.hxx index e3b15f5..bc6af97 100644 --- a/include/consthash/cityhash64.hxx +++ b/include/consthash/cityhash64.hxx @@ -69,6 +69,11 @@ constexpr uint64_t city64(const char *buf, size_t len) return __detail::city64impl(buf, len); } +constexpr uint64_t city64(const char *buf) +{ + return __detail::city64impl(buf, __detail::str_len(buf)); +} + // Hash function for a byte array. For convenience, a 64-bit seed is also // hashed into the result. constexpr uint64_t city64_seed(const char *buf, size_t len, uint64_t seed) diff --git a/include/consthash/common.hxx b/include/consthash/common.hxx index 4e125fb..21f6376 100644 --- a/include/consthash/common.hxx +++ b/include/consthash/common.hxx @@ -24,6 +24,11 @@ struct ensure static constexpr void ct() { } }; +constexpr size_t str_len(const char* const str) +{ + return *str ? (1 + str_len(str + 1)) : 0; +} + }; // namespace __detail CONSTHASH_NAMESPACE_END; diff --git a/include/consthash/crc32.hxx b/include/consthash/crc32.hxx index a1ffd13..120bd69 100644 --- a/include/consthash/crc32.hxx +++ b/include/consthash/crc32.hxx @@ -67,6 +67,11 @@ constexpr uint32_t crc32(const char* str, size_t size) return crc32impl(0xffffffff, str, size) ^ 0xffffffff; } +constexpr uint32_t crc32(const char* str) +{ + return crc32impl(0xffffffff, str, __detail::str_len(str)) ^ 0xffffffff; +} + CONSTHASH_NAMESPACE_END; #endif // _CONSTHASH_CRC32_HXX diff --git a/include/consthash/crc64.hxx b/include/consthash/crc64.hxx index f0c8fb0..18fb475 100644 --- a/include/consthash/crc64.hxx +++ b/include/consthash/crc64.hxx @@ -88,6 +88,11 @@ constexpr uint64_t crc64(const char* str, size_t size) return crc64impl(0xffffffff, str, size) ^ 0xffffffff; } +constexpr uint64_t crc64(const char* str) +{ + return crc64impl(0xffffffff, str, __detail::str_len(str)) ^ 0xffffffff; +} + CONSTHASH_NAMESPACE_END; #endif // _CONSTHASH_CRC64_HXX