我使用外部库,它提供了一般的优先级队列类型实现。 优先级队列的类(在头文件中声明,称之为priorityQueue.h)是
template <typename KeyType, typename DataType, template <typename datatype> class StorageType>
class PriorityQueue {...};
包含插入函数:
//Insert a key-value pair to the priority queue
void insert( const KeyType& key, const DataType& data, const DescriptorType ptr = 0)
我需要这个优先级队列来存储以下结构的项目:
struct certificate
{
float tfail;
typename GraphType::NodeIterator n;
unsigned int ne, citem;
};
所以我实现了这个功能:
void storeCertificates(const NodeIterator& u, int node_or_edge)
{
//representation: (ne, idn, tfail), for a node identified by idn if we have a min cert (ne= 0), or a tail of an edge identified by idn if we have a pr cert (ne=1)
certificate cert;
int ne;
if(node_or_edge == 0) //min certificate
ne = 0;
else //prim certificate
ne = 1;
cert.ne = ne;
cert.n = u;
cert.tfail = u->tfail;
cert.citem = 0;
c.insert( cert.tfail, cert, cert.citem); //<=========
}
将证书项存储到定义为:
的优先级队列中 typedef PriorityQueue< WeightType, NodeIterator, HeapStorage> PriorityQueueType;
PriorityQueueType c;
在编译时,我收到以下错误:
td_dijkstra_and_os.h:680:2: error: function does not match call to
‘PriorityQueue<float, std::_List_iterator<ALNode<node, edge> >, HeapStorage>::insert(float&, TD_Dijkstra_OS<DynamicGraph<AdjacencyListImpl, node, edge> >::certificate&, unsigned int&)’
td_dijkstra_and_os.h:680:2: note: candidate is:
/home/danuser/eCOMPASS/pgl/include/Structs/Trees/priorityQueue.h:132:10: σημείωση: void PriorityQueue<KeyType, DataType, StorageType>::insert(const KeyType&, const DataType&, PriorityQueue<KeyType, DataType, StorageType>::DescriptorType) [with KeyType = float, DataType = std::_List_iterator<ALNode<node, edge> >, StorageType = HeapStorage, PriorityQueue<KeyType, DataType, StorageType>::DescriptorType = unsigned int*, PQSizeType = unsigned int]
/home/danuser/eCOMPASS/pgl/include/Structs/Trees/priorityQueue.h:132:10: σημείωση: no known conversion for argument 2 from ‘TD_Dijkstra_OS<DynamicGraph<AdjacencyListImpl, node, edge> >::certificate’ to ‘const std::_List_iterator<ALNode<node, edge> >&’
请提供一种正确的方法,将此插入功能用于我的实现。
编辑:有人可以通过使用std :: priority_queue或更好的优先级队列来提供此实现吗?
答案 0 :(得分:2)
DataType
为NodeIterator
,但您尝试插入certificate
。
答案 1 :(得分:1)
您正在为
创建实例 PeiorityQueueType c;
类型
PriorityQueue< WeightType, NodeIterator, HeapStorage>
创建实例后,插入函数将由编译器生成。
void insert(const WeightType& key, const NodeItrator& data, const DescriptorType ptr = 0);
但是你将插入函数称为
c.insert( cert.tfail, cert, cert.citem);
是
template<const float&, const certificate&, unsigned int >.
您声明的数据类型是什么样的。因此,更改函数的调用插入函数数据类型。