微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 C++ 中重新散列单独的链接,对链表的向量

如何解决在 C++ 中重新散列单独的链接,对链表的向量

我正在尝试创建一个重新散列哈希表的函数,该哈希表是链表或对的向量。我现在有:

//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();

}

我遇到了一些错误,而且我对使用配对还很陌生,所以我不太明白我哪里出错了。这些是我收到的错误

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> > > > >’ to non-scalar type ‘std::__cxx11::list<std::pair<int,int> > >’ requested
  240 |      list<pair<K,V>> temp = table;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。