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
6 changes: 2 additions & 4 deletions include/frozen/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
#error \
"frozen/algorithm.h requires C++23 or later. Compile with /std:c++latest or /std:c++23."
#endif
#elif __cplusplus < 202302L
#elif __cplusplus < 202101L
#error "frozen/algorithm.h requires C++23 or later. Compile with -std=c++23 or later."
#endif

#include "frozen/bits/basic_types.h"
#include "frozen/bits/version.h"
#include "frozen/string.h"
#include "bits/basic_types.h"

namespace frozen
{
Expand Down
2 changes: 1 addition & 1 deletion include/frozen/bits/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#pragma once

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

#include <limits>
#include <tuple>
Expand Down
4 changes: 2 additions & 2 deletions include/frozen/bits/basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

#pragma once

#include "frozen/bits/constexpr_assert.h"
#include "frozen/bits/exceptions.h"
#include "constexpr_assert.h"
#include "exceptions.h"

#include <array>
#include <concepts>
Expand Down
4 changes: 2 additions & 2 deletions include/frozen/bits/pmh.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
// inspired from http://stevehanov.ca/blog/index.php?id=119
#pragma once

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

#include <cstddef>
#include <cstdint>
Expand Down
2 changes: 1 addition & 1 deletion include/frozen/bits/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#if _MSVC_LANG < 202302L
#error "frozen 2.0 requires C++23 or later. Compile with /std:c++latest or /std:c++23."
#endif
#elif __cplusplus < 202302L
#elif __cplusplus < 202101L
#error "frozen 2.0 requires C++23 or later. Compile with -std=c++23 or later."
#endif

Expand Down
11 changes: 5 additions & 6 deletions include/frozen/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@
#if _MSVC_LANG < 202302L
#error "frozen/map.h requires C++23 or later. Compile with /std:c++latest or /std:c++23."
#endif
#elif __cplusplus < 202302L
#elif __cplusplus < 202101L
#error "frozen/map.h requires C++23 or later. Compile with -std=c++23 or later."
#endif

#include "frozen/bits/algorithms.h"
#include "frozen/bits/basic_types.h"
#include "frozen/bits/exceptions.h"
#include "frozen/bits/mpl.h"
#include "frozen/bits/version.h"
#include "bits/algorithms.h"
#include "bits/basic_types.h"
#include "bits/exceptions.h"
#include "bits/mpl.h"

#include <functional>
#include <iterator>
Expand Down
5 changes: 2 additions & 3 deletions include/frozen/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
#if _MSVC_LANG < 202302L
#error "frozen/random.h requires C++23 or later. Compile with /std:c++latest or /std:c++23."
#endif
#elif __cplusplus < 202302L
#elif __cplusplus < 202101L
#error "frozen/random.h requires C++23 or later. Compile with -std=c++23 or later."
#endif

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

#include <concepts>
#include <cstdint>
Expand Down
27 changes: 15 additions & 12 deletions include/frozen/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@
#if _MSVC_LANG < 202302L
#error "frozen/set.h requires C++23 or later. Compile with /std:c++latest or /std:c++23."
#endif
#elif __cplusplus < 202302L
#elif __cplusplus < 202101L
#error "frozen/set.h requires C++23 or later. Compile with -std=c++23 or later."
#endif

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

#include <functional>
#include <iterator>
Expand Down Expand Up @@ -101,9 +100,10 @@ namespace frozen
{
const_iterator where = lower_bound(key);
if ((where != end()) && !value_comp()(key, *where))
{
return where;
else
return end();
}
return end();
}

template <class KeyType>
Expand All @@ -118,29 +118,32 @@ namespace frozen
{
auto const lower = lower_bound(key);
if (lower == end())
{
return { lower, lower };
else
return { lower, lower + 1 };
}
return { lower, lower + 1 };
}

template <class KeyType>
[[nodiscard]] constexpr const_iterator lower_bound(KeyType const& key) const
{
auto const where = bits::lower_bound<N>(keys_.begin(), key, value_comp());
if ((where != end()) && !value_comp()(key, *where))
{
return where;
else
return end();
}
return end();
}

template <class KeyType>
[[nodiscard]] constexpr const_iterator upper_bound(KeyType const& key) const
{
auto const where = bits::lower_bound<N>(keys_.begin(), key, value_comp());
if ((where != end()) && !value_comp()(key, *where))
{
return where + 1;
else
return end();
}
return end();
}

/* observers */
Expand Down
10 changes: 9 additions & 1 deletion include/frozen/string.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#pragma once

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

#include <cstddef>
#include <string_view>
Expand Down
14 changes: 6 additions & 8 deletions include/frozen/unordered_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,17 @@
#error \
"frozen/unordered_map.h requires C++23 or later. Compile with /std:c++latest or /std:c++23."
#endif
#elif __cplusplus < 202302L
#elif __cplusplus < 202101L
#error "frozen/unordered_map.h requires C++23 or later. Compile with -std=c++23 or later."
#endif

#include "frozen/bits/basic_types.h"
#include "frozen/bits/elsa.h"
#include "frozen/bits/exceptions.h"
#include "frozen/bits/pmh.h"
#include "frozen/bits/version.h"
#include "frozen/random.h"
#include "bits/basic_types.h"
#include "bits/elsa.h"
#include "bits/exceptions.h"
#include "bits/pmh.h"
#include "random.h"

#include <functional>
#include <tuple>
#include <utility>

namespace frozen
Expand Down
87 changes: 46 additions & 41 deletions include/frozen/unordered_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
#error \
"frozen/unordered_set.h requires C++23 or later. Compile with /std:c++latest or /std:c++23."
#endif
#elif __cplusplus < 202302L
#elif __cplusplus < 202101L
#error "frozen/unordered_set.h requires C++23 or later. Compile with -std=c++23 or later."
#endif

#include "frozen/bits/basic_types.h"
#include "frozen/bits/elsa.h"
#include "frozen/bits/pmh.h"
#include "frozen/bits/version.h"
#include "frozen/random.h"
#include "bits/basic_types.h"
#include "bits/elsa.h"
#include "bits/pmh.h"
#include "random.h"

#include <functional>
#include <utility>
Expand All @@ -50,7 +49,7 @@ namespace frozen
struct Get
{
template <class T>
constexpr T const& operator()(T const& key) const
constexpr auto operator()(T const& key) const -> T const&
{
return key;
}
Expand Down Expand Up @@ -85,7 +84,6 @@ namespace frozen
using const_iterator = typename container_type::const_iterator;
using iterator = const_iterator;

public:
/* constructors */
unordered_set(unordered_set const&) = default;
constexpr unordered_set(container_type keys, Hash const& hash, KeyEqual const& equal) :
Expand All @@ -111,72 +109,79 @@ namespace frozen
}

/* iterators */
[[nodiscard]] constexpr const_iterator begin() const { return keys_.begin(); }
[[nodiscard]] constexpr const_iterator end() const { return keys_.end(); }
[[nodiscard]] constexpr const_iterator cbegin() const { return keys_.begin(); }
[[nodiscard]] constexpr const_iterator cend() const { return keys_.end(); }
[[nodiscard]] constexpr auto begin() const -> const_iterator { return keys_.begin(); }
[[nodiscard]] constexpr auto end() const -> const_iterator { return keys_.end(); }
[[nodiscard]] constexpr auto cbegin() const -> const_iterator { return keys_.begin(); }
[[nodiscard]] constexpr auto cend() const -> const_iterator { return keys_.end(); }

/* capacity */
[[nodiscard]] constexpr bool empty() const { return !N; }
[[nodiscard]] constexpr size_type size() const { return N; }
[[nodiscard]] constexpr size_type max_size() const { return N; }
[[nodiscard]] constexpr auto empty() const -> bool { return !N; }
[[nodiscard]] constexpr auto size() const -> size_type { return N; }
[[nodiscard]] constexpr auto max_size() const -> size_type { return N; }

/* lookup */
template <class KeyType>
[[nodiscard]] constexpr std::size_t count(KeyType const& key) const
[[nodiscard]] constexpr auto count(KeyType const& key) const -> std::size_t
{
return find(key, hash_function(), key_eq()) != end();
}

template <class KeyType, class Hasher, class Equal>
[[nodiscard]] constexpr const_iterator find(KeyType const& key, Hasher const& hash,
Equal const& equal) const
[[nodiscard]] constexpr auto find(KeyType const& key, Hasher const& hash,
Equal const& equal) const -> const_iterator
{
auto const pos = tables_.lookup(key, hash);
auto it = keys_.begin() + pos;
if (it != keys_.end() && equal(*it, key))
return it;
else
return keys_.end();
auto iter = keys_.begin() + pos;
if (iter != keys_.end() && equal(*iter, key))
{
return iter;
}
return keys_.end();
}

template <class KeyType>
[[nodiscard]] constexpr const_iterator find(KeyType const& key) const
[[nodiscard]] constexpr auto find(KeyType const& key) const -> const_iterator
{
auto const pos = tables_.lookup(key, hash_function());
auto it = keys_.begin() + pos;
if (it != keys_.end() && key_eq()(*it, key))
return it;
else
return keys_.end();
auto iter = keys_.begin() + pos;
if (iter != keys_.end() && key_eq()(*iter, key))
{
return iter;
}
return keys_.end();
}

template <class KeyType>
[[nodiscard]] constexpr bool contains(KeyType const& key) const
[[nodiscard]] constexpr auto contains(KeyType const& key) const -> bool
{
return this->find(key) != keys_.end();
}

template <class KeyType>
[[nodiscard]] constexpr std::pair<const_iterator, const_iterator>
equal_range(KeyType const& key) const
[[nodiscard]] constexpr auto equal_range(KeyType const& key) const
-> std::pair<const_iterator, const_iterator>
{
auto const it = find(key);
if (it != end())
return { it, it + 1 };
else
return { keys_.end(), keys_.end() };
auto const iter = find(key);
if (iter != end())
{
return { iter, iter + 1 };
}
return { keys_.end(), keys_.end() };
}

/* bucket interface */
[[nodiscard]] constexpr std::size_t bucket_count() const { return storage_size; }
[[nodiscard]] constexpr std::size_t max_bucket_count() const { return storage_size; }
[[nodiscard]] constexpr auto bucket_count() const -> std::size_t { return storage_size; }
[[nodiscard]] constexpr auto max_bucket_count() const -> std::size_t
{
return storage_size;
}

/* observers*/
[[nodiscard]] constexpr const hasher& hash_function() const
[[nodiscard]] constexpr auto hash_function() const -> const hasher&
{
return tables_.hash_function();
}
[[nodiscard]] constexpr const key_equal& key_eq() const
[[nodiscard]] constexpr auto key_eq() const -> const key_equal&
{
return static_cast<KeyEqual const&>(*this);
}
Expand Down