Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
cmake -B build
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_CXX_STANDARD=23
-Dfrozen.tests=ON
"-Dfrozen.tests=ON"
-DCMAKE_VERBOSE_MAKEFILE=ON
${{ matrix.cmake_args }}

Expand Down
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ include(CTest)
include(GNUInstallDirs)
include(cmake/detect_cxx_version.cmake)

# ###################### sccache #######################
find_program(SCCACHE_PROGRAM sccache)
if(SCCACHE_PROGRAM)
message(STATUS "sccache found: ${SCCACHE_PROGRAM}")
set(CMAKE_C_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}")
else()
message(STATUS "sccache not found; building without a compiler cache")
endif()

if(MSVC)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>")
endif()

#
# The `frozen.testing`, `frozen.benchmark`, and `frozen.coverage` options
# only appear as cmake-gui and ccmake options iff frozen is the highest
Expand Down
5 changes: 1 addition & 4 deletions include/frozen/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* under the License.
*/

#ifndef FROZEN_LETITGO_ALGORITHM_H
#define FROZEN_LETITGO_ALGORITHM_H
#pragma once

// Require C++23 or later
#if defined(_MSVC_LANG)
Expand Down Expand Up @@ -270,5 +269,3 @@ namespace frozen
}

} // namespace frozen

#endif
5 changes: 1 addition & 4 deletions include/frozen/bits/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* under the License.
*/

#ifndef FROZEN_LETITGO_BITS_ALGORITHMS_H
#define FROZEN_LETITGO_BITS_ALGORITHMS_H
#pragma once

#include "frozen/bits/basic_types.h"

Expand Down Expand Up @@ -266,5 +265,3 @@ namespace frozen::bits
}

} // namespace frozen::bits

#endif
5 changes: 1 addition & 4 deletions include/frozen/bits/basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* under the License.
*/

#ifndef FROZEN_LETITGO_BASIC_TYPES_H
#define FROZEN_LETITGO_BASIC_TYPES_H
#pragma once

#include "frozen/bits/constexpr_assert.h"
#include "frozen/bits/exceptions.h"
Expand Down Expand Up @@ -247,5 +246,3 @@ namespace frozen::bits
};

} // namespace frozen::bits

#endif
5 changes: 1 addition & 4 deletions include/frozen/bits/constexpr_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@
* under the License.
*/

#ifndef FROZEN_LETITGO_CONSTEXPR_ASSERT_H
#define FROZEN_LETITGO_CONSTEXPR_ASSERT_H
#pragma once

#include <cassert>
#include <utility>

inline void constexpr_assert_failed() {}

#define constexpr_assert(cond, msg) ((void) ((cond) ? 0 : (constexpr_assert_failed(), 0)))

#endif
5 changes: 1 addition & 4 deletions include/frozen/bits/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* under the License.
*/

#ifndef FROZEN_LETITGO_DEFINES_H
#define FROZEN_LETITGO_DEFINES_H
#pragma once

// C++23 guarantees all previously-detected features:
// - string_view (C++17)
Expand All @@ -31,5 +30,3 @@
// The feature-detection macros have been removed. This header
// is here only for backward compatibility to the original
// frozen implementation.

#endif // FROZEN_LETITGO_DEFINES_H
5 changes: 1 addition & 4 deletions include/frozen/bits/elsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* under the License.
*/

#ifndef FROZEN_LETITGO_ELSA_H
#define FROZEN_LETITGO_ELSA_H
#pragma once

#include <concepts>
#include <type_traits>
Expand Down Expand Up @@ -64,5 +63,3 @@ namespace frozen
template <class T = void>
using anna = elsa<T>;
} // namespace frozen

#endif
5 changes: 1 addition & 4 deletions include/frozen/bits/elsa_std.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef FROZEN_LETITGO_BITS_ELSA_STD_H
#define FROZEN_LETITGO_BITS_ELSA_STD_H
#pragma once

#include "elsa.h"
#include "hash_string.h"
Expand Down Expand Up @@ -39,5 +38,3 @@ namespace frozen
};

} // namespace frozen

#endif // FROZEN_LETITGO_BITS_ELSA_STD_H
5 changes: 1 addition & 4 deletions include/frozen/bits/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* under the License.
*/

#ifndef FROZEN_LETITGO_EXCEPTIONS_H
#define FROZEN_LETITGO_EXCEPTIONS_H
#pragma once

#if defined(FROZEN_NO_EXCEPTIONS) || (defined(_MSC_VER) && !defined(_CPPUNWIND)) || \
(!defined(_MSC_VER) && !defined(__cpp_exceptions))
Expand All @@ -35,5 +34,3 @@
#define FROZEN_THROW_OR_ABORT(err) throw err

#endif

#endif
33 changes: 21 additions & 12 deletions include/frozen/bits/hash_string.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
#ifndef FROZEN_LETITGO_BITS_HASH_STRING_H
#define FROZEN_LETITGO_BITS_HASH_STRING_H
#pragma once

#include <cstddef>

namespace frozen
{
// djb2 hash constants
constexpr std::size_t djb2_initial = 5381;
constexpr std::size_t djb2_multiplier = 33;

// FNV-1 hash constants (32-bit)
constexpr std::size_t fnv_offset_basis = 0x811c9dc5;
constexpr std::size_t fnv_prime = 0x01000193;
constexpr std::size_t fnv_shift_bits = 8;

template <typename String>
constexpr std::size_t hash_string(const String& value)
{
std::size_t d = 5381;
for (const auto& c: value)
d = d * 33 + static_cast<std::size_t>(c);
return d;
std::size_t hash = djb2_initial;
for (const auto& chr: value)
{
hash = (hash * djb2_multiplier) + static_cast<std::size_t>(chr);
}
return hash;
}

// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
// With the lowest bits removed, based on experimental setup.
template <typename String>
constexpr std::size_t hash_string(const String& value, std::size_t seed)
{
std::size_t d = (0x811c9dc5 ^ seed) * static_cast<std::size_t>(0x01000193);
for (const auto& c: value)
d = (d ^ static_cast<std::size_t>(c)) * static_cast<std::size_t>(0x01000193);
return d >> 8;
std::size_t hash = (fnv_offset_basis ^ seed) * static_cast<std::size_t>(fnv_prime);
for (const auto& chr: value)
{
hash = (hash ^ static_cast<std::size_t>(chr)) * static_cast<std::size_t>(fnv_prime);
}
return hash >> fnv_shift_bits;
}

} // namespace frozen

#endif // FROZEN_LETITGO_BITS_HASH_STRING_H
5 changes: 1 addition & 4 deletions include/frozen/bits/mpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* under the License.
*/

#ifndef FROZEN_LETITGO_BITS_MPL_H
#define FROZEN_LETITGO_BITS_MPL_H
#pragma once

#include <utility>

Expand Down Expand Up @@ -53,5 +52,3 @@ namespace frozen::bits
using remove_cv_t = typename remove_cv<T>::type;

} // namespace frozen::bits

#endif
6 changes: 1 addition & 5 deletions include/frozen/bits/pmh.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
*/

// inspired from http://stevehanov.ca/blog/index.php?id=119
#ifndef FROZEN_LETITGO_PMH_H
#define FROZEN_LETITGO_PMH_H
#pragma once

#include "frozen/bits/algorithms.h"
#include "frozen/bits/basic_types.h"

#include <array>
#include <cstddef>
#include <cstdint>
#include <limits>
Expand Down Expand Up @@ -282,5 +280,3 @@ namespace frozen::bits
}

} // namespace frozen::bits

#endif
5 changes: 1 addition & 4 deletions include/frozen/bits/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* under the License.
*/

#ifndef FROZEN_LETITGO_VERSION_H
#define FROZEN_LETITGO_VERSION_H
#pragma once

// Require C++23 or later
#if defined(_MSVC_LANG)
Expand All @@ -35,5 +34,3 @@
#define FROZEN_MAJOR_VERSION 2
#define FROZEN_MINOR_VERSION 0
#define FROZEN_PATCH_VERSION 0

#endif
6 changes: 2 additions & 4 deletions include/frozen/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* under the License.
*/

#ifndef FROZEN_LETITGO_MAP_H
#define FROZEN_LETITGO_MAP_H
#pragma once

// Require C++23 or later
#if defined(_MSVC_LANG)
Expand All @@ -38,6 +37,7 @@
#include "frozen/bits/mpl.h"
#include "frozen/bits/version.h"

#include <functional>
#include <iterator>
#include <utility>

Expand Down Expand Up @@ -456,5 +456,3 @@ namespace frozen
}

} // namespace frozen

#endif
5 changes: 1 addition & 4 deletions include/frozen/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* under the License.
*/

#ifndef FROZEN_LETITGO_RANDOM_H
#define FROZEN_LETITGO_RANDOM_H
#pragma once

// Require C++23 or later
#if defined(_MSVC_LANG)
Expand Down Expand Up @@ -104,5 +103,3 @@ namespace frozen
using default_prg_t = minstd_rand;

} // namespace frozen

#endif
6 changes: 2 additions & 4 deletions include/frozen/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* under the License.
*/

#ifndef FROZEN_SET_H
#define FROZEN_SET_H
#pragma once

// Require C++23 or later
#if defined(_MSVC_LANG)
Expand All @@ -36,6 +35,7 @@
#include "frozen/bits/basic_types.h"
#include "frozen/bits/version.h"

#include <functional>
#include <iterator>
#include <utility>

Expand Down Expand Up @@ -315,5 +315,3 @@ namespace frozen
set(T, Args...) -> set<T, sizeof...(Args) + 1>;

} // namespace frozen

#endif
19 changes: 2 additions & 17 deletions include/frozen/string.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
#ifndef FROZEN_LETITGO_STRING_H
#define FROZEN_LETITGO_STRING_H

// Require C++23 or later
#if defined(_MSVC_LANG)
#if _MSVC_LANG < 202302L
#error "frozen/string.h requires C++23 or later. Compile with /std:c++latest or /std:c++23."
#endif
#elif __cplusplus < 202302L
#error "frozen/string.h requires C++23 or later. Compile with -std=c++23 or later."
#endif

#include "frozen/bits/elsa.h"
#include "frozen/bits/hash_string.h"
#pragma once

#include "frozen/bits/version.h"

#include <cstddef>
#include <functional>
#include <string_view>

namespace frozen
Expand Down Expand Up @@ -58,5 +45,3 @@ namespace frozen
} // namespace string_literals

} // namespace frozen

#endif
5 changes: 1 addition & 4 deletions include/frozen/unordered_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* under the License.
*/

#ifndef FROZEN_LETITGO_UNORDERED_MAP_H
#define FROZEN_LETITGO_UNORDERED_MAP_H
#pragma once

// Require C++23 or later
#if defined(_MSVC_LANG)
Expand Down Expand Up @@ -253,5 +252,3 @@ namespace frozen
}

} // namespace frozen

#endif
6 changes: 2 additions & 4 deletions include/frozen/unordered_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* under the License.
*/

#ifndef FROZEN_LETITGO_UNORDERED_SET_H
#define FROZEN_LETITGO_UNORDERED_SET_H
#pragma once

// Require C++23 or later
#if defined(_MSVC_LANG)
Expand All @@ -39,6 +38,7 @@
#include "frozen/bits/version.h"
#include "frozen/random.h"

#include <functional>
#include <utility>

namespace frozen
Expand Down Expand Up @@ -211,5 +211,3 @@ namespace frozen
unordered_set(T, Args...) -> unordered_set<T, sizeof...(Args) + 1>;

} // namespace frozen

#endif
Loading