本文整理汇总了C++中map::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ map::erase方法的具体用法?C++ map::erase怎么用?C++ map::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map
的用法示例。
在下文中一共展示了map::erase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
ADDAPP(delaun_distr);
ADDAPP(spellmech);
ADDAPP(short_tests);
ADDAPP(geomtests);
ADDAPP(tests_path);
ADDAPP(test_perlin);
ADDAPP(checkers_box);
ADDAPP(swarming);
ADDAPP(citynet2);
ADDAPP(testbed);
ADDAPP(geomtest_orient);
ADDAPP(holosight);
ADDAPP(recoil_simul);
ADDAPP(recoil_spring);
ADDAPP(bar_bump);
ADDAPP(masonette);
ADDAPP(mild_tests);
ADDAPP(perlin_plain);
/*
ADDAPP(phone_pattern);
ADDAPP(guns_test);
ADDAPP(triangul); // just re add triangul.cpp to the project!
ADDAPP(quadtree_test);
ADDAPP(balldemo);
apps["smoothmouse"] = smoothmouse(window,UI);
ADDAPP(guns_test);
ADDAPP(kdtree);
*/
}
//{
// configfile descr_file;
// descr_file.init("demo_descr.txt");
// set<string> avail;
// for (auto&a : descr_file.dict) avail.insert(a.first);
// for(auto&app :apps)
// {
// if (descr_file.dict.count(app.first))
// {
// avail.erase(app.first);
// }
// }
// for (auto&a : avail)
// {
// msgs("not loaded " + a);
// }
//}
auto dont_load = cfg.getlist("dont_load");
for (auto&a : dont_load)
{
apps.erase(a);
}
//for (auto&a : dont_load) dont_load_these.insert(a);
//auto dont_load_these = split2(dont_load," ");
// read the
string s = cfg.getstr("app");
if (cfg.getvar<int>("use_menu") == 1)
{
while (1)
{
string choice = appchooser(window, UI)();
//int i = 432;
msgs("chosen " + choice);
if (choice != "none")
apps[choice]();
else
{
break;
}
}
}
else
{
if (s == "")
{
msgs("######## error in config, app was not found! ########");
return -2;
}
if (!apps.count(s))
{
msgs("######## app " + s + " not found! ######## ");
throw runtime_error(string("app " + s + " not found!"));
return -2;
}
vector<string> keys;
auto choice = cfg.getstr("app");
show_keys(cfg.getstr("app"), keys);
msgs(choice);
for (auto&a : keys)
msgs(a);
apps[cfg.getstr("app")]();
}
return 0;
}
示例2: AIUpdate
void AIUpdate()
{
uint32 plrcounts[2] = { 0, 0 };
// details:
// loop through inrange players, for new ones, send the enable CP worldstate.
// the value of the map is a timestamp of the last update, to avoid cpu time wasted
// doing lookups of objects that have already been updated
unordered_set<PlayerPointer>::iterator itr = _gameobject->GetInRangePlayerSetBegin();
unordered_set<PlayerPointer>::iterator itrend = _gameobject->GetInRangePlayerSetEnd();
map<uint32,uint32>::iterator it2, it3;
uint32 timeptr = (uint32)UNIXTIME;
bool in_range;
bool is_valid;
PlayerPointer plr = NULLPLR;
for(; itr != itrend; ++itr)
{
if( !(*itr)->IsPvPFlagged() || (*itr)->InStealth() )
is_valid = false;
else
is_valid = true;
in_range = (_gameobject->GetDistanceSq((*itr)) <= BANNER_RANGE) ? true : false;
it2 = StoredPlayers.find((*itr)->GetLowGUID());
if( it2 == StoredPlayers.end() )
{
// new player :)
if( in_range )
{
(*itr)->SendWorldStateUpdate(WORLDSTATE_HELLFIRE_PVP_CAPTURE_BAR_DISPLAY, 1);
(*itr)->SendWorldStateUpdate(WORLDSTATE_HELLFIRE_PVP_CAPTURE_BAR_VALUE, Status);
StoredPlayers.insert(make_pair((*itr)->GetLowGUID(), timeptr));
if( is_valid )
plrcounts[(*itr)->GetTeam()]++;
}
}
else
{
// oldie
if( !in_range )
{
(*itr)->SendWorldStateUpdate(WORLDSTATE_HELLFIRE_PVP_CAPTURE_BAR_DISPLAY, 0);
StoredPlayers.erase(it2);
}
else
{
(*itr)->SendWorldStateUpdate(WORLDSTATE_HELLFIRE_PVP_CAPTURE_BAR_VALUE, Status);
it2->second = timeptr;
if( is_valid )
plrcounts[(*itr)->GetTeam()]++;
}
}
}
// handle stuff for the last tick
if( Status == 100 && m_bannerStatus != BANNER_STATUS_ALLIANCE )
{
m_bannerStatus = BANNER_STATUS_ALLIANCE;
SetArtKit();
// send message to everyone in the zone, has been captured by the Alliance
_gameobject->GetMapMgr()->SendPvPCaptureMessage(ZONE_HELLFIRE_PENINSULA, ZONE_HELLFIRE_PENINSULA, "|cffffff00%s has been taken by the Alliance!|r", ControlPointName);
// tower update
g_allianceTowers++;
UpdateTowerCount(_gameobject->GetMapMgr());
// state update
_gameobject->GetMapMgr()->GetStateManager().UpdateWorldState(g_neutralStateFields[towerid], 0);
_gameobject->GetMapMgr()->GetStateManager().UpdateWorldState(g_allianceStateFields[towerid], 1);
// woot
g_towerOwners[towerid] = 1;
UpdateInDB();
}
else if( Status == 0 && m_bannerStatus != BANNER_STATUS_HORDE )
{
m_bannerStatus = BANNER_STATUS_HORDE;
SetArtKit();
// send message to everyone in the zone, has been captured by the Horde
_gameobject->GetMapMgr()->SendPvPCaptureMessage(ZONE_HELLFIRE_PENINSULA, ZONE_HELLFIRE_PENINSULA, "|cffffff00%s has been taken by the Horde!|r", ControlPointName);
// tower update
g_hordeTowers++;
UpdateTowerCount(_gameobject->GetMapMgr());
// state update
_gameobject->GetMapMgr()->GetStateManager().UpdateWorldState(g_neutralStateFields[towerid], 0);
_gameobject->GetMapMgr()->GetStateManager().UpdateWorldState(g_hordeStateFields[towerid], 1);
// woot
g_towerOwners[towerid] = 0;
UpdateInDB();
}
else if( m_bannerStatus != BANNER_STATUS_NEUTRAL )
//.........这里部分代码省略.........
示例3: remove
void remove() {
pot_.erase(top());
}
示例4: ProcessAlert
bool CAlert::ProcessAlert()
{
if (!CheckSignature())
return false;
if (!IsInEffect())
return false;
// alert.nID=max is reserved for if the alert key is
// compromised. It must have a pre-defined message,
// must never expire, must apply to all versions,
// and must cancel all previous
// alerts or it will be ignored (so an attacker can't
// send an "everything is OK, don't panic" version that
// cannot be overridden):
int maxInt = std::numeric_limits<int>::max();
if (nID == maxInt)
{
if (!(
nExpiration == maxInt &&
nCancel == (maxInt-1) &&
nMinVer == 0 &&
nMaxVer == maxInt &&
setSubVer.empty() &&
nPriority == maxInt &&
strStatusBar == "URGENT: Alert key compromised, upgrade required"
))
return false;
}
{
LOCK(cs_mapAlerts);
// Cancel previous alerts
for (map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();)
{
const CAlert& alert = (*mi).second;
if (Cancels(alert))
{
printf("cancelling alert %d\n", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else if (!alert.IsInEffect())
{
printf("expiring alert %d\n", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else
mi++;
}
// Check if this alert has been cancelled
BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts)
{
const CAlert& alert = item.second;
if (alert.Cancels(*this))
{
printf("alert already cancelled by %d\n", alert.nID);
return false;
}
}
// Add to mapAlerts
mapAlerts.insert(make_pair(GetHash(), *this));
// Notify UI if it applies to me
if(AppliesToMe())
uiInterface.NotifyAlertChanged(GetHash(), CT_NEW);
}
printf("accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
return true;
}
示例5: conn_to_Task
//.........这里部分代码省略.........
printf("All tasks are connected!\n");
Task_All_Connected = true;
}
}
else if(buf_in[0] == '9')
{
int id = 0;
long t = 0;
sscanf(buf_in + sizeof(char) * 2, "%d %ld", &id, &t);
//printf("This id: %d\n", id);
//for(Split_Map_iter = Ongoing_Split.begin(); Split_Map_iter != Ongoing_Split.end(); Split_Map_iter++)
//{
// printf("%d %d\n", Split_Map_iter->first, Split_Map_iter->second.Split_Id);
//}
//printf("%d\n", Unassigned_Split.size());
// Search the Split in Ongoing Map
Split_Map_iter = Ongoing_Split.find(id);
if(Split_Map_iter == Ongoing_Split.end())
{
//printf("Error: no such Split ongoing!\n");
epoll_ctl(epfd, EPOLL_CTL_DEL, tmpfd, &ev);
continue;
}
// Put it into Finished vector
Split tmp_Split(Split_Map_iter->second);
tmp_Split.Finished_Time = t;
Finished_Split.push_back(tmp_Split);
// Erase it from Ongoing Map
Ongoing_Split.erase(Split_Map_iter);
// judge if it is a CPU Task
Task_iter = CPU_Task_Info.find(events[i].data.fd);
Task_Info *tmp_Task;
if(Task_iter == CPU_Task_Info.end())
{
Task_iter = GPU_Task_Info.find(events[i].data.fd);
if(Task_iter == GPU_Task_Info.end())
{
printf("Error: no such Task can be found with ID: %d.\n", events[i].data.fd);
continue;
}
}
tmp_Task = &(Task_iter->second);
// revise information in that Task_Info
Split *new_Split = new Split(tmp_Task->Task_Queue.front());
new_Split->Finished_Time = t;
tmp_Task->Splits_Finish_Time.push_back(*new_Split);
tmp_Task->Task_Queue.pop();
printf("Split %d is done at %ld by Task %d.\n", new_Split->Split_Id, new_Split->Finished_Time, events[i].data.fd);
// To see if Job is complete
printf("Uassigned_Split: %d\nOngoing_Split: %d\n", Unassigned_Split.size(), Ongoing_Split.size());
if(Unassigned_Split.empty() && Ongoing_Split.empty())
{
pthread_mutex_lock(&RM_Mutex);
pthread_cond_signal(&Job_Complete_RM);
pthread_mutex_unlock(&RM_Mutex);
pthread_mutex_lock(&IF_Mutex);
pthread_cond_signal(&Job_Complete_IF);
pthread_mutex_unlock(&IF_Mutex);
示例6: CacheBannerInternal
//.........这里部分代码省略.........
dst->fmt.palette = img->fmt.palette;
}
const float fCustomImageCoords[8] = {
0.02f, 0.78f, // top left
0.22f, 0.98f, // bottom left
0.98f, 0.22f, // bottom right
0.78f, 0.02f, // top right
};
RageSurfaceUtils::BlitTransform( img, dst, fCustomImageCoords );
// SDL_SaveBMP( dst, BannerPath + "-test.bmp" );
delete img;
img = dst;
WasRotatedBanner = true;
}
const int src_width = img->w, src_height = img->h;
int width = img->w / 2, height = img->h / 2;
// int width = img->w, height = img->h;
/* Round to the nearest power of two. This simplifies the actual texture load. */
width = closest(width, power_of_two(width), power_of_two(width) / 2);
height = closest(height, power_of_two(height), power_of_two(height) / 2);
/* Don't resize the image to less than 32 pixels in either dimension or the next
* power of two of the source (whichever is smaller); it's already very low res. */
width = max( width, min(32, power_of_two(src_width)) );
height = max( height, min(32, power_of_two(src_height)) );
RageSurfaceUtils::ApplyHotPinkColorKey( img );
RageSurfaceUtils::Zoom( img, width, height );
/*
* When paletted banner cache is enabled, cached banners are paletted. Cached
* 32-bit banners take 1/16 as much memory, 16-bit banners take 1/8, and paletted
* banners take 1/4.
*
* When paletted banner cache is disabled, cached banners are stored in 16-bit
* RGBA. Cached 32-bit banners take 1/8 as much memory, cached 16-bit banners
* take 1/4, and cached paletted banners take 1/2.
*
* Paletted cache is disabled by default because palettization takes time, causing
* the initial cache run to take longer. Also, newer ATI hardware doesn't supported
* paletted textures, which would slow down runtime, because we have to depalettize
* on use. They'd still have the same memory benefits, though, since we only load
* one cached banner into a texture at once, and the speed hit may not matter on
* newer ATI cards. RGBA is safer, though.
*/
if( PREFSMAN->m_bPalettedBannerCache )
{
if( img->fmt.BytesPerPixel != 1 )
RageSurfaceUtils::Palettize( img );
} else {
/* Dither to the final format. We use A1RGB5, since that's usually supported
* natively by both OpenGL and D3D. */
RageSurface *dst = CreateSurface( img->w, img->h, 16,
0x7C00, 0x03E0, 0x001F, 0x8000 );
/* OrderedDither is still faster than ErrorDiffusionDither, and
* these images are very small and only displayed briefly. */
RageSurfaceUtils::OrderedDither( img, dst );
delete img;
img = dst;
}
const CString CachePath = GetBannerCachePath(BannerPath);
RageSurfaceUtils::SaveSurface( img, CachePath );
if( PREFSMAN->m_BannerCache == PrefsManager::BNCACHE_LOW_RES )
{
/* If an old image is loaded, free it. */
if( g_BannerPathToImage.find(BannerPath) != g_BannerPathToImage.end() )
{
RageSurface *oldimg = g_BannerPathToImage[BannerPath];
delete oldimg;
g_BannerPathToImage.erase(BannerPath);
}
/* Keep it; we're just going to load it anyway. */
g_BannerPathToImage[BannerPath] = img;
}
else
delete img;
/* Remember the original size. */
BannerData.SetValue( BannerPath, "Path", CachePath );
BannerData.SetValue( BannerPath, "Width", src_width );
BannerData.SetValue( BannerPath, "Height", src_height );
BannerData.SetValue( BannerPath, "FullHash", GetHashForFile( BannerPath ) );
/* Remember this, so we can hint Sprite. */
BannerData.SetValue( BannerPath, "Rotated", WasRotatedBanner );
BannerData.WriteFile( BANNER_CACHE_INDEX );
}
示例7:
void
dequeue_answer(int fd)
{
delete pending_writes[fd].second;
pending_writes.erase(fd);
}
示例8: ProcessAlert
bool CAlert::ProcessAlert(const std::vector<unsigned char>& alertKey)
{
if (!CheckSignature(alertKey))
return error("CAlert::ProcessAlert: verify signature failed");
if (!IsInEffect())
return error("CAlert::ProcessAlert: Expired");
// alert.nID=max is reserved for if the alert key is
// compromised. It must have a pre-defined message,
// must never expire, must apply to all versions,
// and must cancel all previous
// alerts or it will be ignored (so an attacker can't
// send an "everything is OK, don't panic" version that
// cannot be overridden):
int maxInt = std::numeric_limits<int>::max();
if (nID == maxInt)
{
if (!(
nExpiration == maxInt &&
nCancel == (maxInt-1) &&
nMinVer == 0 &&
nMaxVer == maxInt &&
setSubVer.empty() &&
nPriority == maxInt &&
strStatusBar == "URGENT: Alert key compromised, upgrade required"
))
return false;
}
{
LOCK(cs_mapAlerts);
// Cancel previous alerts
for (map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();)
{
const CAlert& alert = (*mi).second;
if (Cancels(alert))
{
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else if (!alert.IsInEffect())
{
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else
mi++;
}
// Check if this alert has been cancelled
for (auto& item : mapAlerts)
{
const CAlert& alert = item.second;
if (alert.Cancels(*this))
return error("CAlert::ProcessAlert: Cancelled");
}
// Add to mapAlerts
mapAlerts.insert(make_pair(GetHash(), *this));
if(AppliesToMe())
{
uiInterface.NotifyAlertChanged(GetHash(), CT_NEW);
Notify(strStatusBar);
}
}
return true;
}
示例9: erase
void erase(int key) {
int old_time = key_to_time[key];
time_to_key.erase(old_time);
key_to_time.erase(key);
key_to_value.erase(key);
}
示例10: main
int main(int argc,char *argv[])
{
//Seed RNG
srand(time(NULL));
//get socket
listenfd = socket(AF_INET, SOCK_STREAM, 0);
if (listenfd == -1)
err(1, "socket");
int g = 1;
signal(SIGPIPE, SIG_IGN);
//ignore sigpipes
setsockopt(listenfd,SOL_SOCKET,SO_REUSEADDR,&g,sizeof(int));
//force drop other applications on the same port
//fcntl(listenfd, F_SETFL, O_NONBLOCK);
memset(&serv_addr, '0', sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(6667);
if (bind(listenfd, (struct sockaddr*)&serv_addr,sizeof(serv_addr)) == -1)
err(1, "bind to port %d", ntohs(serv_addr.sin_port));
if(listen(listenfd, 10) == -1){
printf("Failed to listen\n");
return -1;
}
thread z(ControlServer);
z.detach();
//again because we spawned a thread
signal(SIGPIPE, SIG_IGN);
while(true)
{
{
mutex_guard lock(connections_mutex);
auto dead_connections = std::remove_if(connections.begin(), connections.end(),
[&](User const *u){ return u->dead; });
for (auto it = dead_connections; it != connections.end(); it++)
delete *it;
connections.erase(dead_connections, connections.end());
for (User *puser : connections)
{
User &user = *puser;
string command_str = user.try_read();
if (user.dead) continue;
chop_newline_off(command_str);
vector<string> command = parse_irc_command(command_str);
if (!command.empty())
{
cout << "\033[91m← " << user.username << "\t" << command_str << "\033[m" << endl;
if(command[0] == "USER")
{
//stub incase anyone wants to implement authentication
}
else if(command[0] == "PING")
{
user.write(":tinyirc PONG :" + command[1] + "\r\n");
}
else if(command[0] == "PONG" && user.status != User::ConnectStatus::NICKSET)
{
//reset anti-drop
user.dontkick = true;
user.rticks = 0;
}
else if(command[0] == "PONG" && user.status == User::ConnectStatus::NICKSET)
{
//oh nice, you accepted our PING, welcome to the party
user.write(":tinyirc 001 " + user.username + " :Hello!" + "\r\n");
user.write(":tinyirc 002 " + user.username + " :This server is running TinyIRC pre-alpha!" + "\r\n");
user.write(":tinyirc 003 " + user.username + " :This server doesn't have date tracking." + "\r\n");
user.write(":tinyirc 004 " + user.username + " tinyirc " + " tinyirc(0.0.1) " + "CDGNRSUWagilopqrswxyz" + " BCIMNORSabcehiklmnopqstvz" + " Iabehkloqv" + "\r\n");
user.write(":tinyirc 005 " + user.username + " CALLERID CASEMAPPING=rfc1459 DEAF=D KICKLEN=180 MODES=4 PREFIX=(qaohv)~&@%+ STATUSMSG=~&@%+ EXCEPTS=e INVEX=I NICKLEN=30 NETWORK=tinyirc MAXLIST=beI:250 MAXTARGETS=4 :are supported by this server\r\n");
user.write(":tinyirc 005 " + user.username + " CHANTYPES=# CHANLIMIT=#:500 CHANNELLEN=50 TOPICLEN=390 CHANMODES=beI,k,l,BCMNORScimnpstz AWAYLEN=180 WATCH=60 NAMESX UHNAMES KNOCK ELIST=CMNTU SAFELIST :are supported by this server\r\n");
user.write(":tinyirc 251 " + user.username + " :LUSERS is unimplemented." + "\r\n");
user.status = User::ConnectStatus::READY;
user.dontkick = true;
}
else if(command[0] == "NICK")
{
string new_nick = remove_erase_if(command[1], ".,#\r");
if(new_nick.size() > 225 || new_nick.size() == 0)
new_nick = "FAGGOT" + to_string(rand() % 9000);
bool inuse = false;
if (usersbyname.find(new_nick) != usersbyname.end())
inuse = true;
//if not authed, set username and PING, else set username
if(user.status == User::ConnectStatus::CONNECTED)
{
user.username = new_nick;
if(inuse)
{
//.........这里部分代码省略.........
示例11: del_local
void del_local(const string& key)
{ local_frame_.erase(key); }
示例12: cal
ll cal(int num)
{
map<int,int> map1,mapbd;
mapp.clear();
memset(s,0,sizeof(s));
memset(val,0,sizeof(val));
qoi=0;
for(int i=n-1;i>=0;--i)
{
int tmp=p[i].second;
mapp[tmp]=tmp;
++qoi,q[qoi][0]=i,q[qoi][1]=s[tmp],s[tmp]=qoi;
}
ll r(0);
for(int i=0;i<n;)
{
// cout<<"* "<<i<<' '<<val[i]<<endl;
// cout<<"--------"<<endl;
// for(ite=map1.begin();ite!=map1.end();++ite)
// cout<<ite->first<<' '<<ite->second<<endl;
// cout<<endl<<endl;
int j=i;
for(;p[j].first==p[i].first;++j)
{
int tmp=p[j].second;
int v=val[q[s[tmp]][0]];
if(v)
{
for(;v>0;)
{
ite=map1.lower_bound(tmp);
int tz=min(ite->second,v);
ite->second-=tz;
v-=tz;
//cout<<'!'<<j<<' '<<tz<<endl;
r+=tz;
if(ite->second<=0)
map1.erase(ite);
}
mapbd.erase(tmp);
}
s[tmp]=q[s[tmp]][1];
if(s[tmp]==0)
mapp.erase(tmp);
}
// cout<<"--------------------"<<endl;
// for(ite=map1.begin();ite!=map1.end();++ite)
// cout<<ite->first<<' '<<ite->second<<endl;
// cout<<endl<<endl;
int k=i;
for(;i<j;++i)
{
int tmp=p[i].second;
ite=mapbd.upper_bound(tmp);
int c=(ite==mapbd.end()?num+1:ite->first);
ite=map1.upper_bound(tmp);
//cout<<"**"<<ite->first<<' '<<ite->second<<endl;
for(;ite!=map1.end() && ite->first<=c;)
{
map1[tmp]+=ite->second;
//cout<<"!!"<<i<<' '<<ite->first<<' '<<ite->second<<endl;
r+=ite->second;
ii=ite;
++ite;
map1.erase(ii);
}
}
i=k;
for(;i<j;++i)
{
ite=mapp.lower_bound(p[i].second);
int c=(i==j-1?num:p[i+1].second);
if(ite!=mapp.end() && ite->first<c)
{
//cout<<"add "<<i<<' '<<ite->first<<' '<<c<<endl;
mapbd[ite->first]=1;
++val[q[s[ite->first]][0]];
++map1[c];
if(ite->first==p[i].second)
--r;
}
}
}
return r;
}
示例13: RunRetransThread
//.........这里部分代码省略.........
} else if (timeout_set.find(retx_request->msg_id) != timeout_set.end()) {
continue;
}
// check whether the retransmission for the file has already time out
if (GetElapsedSeconds(meta->multicast_start_cpu_time) > meta->retx_timeout_seconds) {
//cout << "Retx timeout for file " << retx_request->msg_id << ". Elapsed Time: "
// << GetElapsedSeconds(meta->multicast_start_cpu_time) << " Timeout: " << meta->retx_timeout_seconds << endl;
send_header->session_id = retx_request->msg_id;
send_header->flags = FMTP_RETRANS_TIMEOUT;
send_header->data_len = 0;
retrans_tcp_server->SelectSend(sock_fd, send_buf, FMTP_HLEN);
timeout_set.insert(retx_request->msg_id);
}
else if (meta->is_disk_file) { // is disk file transfer
FileMessageMetadata* file_meta = (FileMessageMetadata*)meta;
// get the file descriptor to read data from the file
int fd;
if ( (it = retrans_fd_map.find(recv_header->session_id)) != retrans_fd_map.end()) {
fd = it->second;
}
else {
if ( (fd = open(file_meta->file_name.c_str(), O_RDONLY)) < 0)
SysError("FMTPSender::RunRetransThread() file open error");
else
retrans_fd_map[recv_header->session_id] = fd;
}
// send the missing blocks to the receiver
lseek(fd, retx_request->seq_num, SEEK_SET);
size_t remained_size = retx_request->data_len;
size_t curr_pos = retx_request->seq_num;
send_header->session_id = recv_header->session_id;
send_header->flags = FMTP_RETRANS_DATA;
while (remained_size > 0) {
size_t data_length =
remained_size > FMTP_DATA_LEN ? FMTP_DATA_LEN
: remained_size;
send_header->seq_number = curr_pos;
send_header->data_len = data_length;
read(fd, send_packet_data, send_header->data_len);
retrans_tcp_server->SelectSend(sock_fd, send_buf, FMTP_HLEN + send_header->data_len);
curr_pos += data_length;
remained_size -= data_length;
// Update statistics
send_stats.total_retrans_packets++;
send_stats.total_retrans_bytes += send_header->data_len;
//file_meta->stats.session_retrans_packets++;
//file_meta->stats.session_retrans_bytes += header->data_len;
}
}
else { // is memory data transfer
}
}
else if (recv_header->flags & FMTP_RETRANS_END) {
if (retrans_tcp_server->Receive(sock_fd, retx_request, recv_header->data_len) < 0) {
SysError("FMTPSender::RunRetransThread()::receive retx end msg error");
}
// send back the retransmission end message to the receiver
send_header->session_id = recv_header->session_id;
send_header->seq_number = 0;
send_header->data_len = 0;
send_header->flags = FMTP_RETRANS_END;
retrans_tcp_server->SelectSend(sock_fd, send_header, FMTP_HLEN);
map<uint, int>::iterator it = retrans_fd_map.find(recv_header->session_id);
if ( it != retrans_fd_map.end() ) {
close(it->second);
retrans_fd_map.erase(it);
}
if ( timeout_set.find(recv_header->session_id) != timeout_set.end() )
timeout_set.erase(recv_header->session_id);
// mark the completion of retransmission to one receiver
metadata.RemoveFinishedReceiver(recv_header->session_id, sock_fd);
}
else if (recv_header->flags & FMTP_HISTORY_STATISTICS) {
char* buf = new char[recv_header->data_len + 1];
if (retrans_tcp_server->Receive(sock_fd, buf, recv_header->data_len) < 0) {
break;
}
buf[recv_header->data_len] = '\0';
status_proxy->SendMessageLocal(EXP_RESULT_REPORT, buf);
delete[] buf;
cout << "Received a history statistics from socket " << sock_fd << endl;
}
}
cout << "Retransmission thread exited for socket " << sock_fd << endl;
}
示例14: getdis
double getdis(int stx, int sty, int enx, int eny) {
pid ex;
pq.push(make_pair(0, make_pair(stx, sty)));
int i;
int j;
if (board[stx][sty] == 1) {
return 0;
}
int test;
while (!pq.empty()) {
ex = pq.top();
pq.pop();
mp1.insert(make_pair(ex.second, 1));
mp.erase(ex.second);
i = ex.second.first;
j = ex.second.second;
if ((ex.second.first == enx) && (ex.second.second == eny)) {
return ex.first;
}
if ((j + 1 < m) && (board[i][j + 1] == 0) && (mp1.count(make_pair(i, j+1)) == 0)) {
if (mp.count(make_pair(i, j + 1)) == 0) {
pq.push(make_pair(ex.first + 1, make_pair(i, j+1)));
mp.insert(make_pair(make_pair(i,j + 1),ex.first + 1));
}
else {
test = mp[make_pair(i, j + 1)];
if (test > ex.first + 1) {
pq.push(make_pair(ex.first + 1, make_pair(i, j+1)));
mp[make_pair(i,j+1)] = ex.first + 1;
}
}
}
if (((j + 1 < m) && (i + 1 < n)) && (board[i + 1][j + 1] == 0) && (mp1.count(make_pair(i + 1, j+1)) == 0)) {
if (mp.count(make_pair(i + 1, j + 1)) == 0) {
pq.push(make_pair(ex.first + rt2, make_pair(i + 1, j+1)));
mp.insert(make_pair(make_pair(i + 1,j + 1),ex.first + rt2));
}
else {
test = mp[make_pair(i + 1, j + 1)];
if (test > ex.first + rt2) {
pq.push(make_pair(ex.first + rt2, make_pair(i+1, j+1)));
mp[make_pair(i+1,j+1)] = ex.first + rt2;
}
}
}
if ((i + 1 < n) && (board[i+1][j] == 0) && (mp1.count(make_pair(i + 1, j)) == 0)) {
if (mp.count(make_pair(i + 1, j)) == 0) {
pq.push(make_pair(ex.first + 1, make_pair(i + 1, j)));
mp.insert(make_pair(make_pair(i + 1,j),ex.first + 1));
}
else {
test = mp[make_pair(i + 1, j)];
if (test > ex.first + 1) {
pq.push(make_pair(ex.first + 1, make_pair(i + 1, j)));
mp[make_pair(i+1,j)] = ex.first + 1;
}
}
}
if (((j - 1 >= 0) && (i + 1 < n)) && (board[i + 1][j - 1] == 0) && (mp1.count(make_pair(i + 1, j-1)) == 0)) {
if (mp.count(make_pair(i + 1, j - 1)) == 0) {
pq.push(make_pair(ex.first + rt2, make_pair(i + 1, j-1)));
mp.insert(make_pair(make_pair(i + 1,j - 1),ex.first + rt2));
}
else {
test = mp[make_pair(i + 1, j - 1)];
if (test > ex.first + rt2) {
pq.push(make_pair(ex.first + rt2, make_pair(i+1, j-1)));
mp[make_pair(i+1,j-1)] = ex.first + rt2;
}
}
}
if ((j - 1 >= 0) && (board[i][j - 1] == 0) && (mp1.count(make_pair(i, j-1)) == 0)) {
if (mp.count(make_pair(i, j - 1)) == 0) {
pq.push(make_pair(ex.first + 1, make_pair(i, j - 1)));
mp.insert(make_pair(make_pair(i,j - 1),ex.first + 1));
}
else {
test = mp[make_pair(i, j - 1)];
if (test > ex.first + 1) {
pq.push(make_pair(ex.first + 1, make_pair(i, j - 1)));
mp[make_pair(i,j-1)] = ex.first + 1;
}
}
}
if (((j - 1 >= 0) && (i - 1 >= 0)) && (board[i - 1][j - 1] == 0) && (mp1.count(make_pair(i-1, j-1)) == 0)) {
if (mp.count(make_pair(i - 1, j - 1)) == 0) {
pq.push(make_pair(ex.first + rt2, make_pair(i - 1, j-1)));
mp.insert(make_pair(make_pair(i - 1,j - 1),ex.first + rt2));
}
//.........这里部分代码省略.........
示例15: check_overlapping_nodes
void check_overlapping_nodes(::std::vector<table_entry*> & links, map<unsigned long long, string> & chains, int len,
::std::map<unsigned long long, unsigned long long>& mapping, unsigned int min_overlap,
int ov_perc){
::std::map<unsigned long long, string>::iterator chain_it;
::std::map<unsigned long long, string>::iterator chain_it_2;
::std::vector<small_frag> short_blocks;
stack<unsigned int> s;
queue<unsigned long long> q;
for(chain_it = chains.begin(); chain_it != chains.end(); ++chain_it){
for(chain_it_2 = chains.begin(); chain_it_2 != chains.end(); ++chain_it_2){
unsigned int ov = overlappedStringLength(chain_it->second,chain_it_2->second);
if(chain_it != chain_it_2 && ov < (ov_perc*chain_it->second.length())/100 &&
(ov_perc*ov < chain_it_2->second.length())/100 && ov > min_overlap){
bool new_node = false;
CharString pat_text=prefix(chain_it_2->second,ov);
//::std::cout << chain_it->second << ::std::endl;
//::std::cout << chain_it_2->second << ::std::endl;
//::std::cout << ov << ::std::endl;
Pattern<CharString, ShiftAnd> pattern(pat_text);
for(unsigned int i=0; i<links.size();++i){
CharString link_read = links[i]->get_short_read()->get_RNA_seq_sequence();
Finder<CharString> finder(link_read);
if(find(finder,pattern) && (
prefix(link_read,beginPosition(finder)) == infix(chain_it->second,chain_it->second.length()-ov-beginPosition(finder),chain_it->second.length()-ov) ||
suffix(link_read,length(link_read) - endPosition(finder)) == infix(chain_it_2->second,ov,ov+endPosition(finder)))){
//::std::cout << link_read << ::std::endl;
//::std::cout << prefix(link_read,beginPosition(finder)) << ::std::endl;
//::std::cout << infix(chain_it->second,chain_it->second.length()-ov-beginPosition(finder),chain_it->second.length()-ov) << ::std::endl;
//::std::cout << suffix(link_read,length(link_read) - endPosition(finder)) << ::std::endl;
//::std::cout << infix(chain_it_2->second,ov,ov+endPosition(finder)) << ::std::endl;
new_node = true;
}
}
if(new_node){
small_frag f;
f.frag_links.D_chain = chain_it->first;
f.frag_links.A_chain = chain_it_2->first;
f.frag = prefix(chain_it_2->second,ov);
short_blocks.push_back(f);
}
}else{
if(chain_it != chain_it_2 && ov>=(ov_perc*chain_it->second.length())/100){
//::std::cout << "Chain_it sub-node of Chain_it_2" << ::std::endl;
//::std::cout << "Chain_it " << chain_it->second << ::std::endl;
//::std::cout << "Chain_it_2 " << chain_it_2->second << ::std::endl;
//::std::cout << ov << ::std::endl;
q.push(chain_it->first);
}else{
if(chain_it != chain_it_2 && ov>=(ov_perc*chain_it_2->second.length())/100){
//::std::cout << "Chain_it_2 sub-node of Chain_it" << ::std::endl;
//::std::cout << "Chain_it " << chain_it->second << ::std::endl;
//::std::cout << "Chain_it_2 " <<chain_it_2->second << ::std::endl;
//::std::cout << ov << ::std::endl;
q.push(chain_it_2->first);
}
}
}
}
}
for(unsigned int i=0; i<short_blocks.size(); ++i){
bool sub_seq = false;
for(unsigned int k=0; k<short_blocks.size(); ++k){
if(short_blocks[i].frag == short_blocks[k].frag && i<k){
links_pair erased_links;
erased_links.D_chain = short_blocks[i].frag_links.D_chain;
erased_links.A_chain = short_blocks[i].frag_links.A_chain;
short_blocks[k].other_links.push_back(erased_links);
sub_seq = true;
}
if(i!=k && (::seqan::length(short_blocks[i].frag)) < (::seqan::length(short_blocks[k].frag))){
Finder<CharString> finder(short_blocks[k].frag);
Pattern<CharString, ShiftAnd> pattern(short_blocks[i].frag);
if(find(finder,pattern)){
links_pair erased_links;
erased_links.D_chain = short_blocks[i].frag_links.D_chain;
erased_links.A_chain = short_blocks[i].frag_links.A_chain;
//::std::cout << i << k << " - " << beginPosition(finder) << " " << endPosition(finder) << ::std::endl;
short_blocks[k].other_links.push_back(erased_links);
sub_seq = true;
}
}
}
if(sub_seq){
s.push(i);
}
}
while(!s.empty()){
short_blocks.erase(short_blocks.begin()+s.top());
s.pop();
}
while(!q.empty()){
chains.erase(q.front());
q.pop();
}
for(unsigned int i=0; i<short_blocks.size(); ++i){
//::std::cout << short_blocks[i].frag << " " << length(short_blocks[i].frag) << ::std::endl;
//.........这里部分代码省略.........