当前位置: 首页>>代码示例>>C++>>正文


C++ ItemList::prepend方法代码示例

本文整理汇总了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();
            }
        }
开发者ID:AlbertBaggios,项目名称:wpoanalytics,代码行数:44,代码来源:FPTree.cpp


注:本文中的ItemList::prepend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。