martinus / robin-hood-hashing

Fast & memory efficient hashtable based on robin hood hashing for C++11/14/17/20
https://gitter.im/martinus/robin-hood-hashing
MIT License
1.5k stars 143 forks source link

Not working #65

Closed Manoj-red-hat closed 4 years ago

Manoj-red-hat commented 4 years ago

`//============================================================================ // Name : ROBIN_HOOD TEST // Author : legion //============================================================================

include

include "robin_hood.h"

using namespace std;

int main() { robin_hood::unordered_map<int, std::pair<int, int>> data; data.insert(std::make_pair(1, std::make_pair(2, 2))); auto f = data.find(1); cout << f.first; return 0; } `

ERROR make all Building file: ../src/console.cpp Invoking: GCC C++ Compiler g++ -std=c++17 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/console.d" -MT"src/console.o" -o "src/console.o" "../src/console.cpp" ../src/console.cpp: In function ‘int main()’: ../src/console.cpp:16:54: error: no matching function for call to ‘robin_hood::detail::Table<true, 80, int, std::pair<int, int>, robin_hood::hash<int>, std::equal_to<int> >::insert(std::pair<int, std::pair<int, int> >)’ 16 | data.insert(std::make_pair(1, std::make_pair(2, 2))); | ^ In file included from ../src/console.cpp:11: ../src/robin_hood.h:1647:10: note: candidate: ‘template<class Iter> void robin_hood::detail::Table<IsFlat, MaxLoadFactor100, Key, T, Hash, KeyEqual>::insert(Iter, Iter) [with Iter = Iter; bool IsFlat = true; long unsigned int MaxLoadFactor100 = 80; Key = int; T = std::pair<int, int>; Hash = robin_hood::hash<int>; KeyEqual = std::equal_to<int>]’ 1647 | void insert(Iter first, Iter last) { | ^~~~~~ ../src/robin_hood.h:1647:10: note: template argument deduction/substitution failed: ../src/console.cpp:16:54: note: candidate expects 2 arguments, 1 provided 16 | data.insert(std::make_pair(1, std::make_pair(2, 2))); | ^ In file included from ../src/console.cpp:11: ../src/robin_hood.h:1667:31: note: candidate: ‘std::pair<robin_hood::detail::Table<IsFlat, MaxLoadFactor100, Key, T, Hash, KeyEqual>::Iter<false>, bool> robin_hood::detail::Table<IsFlat, MaxLoadFactor100, Key, T, Hash, KeyEqual>::insert(const value_type&) [with bool IsFlat = true; long unsigned int MaxLoadFactor100 = 80; Key = int; T = std::pair<int, int>; Hash = robin_hood::hash<int>; KeyEqual = std::equal_to<int>; robin_hood::detail::Table<IsFlat, MaxLoadFactor100, Key, T, Hash, KeyEqual>::value_type = robin_hood::pair<int, std::pair<int, int> >]’ 1667 | std::pair<iterator, bool> insert(const value_type& keyval) { | ^~~~~~ ../src/robin_hood.h:1667:56: note: no known conversion for argument 1 from ‘std::pair<int, std::pair<int, int> >’ to ‘const value_type&’ {aka ‘const robin_hood::pair<int, std::pair<int, int> >&’} 1667 | std::pair<iterator, bool> insert(const value_type& keyval) { | ~~~~~~~~~~~~~~~~~~^~~~~~ ../src/robin_hood.h:1672:31: note: candidate: ‘std::pair<robin_hood::detail::Table<IsFlat, MaxLoadFactor100, Key, T, Hash, KeyEqual>::Iter<false>, bool> robin_hood::detail::Table<IsFlat, MaxLoadFactor100, Key, T, Hash, KeyEqual>::insert(robin_hood::detail::Table<IsFlat, MaxLoadFactor100, Key, T, Hash, KeyEqual>::value_type&&) [with bool IsFlat = true; long unsigned int MaxLoadFactor100 = 80; Key = int; T = std::pair<int, int>; Hash = robin_hood::hash<int>; KeyEqual = std::equal_to<int>; robin_hood::detail::Table<IsFlat, MaxLoadFactor100, Key, T, Hash, KeyEqual>::value_type = robin_hood::pair<int, std::pair<int, int> >]’ 1672 | std::pair<iterator, bool> insert(value_type&& keyval) { | ^~~~~~ ../src/robin_hood.h:1672:51: note: no known conversion for argument 1 from ‘std::pair<int, std::pair<int, int> >’ to ‘robin_hood::detail::Table<true, 80, int, std::pair<int, int>, robin_hood::hash<int>, std::equal_to<int> >::value_type&&’ {aka ‘robin_hood::pair<int, std::pair<int, int> >&&’} 1672 | std::pair<iterator, bool> insert(value_type&& keyval) { | ~~~~~~~~~~~~~^~~~~~ ../src/console.cpp:18:13: error: ‘class robin_hood::detail::Table<true, 80, int, std::pair<int, int>, robin_hood::hash<int>, std::equal_to<int> >::Iter<false>’ has no member named ‘first’ 18 | cout << f.first; | ^~~~~ make: *** [src/subdir.mk:20: src/console.o] Error 1

martinus commented 4 years ago

robin_hood maps internally use robin_hood::pair and not std::pair. So either create a robin_hood::pair and insert it, or better use emplace: data.emplace(1, std::make_pair(2, 2));