我使用提供通用优先级队列类型实现的外部库。优先级队列的类(在头文件中声明,称为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 或者更好的 boost 的优先级队列来提供这个实现吗?