/** 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 . */ #ifndef REXY_CX_HASHMAP_HPP #define REXY_CX_HASHMAP_HPP #include "vector.hpp" #include "array.hpp" #include "../algorithm.hpp" #include "../hash.hpp" #include //CHAR_BIT #include //size_t, ptrdiff_t #include //decay #include namespace rexy::cx{ template struct element{ using key_type = Key; using value_type = Value; Key key; Value value; }; template element(Key,Value) -> element; template> class hashmap { public: using key_type = Key; using mapped_type = Value; using value_type = element; using size_type = size_t; using difference_type = ptrdiff_t; using hasher = Hash; using reference = mapped_type&; using const_reference = const mapped_type&; using pointer = mapped_type*; using const_pointer = const mapped_type*; static constexpr size_type single_bucket_bit = size_type{1} << ((sizeof(size_type)*CHAR_BIT) - 1); static constexpr size_type max_size = N; static_assert((max_size & single_bucket_bit) == 0); private: array m_elements; //perfect hash table array m_g; //'salt' values for indexing into the perfect hash table public: constexpr hashmap(const value_type(&elements)[N]) noexcept(std::is_nothrow_default_constructible::value && std::is_nothrow_copy_constructible::value && std::is_nothrow_move_assignable::value && std::is_nothrow_invocable::value); //no key checks. give a correct key or get a random answer :) template>> constexpr reference operator[](U&& u)noexcept; template>> constexpr const_reference operator[](U&& u)const noexcept; template>> constexpr bool contains(U&& u)const noexcept; }; } #include "hashmap.tpp" #ifdef REXY_STRING_BASE_HPP #include "../string_hash.hpp" #endif #endif