Skip to content

Commit

Permalink
Updated frozen: 1.1.1 -> 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekazakov committed Dec 16, 2024
1 parent 14041cc commit ba5f55f
Show file tree
Hide file tree
Showing 16 changed files with 310 additions and 278 deletions.
2 changes: 1 addition & 1 deletion 3rd_Party/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Verify the Xcode version with `xcode-select -p`.
| Catch2 | 2.13.3 | 2020.10.31 | https://github.com/catchorg/Catch2
| curl | 8.7.1 | 2024.03.27 | https://github.com/curl/curl.git
| fmt | 10.2.1 | 2024.01.04 | https://github.com/fmtlib/fmt.git
| frozen | 1.1.1 | 2022.03.31 | https://github.com/serge-sans-paille/frozen
| frozen | 1.2.0 | 2024.06.02 | https://github.com/serge-sans-paille/frozen
| gtest | 1.14.0 | 2023.08.02 | https://github.com/google/googletest.git
| letsmove | 1.25 | 2020.07.09 | https://github.com/potionfactory/LetsMove.git
| lexilla | 5.4.1 | 2024.10.19 | https://github.com/ScintillaOrg/lexilla.git
Expand Down
2 changes: 1 addition & 1 deletion 3rd_Party/frozen/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TMP_DIR=${CUR_DIR}/frozen.tmp
mkdir ${TMP_DIR}
cd ${TMP_DIR}

git clone -b 1.1.1 --single-branch https://github.com/serge-sans-paille/frozen
git clone -b 1.2.0 --single-branch https://github.com/serge-sans-paille/frozen

cd ..

Expand Down
29 changes: 15 additions & 14 deletions 3rd_Party/frozen/include/frozen/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ template <std::size_t size> class knuth_morris_pratt_searcher {
static constexpr bits::carray<std::ptrdiff_t, size>
build_kmp_cache(char const (&needle)[size + 1]) {
std::ptrdiff_t cnd = 0;
bits::carray<std::ptrdiff_t, size> cache;

cache.fill(-1);
bits::carray<std::ptrdiff_t, size> cache(-1);
for (std::size_t pos = 1; pos < size; ++pos) {
if (needle[pos] == needle[cnd]) {
cache[pos] = cache[cnd];
Expand Down Expand Up @@ -109,9 +107,7 @@ template <std::size_t size> class boyer_moore_searcher {
bits::carray<char, size> needle_;

constexpr auto build_skip_table(char const (&needle)[size + 1]) {
skip_table_type skip_table;

skip_table.fill(size);
skip_table_type skip_table(size);
for (std::size_t i = 0; i < size - 1; ++i)
skip_table[needle[i]] -= i + 1;
return skip_table;
Expand Down Expand Up @@ -166,24 +162,29 @@ template <std::size_t size> class boyer_moore_searcher {
suffix_table_{build_suffix_table(needle)},
needle_(needle) {}

template <class ForwardIterator>
constexpr std::pair<ForwardIterator, ForwardIterator> operator()(ForwardIterator first, ForwardIterator last) const {
template <class RandomAccessIterator>
constexpr std::pair<RandomAccessIterator, RandomAccessIterator> operator()(RandomAccessIterator first, RandomAccessIterator last) const {
if (size == 0)
return { first, first + size };
return { first, first };

if (size > size_t(last - first))
return { last, last };

ForwardIterator iter = first + size - 1;
while (iter < last) {
RandomAccessIterator iter = first + size - 1;
while (true) {
std::ptrdiff_t j = size - 1;
while (j > 0 && (*iter == needle_[j])) {
--iter;
--j;
}
if (*iter == needle_[0])
if (j == 0 && *iter == needle_[0])
return { iter, iter + size};

iter += std::max(skip_table_[*iter], suffix_table_[j]);
std::ptrdiff_t jump = std::max(skip_table_[*iter], suffix_table_[j]);
if (jump >= last - iter)
return { last, last };
iter += jump;
}
return { last, last + size};
}
};

Expand Down
24 changes: 15 additions & 9 deletions 3rd_Party/frozen/include/frozen/bits/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,25 @@ constexpr void cswap(std::tuple<Tys...> &a, std::tuple<Tys...> &b) {
cswap(a, b, std::make_index_sequence<sizeof...(Tys)>());
}

template <typename Iter>
constexpr void iter_swap(Iter a, Iter b) {
cswap(*a, *b);
}

template <typename Iterator, class Compare>
constexpr Iterator partition(Iterator left, Iterator right, Compare const &compare) {
auto pivot = left + (right - left) / 2;
auto value = *pivot;
cswap(*right, *pivot);
iter_swap(right, pivot);
pivot = right;
for (auto it = left; 0 < right - it; ++it) {
if (compare(*it, value)) {
cswap(*it, *left);
if (compare(*it, *pivot)) {
iter_swap(it, left);
left++;
}
}
cswap(*right, *left);
return left;
iter_swap(pivot, left);
pivot = left;
return pivot;
}

template <typename Iterator, class Compare>
Expand All @@ -133,10 +139,10 @@ constexpr void quicksort(Iterator left, Iterator right, Compare const &compare)
}
}

template <typename T, std::size_t N, class Compare>
constexpr bits::carray<T, N> quicksort(bits::carray<T, N> const &array,
template <typename Container, class Compare>
constexpr Container quicksort(Container const &array,
Compare const &compare) {
bits::carray<T, N> res = array;
Container res = array;
quicksort(res.begin(), res.end() - 1, compare);
return res;
}
Expand Down
55 changes: 23 additions & 32 deletions 3rd_Party/frozen/include/frozen/bits/basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

#include <array>
#include <utility>
#include <iterator>
#include <string>
#include <type_traits>

namespace frozen {

Expand Down Expand Up @@ -62,8 +62,10 @@ class cvector {
}

// Iterators
constexpr iterator begin() noexcept { return data; }
constexpr iterator end() noexcept { return data + dsize; }
constexpr iterator begin() noexcept { return data; }
constexpr iterator end() noexcept { return data + dsize; }
constexpr const_iterator begin() const noexcept { return data; }
constexpr const_iterator end() const noexcept { return data + dsize; }

// Capacity
constexpr size_type size() const { return dsize; }
Expand All @@ -87,12 +89,12 @@ template <class T, std::size_t N>
class carray {
T data_ [N] = {}; // zero-initialization for scalar type T, default-initialized otherwise

template <std::size_t M, std::size_t... I>
constexpr carray(T const (&init)[M], std::index_sequence<I...>)
: data_{init[I]...} {}
template <class Iter, std::size_t... I>
constexpr carray(Iter iter, std::index_sequence<I...>)
: data_{((void)I, *iter++)...} {}
template <std::size_t... I>
constexpr carray(const T& value, std::index_sequence<I...>)
: data_{((void)I, value)...} {}

public:
// Container typdefs
Expand All @@ -103,46 +105,43 @@ class carray {
using const_pointer = const value_type *;
using iterator = pointer;
using const_iterator = const_pointer;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;

// Constructors
constexpr carray(void) = default;
template <std::size_t M>
constexpr carray(T const (&init)[M])
constexpr carray() = default;
constexpr carray(const value_type& val)
: carray(val, std::make_index_sequence<N>()) {}
template <typename U, std::enable_if_t<std::is_convertible<U, T>::value, std::size_t> M>
constexpr carray(U const (&init)[M])
: carray(init, std::make_index_sequence<N>())
{
static_assert(M >= N, "Cannot initialize a carray with an smaller array");
}
template <std::size_t M>
constexpr carray(std::array<T, M> const &init)
: carray(&init[0], std::make_index_sequence<N>())
template <typename U, std::enable_if_t<std::is_convertible<U, T>::value, std::size_t> M>
constexpr carray(std::array<U, M> const &init)
: carray(init.begin(), std::make_index_sequence<N>())
{
static_assert(M >= N, "Cannot initialize a carray with an smaller array");
}
constexpr carray(std::initializer_list<T> init)
template <typename U, std::enable_if_t<std::is_convertible<U, T>::value>* = nullptr>
constexpr carray(std::initializer_list<U> init)
: carray(init.begin(), std::make_index_sequence<N>())
{
// clang & gcc doesn't recognize init.size() as a constexpr
// static_assert(init.size() >= N, "Cannot initialize a carray with an smaller initializer list");
}
template <typename U, std::enable_if_t<std::is_convertible<U, T>::value>* = nullptr>
constexpr carray(const carray<U, N>& rhs)
: carray(rhs.begin(), std::make_index_sequence<N>())
{
}

// Iterators
constexpr iterator begin() noexcept { return data_; }
constexpr const_iterator begin() const noexcept { return data_; }
constexpr const_iterator cbegin() const noexcept { return data_; }
constexpr iterator end() noexcept { return data_ + N; }
constexpr const_iterator end() const noexcept { return data_ + N; }
constexpr const_iterator cend() const noexcept { return data_ + N; }

constexpr reverse_iterator rbegin() noexcept { return reverse_iterator(end()); }
constexpr const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); }
constexpr const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); }
constexpr reverse_iterator rend() noexcept { return reverse_iterator(begin()); }
constexpr const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); }
constexpr const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); }

// Capacity
constexpr size_type size() const { return N; }
Expand Down Expand Up @@ -171,12 +170,6 @@ class carray {

constexpr value_type* data() noexcept { return data_; }
constexpr const value_type* data() const noexcept { return data_; }

// Modifiers
constexpr void fill(const value_type& val) {
for (std::size_t i = 0; i < N; ++i)
data_[i] = val;
}
};
template <class T>
class carray<T, 0> {
Expand All @@ -190,8 +183,6 @@ class carray<T, 0> {
using const_pointer = const value_type *;
using iterator = pointer;
using const_iterator = const_pointer;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;

Expand Down
4 changes: 2 additions & 2 deletions 3rd_Party/frozen/include/frozen/bits/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
#define FROZEN_LETITGO_HAS_CHAR8T
#endif

#if __cpp_deduction_guides >= 201703L
#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201703L
#define FROZEN_LETITGO_HAS_DEDUCTION_GUIDES
#endif

#if __cpp_lib_constexpr_string >= 201907L
#if defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
#define FROZEN_LETITGO_HAS_CONSTEXPR_STRING
#endif

Expand Down
2 changes: 1 addition & 1 deletion 3rd_Party/frozen/include/frozen/bits/elsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ template <> struct elsa<void> {
}
};

template <class T> using anna = elsa<T>;
template <class T=void> using anna = elsa<T>;
} // namespace frozen

#endif
3 changes: 2 additions & 1 deletion 3rd_Party/frozen/include/frozen/bits/elsa_std.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef FROZEN_LETITGO_BITS_ELSA_STD_H
#define FROZEN_LETITGO_BITS_ELSA_STD_H

#include "defines.h"
#include "elsa.h"
#include "hash_string.h"

Expand Down Expand Up @@ -37,4 +38,4 @@ template <typename CharT> struct elsa<std::basic_string<CharT>>

} // namespace frozen

#endif // FROZEN_LETITGO_BITS_ELSA_STD_H
#endif // FROZEN_LETITGO_BITS_ELSA_STD_H
6 changes: 3 additions & 3 deletions 3rd_Party/frozen/include/frozen/bits/hash_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ 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<size_t>(c);
d = d * 33 + static_cast<std::size_t>(c);
return d;
}

// 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<size_t>(0x01000193);
std::size_t d = (0x811c9dc5 ^ seed) * static_cast<std::size_t>(0x01000193);
for (const auto& c : value)
d = (d ^ static_cast<size_t>(c)) * static_cast<size_t>(0x01000193);
d = (d ^ static_cast<std::size_t>(c)) * static_cast<std::size_t>(0x01000193);
return d >> 8 ;
}

Expand Down
56 changes: 56 additions & 0 deletions 3rd_Party/frozen/include/frozen/bits/mpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Frozen
* Copyright 2022 Giel van Schijndel
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#ifndef FROZEN_LETITGO_BITS_MPL_H
#define FROZEN_LETITGO_BITS_MPL_H

#include <utility>

namespace frozen {

namespace bits {

// Forward declarations
template <class, std::size_t>
class carray;

template <typename T>
struct remove_cv : std::remove_cv<T> {};

template <typename... T>
struct remove_cv<std::pair<T...>> {
using type = std::pair<typename remove_cv<T>::type...>;
};

template <typename T, std::size_t N>
struct remove_cv<carray<T, N>> {
using type = carray<typename remove_cv<T>::type, N>;
};

template <typename T>
using remove_cv_t = typename remove_cv<T>::type;

} // namespace bits

} // namespace frozen

#endif
Loading

0 comments on commit ba5f55f

Please sign in to comment.