本文整理汇总了C++中ItemList::prepend方法的典型用法代码示例。如果您正苦于以下问题:C++ ItemList::prepend方法的具体用法?C++ ItemList::prepend怎么用?C++ ItemList::prepend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ItemList
的用法示例。
在下文中一共展示了ItemList::prepend方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: foreach
/**
* Calculate prefix paths that end with a node that has the given ItemID.
* These nodes can be retrieved very quickly using the FPTree's itemPaths.
* A prefix path is a list of Items that reflects a path from the bottom
* of the tree to the root (but excluding the root), following along the
* path of an FPNode that has the ItemID itemID. Because it is a list of
* Items, it also includes both the ItemID and the SupportCount. The
* original SupportCount of the Item encapsulated by the FPNode is erased
* and replaced by the SupportCount of the FPNode we started from, i.e. a
* node that has the ItemID itemID, because we're looking at only the
* paths that include this node.
* Exclude the leaf node itself, as it will no longer be needed.
*/
QList<ItemList> FPTree::calculatePrefixPaths(ItemID itemID) const {
QList<ItemList> prefixPaths;
ItemList prefixPath;
FPNode<SupportCount> * node;
SupportCount supportCount;
Item item;
QList<FPNode<SupportCount> *> leafNodes = this->getItemPath(itemID);
foreach (FPNode<SupportCount> * leafNode, leafNodes) {
// Build the prefix path starting from the given leaf node, by
// traversing up the tree (but do not include the leaf node's item
// in the prefix path).
// Don't copy the item's original count, but the count of the leaf
// node instead, because we're looking at only the paths that
// include this leaf node.
node = leafNode;
supportCount = leafNode->getValue();
while ((node = node->getParent()) != NULL && node->getItemID() != ROOT_ITEMID) {
item.id = node->getItemID();
item.supportCount = supportCount;
prefixPath.prepend(item);
}
// Store the built prefix path & clear it, so we can calculate the
// next. Of course only if there *is* a prefix path, which is not
// the case if the given itemID is at the root level.
if (prefixPath.size() > 0) {
prefixPaths.append(prefixPath);
prefixPath.clear();
}
}