void UserLoginData::AppendUserFriends(MyUtil::Int2IntSeqMap& result, const MyUtil::IntSeq& userFriends, const MyUtil::Int2IntSeqMap& negtiveFriendsMap) { MCE_INFO("[UserLoginData] AppendUserFriends"); for (Int2IntSeqMap::iterator iter = result.begin(); iter != result.end(); ++iter) { IntSeq& recommendList = iter->second; IntSeq tempRecommendList(recommendList); Int2IntSeqMap::const_iterator fIt = negtiveFriendsMap.find(iter->first); if (fIt != negtiveFriendsMap.end() && !recommendList.empty()) { for (IntSeq::const_iterator it = userFriends.begin(); it != userFriends.end(); ++it) { if (find(tempRecommendList.begin(), tempRecommendList.end(), *it) != tempRecommendList.end()) { //过滤好友中已经推出的好友 continue; } UserLoginMapType::iterator ff = _userLoginMap.find( *it ); if (ff == _userLoginMap.end() || (int)ff->second.count() < ACTIVEDAYS) { //过滤不活跃的推荐 continue; } vector<int>::const_iterator userFriendIter = lower_bound(fIt->second.begin(), fIt->second.end(), *it); //过滤好友列表 if (userFriendIter == fIt->second.end() || *userFriendIter != *it) { recommendList.push_back(*it); } } } } }
void BuddyByAddTimeLoaderAdapter::load( const MyUtil::Int2IntSeqMap& lists ){ MCE_DEBUG( "[BuddyByAddTimeLoaderAdapter::load] lists.size()=" << lists.size() ); try { getProxy( 0 )->load( lists ); } catch (Ice::Exception& e) { ostringstream info; for (MyUtil::Int2IntSeqMap::const_iterator ui = lists.begin(); ui != lists.end(); ++ui) { info << ui->first << " "; } MCE_WARN("BuddyByAddTimeLoaderAdapter::load, Ice::Exception: " << e.what() << " ids: " << info.str()); } catch (std::exception& e) { MCE_WARN("BuddyByAddTimeLoaderAdapter::load,Exception: " << e.what()); } catch (...) { MCE_WARN("BuddyByAddTimeLoaderAdapter::load,Exception"); } }
void MyUtil::__writeInt2IntSeqMap(::IceInternal::BasicStream* __os, const ::MyUtil::Int2IntSeqMap& v) { __os->writeSize(::Ice::Int(v.size())); ::MyUtil::Int2IntSeqMap::const_iterator p; for(p = v.begin(); p != v.end(); ++p) { __os->write(p->first); if(p->second.size() == 0) { __os->writeSize(0); } else { __os->write(&p->second[0], &p->second[0] + p->second.size()); } } }
map<int, map<int,UnivData> > UnivLinkFriends::linkFriends(map<int, map<int,UnivData> >& uds){ map<int, map<int,UnivData> > res; int bTotal = 0; int aTotal = 0; for (map<int, map<int,UnivData> >::iterator itMap1 = uds.begin(); itMap1 != uds.end(); ++itMap1) { IntSeq ids; for ( map<int,UnivData>::iterator itMap2 = itMap1->second.begin(); itMap2 != itMap1->second.end(); ++itMap2) { ids.push_back( itMap2->first ); } bTotal += itMap1->second.size(); map<int,string> friends; MyUtil::Int2IntSeqMap buddies = xce::buddy::adapter::BuddyByAddTimeCacheAdapter::instance().getFriendLists(ids); for( MyUtil::Int2IntSeqMap::iterator it1=buddies.begin(); it1!=buddies.end(); ++it1 ){ if( it1->second.size() <= 0 ){ continue; } string& guestStr = friends[it1->first]; for( MyUtil::IntSeq::iterator it2=it1->second.begin(); it2!=it1->second.end(); ++it2 ){ guestStr = guestStr + "" + boost::lexical_cast<string>(*it2) + ","; } } aTotal += friends.size(); cout << "[UnivLinkFriends::linkFriends] linking mod " << itMap1->first << " size/fSize: " << itMap1->second.size() << "/" << friends.size() << endl; for ( map<int,string>::iterator itMap3 = friends.begin(); itMap3 != friends.end(); ++itMap3) { map<int,UnivData>::iterator itMap4 = itMap1->second.find( itMap3->first ); UnivData ud = itMap4->second; ud.has_friends = true; ud.friend_list = itMap3->second; res[itMap1->first].insert( make_pair(itMap4->first,ud) ); } } cout << "[UnivLinkFriends::linkFriends] size/linkedSize: " << bTotal << "/" << aTotal << endl; return res; }
MyUtil::Int2IntSeqMap BuddyByAddTimeCacheAdapter::getFriendLists(const MyUtil::IntSeq& ids){ if (ids.empty()){ return MyUtil::Int2IntSeqMap(); } size_t numCluster_sizeT = getCluster(); int numCluster = (int)numCluster_sizeT; if (numCluster < 0) { MCE_WARN("[BuddyByAddTimeCacheAdapter::getFriendLists] this should not be seen! Why cluster=" << numCluster_sizeT << " ???" ); return MyUtil::Int2IntSeqMap(); } if (numCluster == 0 || numCluster == 1) { try { return getProxy(ids.at(0))->getFriendLists(ids); } catch (...) { return MyUtil::Int2IntSeqMap(); } } else { vector< vector<int> > seperatedIds; seperatedIds.resize( numCluster ); for( MyUtil::IntSeq::const_iterator it = ids.begin(); it != ids.end(); ++it ){ seperatedIds.at( *it % numCluster ).push_back( *it ); } MyUtil::Int2IntSeqMap result; for (int posCluster = 0; posCluster < numCluster; ++posCluster) { MyUtil::Int2IntSeqMap someResult; if( seperatedIds.at(posCluster).size() > 0 ){ try { someResult = getProxy(posCluster)->getFriendLists(seperatedIds.at(posCluster)); } catch (...) { MCE_WARN( "BuddyByAddTimeCacheAdapter::getFriendLists from Proxy(" << posCluster << ") handle unknown exception." ); } result.insert( someResult.begin(), someResult.end() ); } } return result; } }
void CommonFriendCalculator::buildWeight(const MyUtil::Int2IntSeqMap& users, int weight) { MCE_DEBUG("build " << _userId << " size=" << users.size()); try { for(MyUtil::Int2IntSeqMap::const_iterator i=users.begin(); i!=users.end(); ++i) { for(MyUtil::IntSeq::const_iterator ui=i->second.begin();ui!=i->second.end();++ui) { _weightCount[*ui] += weight; MyUtil::Int2IntSeqMap::iterator sIt = _shareCount.find(*ui); if(sIt == _shareCount.end()) { MyUtil::IntSeq firstShares; firstShares.push_back( i->first ); _shareCount.insert(make_pair(*ui, firstShares)); } else { sIt->second.push_back( i->first ); } } } } catch(Ice::Exception& e) { MCE_WARN("buildUser IceException " << _userId << e.what()); } catch(std::exception& e) { MCE_WARN("buildUser stdException " << _userId << e.what()); } catch(...) { MCE_WARN("buildUser exception " << _userId); } }