I am trying to make a function that rehashes a hash table which is a vector of linked lists or pairs. I have right now:
//Resizes the hash to contain at least n buckets
void rehash(int n) {
list<pair<K,V>> temp = table;
clear();
buckets = findNextPrime(n);
table.resize(buckets);
for (int i = 0; i < temp.size(); i++) {
list<pair<K,V> lst = temp[i];
for (pair<K,V> item : lst) {
this -> insert(item);
}
}
temp.clear();
}
I am getting a couple errors and I am very new to working with pairs, so I don't understand quite where I'm going wrong. These are the errors I'm getting:
ChainingHash.h:247:34: error: template argument 1 is invalid
247 | list<pair<K,V> lst = temp[i];
| ^
ChainingHash.h:247:34: error: template argument 2 is invalid
ChainingHash.h:248:29: error: ‘lst’ was not declared in this scope; did you mean ‘lstat’?
248 | for (pair<K,V> item : lst) {
ChainingHash.h:240:29: error: conversion from ‘std::vector<std::__cxx11::list<std::pair<int, int>, std::allocator<std::pair<int, int> > >, std::allocator<std::__cxx11::list<std::pair<int, int>, std::allocator<std::pair<int, int> > > > >’ to non-scalar type ‘std::__cxx11::list<std::pair<int, int>, std::allocator<std::pair<int, int> > >’ requested
240 | list<pair<K,V>> temp = table;
Aucun commentaire:
Enregistrer un commentaire