Clean up rexy::hash stuff

This commit is contained in:
rexy712 2022-06-26 14:20:44 -07:00
parent fb19bdec67
commit 2ecbff1cdd
14 changed files with 54 additions and 188 deletions

View File

@ -22,7 +22,7 @@ option(BUILD_TESTS "Enable testing" OFF)
option(BUILD_HEADER_ONLY "Enable header only build" OFF)
mark_as_advanced(ENABLE_PROFILING)
set(LIBREXY_PUBLIC_HEADERS "include/rexy/rexy.hpp" "include/rexy/algorithm.hpp" "include/rexy/algorithm.tpp" "include/rexy/utility.hpp" "include/rexy/basic_string_hash.hpp" "include/rexy/hash.hpp" "include/rexy/string_view_hash.hpp" "include/rexy/string_hash.hpp" "include/rexy/mpmc_queue.hpp" "include/rexy/mpmc_queue.tpp" "include/rexy/traits.hpp" "include/rexy/steal.hpp" "include/rexy/expression.hpp" "include/rexy/string_base.hpp" "include/rexy/string.hpp" "include/rexy/string_base.tpp" "include/rexy/allocator.hpp" "include/rexy/meta.hpp" "include/rexy/buffer.hpp" "include/rexy/buffer.tpp" "include/rexy/debug_print.hpp" "include/rexy/deferred.hpp" "include/rexy/enum_traits.hpp" "include/rexy/storage_for.hpp" "include/rexy/storage_for.tpp" "include/rexy/visitor.hpp" "include/rexy/string_view.hpp" "include/rexy/string_view.tpp" "include/rexy/format.hpp" "include/rexy/format.tpp")
set(LIBREXY_PUBLIC_HEADERS "include/rexy/rexy.hpp" "include/rexy/algorithm.hpp" "include/rexy/algorithm.tpp" "include/rexy/utility.hpp" "include/rexy/hash.hpp" "include/rexy/mpmc_queue.hpp" "include/rexy/mpmc_queue.tpp" "include/rexy/traits.hpp" "include/rexy/steal.hpp" "include/rexy/expression.hpp" "include/rexy/string_base.hpp" "include/rexy/string.hpp" "include/rexy/string_base.tpp" "include/rexy/allocator.hpp" "include/rexy/meta.hpp" "include/rexy/buffer.hpp" "include/rexy/buffer.tpp" "include/rexy/debug_print.hpp" "include/rexy/deferred.hpp" "include/rexy/enum_traits.hpp" "include/rexy/storage_for.hpp" "include/rexy/storage_for.tpp" "include/rexy/visitor.hpp" "include/rexy/string_view.hpp" "include/rexy/string_view.tpp" "include/rexy/format.hpp" "include/rexy/format.tpp")
if(BUILD_HEADER_ONLY)
set(LIBREXY_BUILT_LIBRARY_HEADERS "")

View File

@ -1,34 +0,0 @@
/**
This file is a part of rexy's general purpose library
Copyright (C) 2020 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef REXY_BASIC_STRING_HASH_HPP
#define REXY_BASIC_STRING_HASH_HPP
#include "string_hash.hpp"
#include "string.hpp"
#include "rexy.hpp"
namespace rexy{
template<>
struct hash<rexy::string> : public string_hash<rexy::string>{};
}
#endif

View File

@ -1,32 +0,0 @@
/**
This file is a part of rexy's general purpose library
Copyright (C) 2020 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef REXY_CX_CX_STRING_HASH_HPP
#define REXY_CX_CX_STRING_HASH_HPP
#include "../string_hash.hpp"
#include "string.hpp"
namespace rexy::cx{
template<std::size_t N>
struct hash<rexy::cx::string<N>> : public string_hash<rexy::cx::string<N>>{};
}
#endif

View File

@ -89,8 +89,4 @@ namespace rexy::cx{
#include "hashmap.tpp"
#ifdef REXY_STRING_BASE_HPP
#include "../string_hash.hpp"
#endif
#endif

View File

@ -35,7 +35,6 @@ namespace rexy::cx{
#include <iterator> //reverse_iterator
#include "../compat/standard.hpp"
#include "../compat/string_base.hpp"
//This is different from rexy::string_view in that this doesn't hold a pointer to a constant string array.
//This holds a mutable array of data which can be modified during compile time. string_view is
@ -105,7 +104,7 @@ namespace rexy::cx{
}
template<class Left, class Right>
constexpr string(const rexy::string_cat_expr<Left,Right>& expr)
noexcept(std::is_nothrow_invocable<rexy::detail::string_appender<cx::string<N>>, decltype(expr)>::value)
noexcept(std::is_nothrow_invocable<rexy::detail::string_appender<cx::string<N,Char>>, decltype(expr)>::value)
{
rexy::detail::string_appender<cx::string<N,value_type>> append(*this);
append(expr);
@ -225,7 +224,7 @@ namespace rexy::cx{
template<class Char, std::size_t N>
static std::true_type check(cx::string<N,Char>);
static std::false_type check(...);
static constexpr bool value = (decltype(check(std::declval<remove_cvref_t<Ts>>()))::value && ...);
static constexpr bool value = (decltype(check(std::declval<rexy::remove_cvref_t<Ts>>()))::value && ...);
};
}
@ -236,8 +235,5 @@ namespace rexy::cx{
#include "../compat/cpp17/cx/string.hpp"
#endif //__cpp_concepts
#ifdef REXY_CX_HASH_HPP
#include "cx_string_hash.hpp"
#endif
#endif

View File

@ -21,6 +21,9 @@
#include <tuple>
#include <utility> //forward, index_sequence
#include <cstddef> //size_t
#include "compat/standard.hpp"
namespace rexy{
template<class T, class... Args>
@ -36,11 +39,11 @@ namespace rexy{
template<class... FArgs>
constexpr deferred(FArgs&&... args);
deferred(const deferred&) = default;
deferred(deferred&&) = default;
~deferred(void) = default;
deferred& operator=(const deferred&) = default;
deferred& operator=(deferred&&) = default;
REXY_CPP20_CONSTEXPR deferred(const deferred&) = default;
REXY_CPP20_CONSTEXPR deferred(deferred&&) = default;
REXY_CPP20_CONSTEXPR ~deferred(void) = default;
REXY_CPP20_CONSTEXPR deferred& operator=(const deferred&) = default;
REXY_CPP20_CONSTEXPR deferred& operator=(deferred&&) = default;
constexpr value_type value(void);
constexpr operator value_type(void);

View File

@ -20,8 +20,8 @@
#define REXY_STRING_APPENDER_HPP
#include "../expression.hpp"
#include "../traits.hpp"
#include <utility> //forward
#include <type_traits> //enable_if, declval
namespace rexy::detail{
@ -49,12 +49,7 @@ namespace rexy::detail{
template<class Val, std::enable_if_t<!rexy::is_template_derived_type<Val,binary_expression>::value,int> = 0, class = decltype(std::declval<Val>().length())>
constexpr void operator()(Val&& v)
{
m_targ.append(std::forward<Val>(v).get(), std::forward<Val>(v).length());
}
template<class Val, std::enable_if_t<!rexy::is_template_derived_type<Val,binary_expression>::value,void*> = nullptr, class = decltype(std::declval<Val>().size())>
constexpr void operator()(Val&& v)
{
m_targ.append(std::forward<Val>(v).get(), std::forward<Val>(v).size());
m_targ.append(std::forward<Val>(v).data(), std::forward<Val>(v).length());
}
};

View File

@ -19,6 +19,8 @@
#ifndef REXY_FILERD_HPP
#define REXY_FILERD_HPP
#ifndef LIBREXY_HEADER_ONLY
#include <cstdio> //FILE
#include <cstddef> //size_t
#include <type_traits> //is_nothrow_constructible
@ -29,7 +31,6 @@
#include "rexy.hpp"
#include "buffer.hpp"
#ifndef LIBREXY_HEADER_ONLY
namespace rexy{

View File

@ -1,6 +1,6 @@
/**
This file is a part of rexy's general purpose library
Copyright (C) 2020 rexy712
Copyright (C) 2020-2022 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -20,10 +20,22 @@
#define REXY_HASH_HPP
#include <climits> //CHAR_BIT
#include <cstddef> //size_t
#include "rexy.hpp"
#include "allocator.hpp"
namespace rexy{
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
class basic_string;
template<class Char>
class basic_string_view;
namespace cx{
template<std::size_t N, class Char>
class string;
}
template<class T>
struct hash{
constexpr std::size_t operator()(const T& t, std::size_t salt = 0)const noexcept{
@ -38,16 +50,32 @@ namespace rexy{
}
};
namespace detail{
//jenkins one at a time hash
template<class Str>
struct string_hash{
constexpr std::size_t operator()(const Str& s, std::size_t salt = 0)const noexcept{
std::size_t hash = salt;
for(std::size_t i = 0;i < s.length();++i){
hash += s[i];
hash += (hash << 10);
hash += (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash << 11);
hash += (hash << 15);
return hash;
}
};
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
struct hash<rexy::basic_string<Char,Alloc>> : public detail::string_hash<rexy::basic_string<Char,Alloc>>{};
template<class Char>
struct hash<rexy::basic_string_view<Char>> : public detail::string_hash<rexy::basic_string_view<Char>>{};
template<std::size_t N, class Char>
struct hash<rexy::cx::string<N,Char>> : public detail::string_hash<rexy::cx::string<N,Char>>{};
}
#ifdef REXY_STRING_VIEW_HPP
#include "string_view_hash.hpp"
#endif
#ifdef REXY_STRING_HPP
#include "basic_string_hash.hpp"
#endif
#ifdef REXY_CX_STRING_HPP
#include "cx/cx_string_hash.hpp"
#endif
#endif

View File

@ -47,8 +47,4 @@ namespace rexy{
}
#ifdef REXY_CX_HASH_HPP
#include "cx/basic_string_hash.hpp"
#endif
#endif

View File

@ -1,45 +0,0 @@
/**
This file is a part of rexy's general purpose library
Copyright (C) 2020 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef REXY_STRING_HASH_HPP
#define REXY_STRING_HASH_HPP
#include "rexy.hpp"
namespace rexy{
//jenkns one at a time hash
template<class Str>
struct string_hash{
constexpr std::size_t operator()(const Str& s, std::size_t salt = 0)const noexcept{
std::size_t hash = salt;
for(std::size_t i = 0;i < s.length();++i){
hash += s[i];
hash += (hash << 10);
hash += (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash << 11);
hash += (hash << 15);
return hash;
}
};
}
#endif

View File

@ -173,8 +173,4 @@ namespace{
#include "string_view.tpp"
#ifdef REXY_HASH_HPP
#include "string_view_hash.hpp"
#endif
#endif

View File

@ -1,33 +0,0 @@
/**
This file is a part of rexy's general purpose library
Copyright (C) 2020-2022 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef REXY_STRING_VIEW_HASH_HPP
#define REXY_STRING_VIEW_HASH_HPP
#include "string_hash.hpp"
#include "string_view.hpp"
#include "rexy.hpp"
namespace rexy{
template<class Char>
struct hash<rexy::basic_string_view<Char>> : public string_hash<rexy::basic_string_view<Char>>{};
}
#endif

View File

@ -11,7 +11,6 @@
#include "rexy/steal.hpp"
#include "rexy/string_base.hpp"
#include "rexy/string_base.tpp"
#include "rexy/string_hash.hpp"
#include "rexy/string.hpp"
#include "rexy/traits.hpp"
#include "rexy/utility.hpp"