本文整理汇总了C++中index_map_type::end方法的典型用法代码示例。如果您正苦于以下问题:C++ index_map_type::end方法的具体用法?C++ index_map_type::end怎么用?C++ index_map_type::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类index_map_type
的用法示例。
在下文中一共展示了index_map_type::end方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
/**
* Updates the priority associated with a item in the queue. This
* function fails if the item is not already present.
*/
void update(T item, Priority priority) {
// Verify that the item is currently in the queue
typename index_map_type::const_iterator iter = index_map.find(item);
assert(iter != index_map.end());
// If it is already present update the priority
size_t i = iter->second;
heap[i].second = priority;
while ((i > 1) && (priority_at(parent(i)) < priority)) {
swap(i, parent(i));
i = parent(i);
}
heapify(i);
}
示例2: remove
//! Remove an item from the queue
bool remove(T item) {
// Ensure that the element is in the queue
typename index_map_type::iterator iter = index_map.find(item);
// only if the element is present in the first place do we need
// remove it
if(iter != index_map.end()) {
size_t i = iter->second;
swap(i, size());
heap.pop_back();
heapify(i);
// erase the element from the index map
index_map.erase(iter);
return true;
}
return false;
}
示例3: insert_cumulative
/**
* If item is already in the queue, sets its priority to the sum
* of the old priority and the new one. If the item is not in the queue,
* adds it to the queue.
*
* returns true if the item was already present
*/
bool insert_cumulative(T item, Priority priority) {
// determine if the item is already in the queue
typename index_map_type::const_iterator iter = index_map.find(item);
if(iter != index_map.end()) { // already present
// If it is already present update the priority
size_t i = iter->second;
heap[i].second = priority + heap[i].second;
// If the priority went up move the priority until its greater
// than its parent
while ((i > 1) && (priority_at(parent(i)) <= priority)) {
swap(i, parent(i));
i = parent(i);
}
// Trickle down if necessary
heapify(i); // This should not be necessary
return false;
} else { // not already present so simply add
push(item, priority);
return true;
}
} // end of insert cumulative
示例4: get
//! Returns the weight associated with a key
Priority get(T item) const {
typename index_map_type::const_iterator iter = index_map.find(item);
assert(iter != index_map.end());
size_t i = iter->second;
return heap[i].second;
}