fork download
  1. void AM_Tree::insert(const map<int, double, item_cmp> &transaction)
  2. {
  3. int depth = 0;
  4. double _util = 0;
  5. double _clo_util = 0;
  6. map<int, double, item_cmp> _util_list;
  7. map<int, double, item_cmp>::const_iterator Tit = transaction.begin(); //iterator開始insert node
  8. map<int, shared_ptr<Node>, item_cmp>::iterator Cit; //iterator指到root children
  9. shared_ptr<Node> Nptr = root;
  10.  
  11. //handle item which is include in root->itemset
  12. if(root->itemset.size() != 0)
  13. {
  14. map<int, double, item_cmp>::const_iterator Rit = transaction.find(root->itemset.back()); //指到目前root最大的item
  15. while(Rit != transaction.end())
  16. {
  17. _util_list.insert(make_pair(Rit->first,Rit->second));
  18. _util += Rit->second;
  19. _clo_util += Rit->second;
  20. Rit++;
  21. }
  22. }
  23. //handle others
  24. while(depth != transaction.size()-root->itemset.size())//here
  25. {
  26. if((Cit = Nptr->children.find(Tit->first)) != Nptr->children.end()) //node exist
  27. Nptr = Cit->second;
  28. else //node didn't exist
  29. {
  30. Nptr->children.insert(make_pair(Tit->first, make_shared<Node>(Node(Tit->first))));
  31. Nptr = Nptr->children[Tit->first];
  32. if(depth) //新node才有可能連到HeaderTable
  33. HeaderTable[Tit->first].push_back(Nptr);
  34. }
  35. _util_list.insert(make_pair(Tit->first, Tit->second));
  36. _clo_util += Tit->second; //plus IUTable clo_util
  37.  
  38. vector<int> index = root->itemset;
  39. index.push_back(Tit->first);
  40. IUTable[index].util += Tit->second + _util; //plus IUTable util
  41. if(depth) {//第二個node以後才需要加clo_util
  42. IUTable[index].clo_util += _clo_util;
  43. map<int, double, item_cmp>::iterator It = _util_list.begin();
  44. for(;It != _util_list.end();++It)
  45. Nptr->util_list[It->first] += It->second;
  46. }
  47. ++Tit;
  48. ++depth;
  49. }
  50. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty