本文整理汇总了C++中multimap::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ multimap::begin方法的具体用法?C++ multimap::begin怎么用?C++ multimap::begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multimap
的用法示例。
在下文中一共展示了multimap::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
void process() {
set<long> trackElements;
for (multimap<long, long>::iterator itr = trackElement_sensors.begin();
itr != trackElement_sensors.end();) {
multimap<long, long>::iterator curr = itr;
while (itr != trackElement_sensors.end() && itr->first == curr->first) {
trackElements.insert(itr->first);
++itr;
}
}
long n = 0;
for (set<long>::iterator it = switches.begin(); it != switches.end(); it++) {
if (trackElements.find(*it) == trackElements.end()) {
n++;
}
}
cout << "Results: " << n << endl;
}
示例2: sendResponse
long sendResponse(istream& in, long status) {
string hdr = string("Connection: close\r\n");
for (multimap<string,string>::const_iterator i=m_response_headers.begin(); i!=m_response_headers.end(); ++i)
hdr += i->first + ": " + i->second + "\r\n";
// We can't return 200 OK here or else the filter is bypassed
// so custom Shib errors will get turned into a generic page.
const char* codestr="Status: 500 Server Error";
switch (status) {
case XMLTOOLING_HTTP_STATUS_UNAUTHORIZED: codestr="Status: 401 Authorization Required"; break;
case XMLTOOLING_HTTP_STATUS_FORBIDDEN: codestr="Status: 403 Forbidden"; break;
case XMLTOOLING_HTTP_STATUS_NOTFOUND: codestr="Status: 404 Not Found"; break;
}
cout << codestr << "\r\n" << hdr << "\r\n";
char buf[1024];
while (in) {
in.read(buf,1024);
cout.write(buf, in.gcount());
}
return SHIB_RETURN_DONE;
}
示例3: sendResponse
long sendResponse(istream& in, long status) {
string hdr = string("Connection: close\r\n");
for (multimap<string,string>::const_iterator i=m_headers.begin(); i!=m_headers.end(); ++i)
hdr += i->first + ": " + i->second + "\r\n";
const char* codestr="Status: 200 OK";
switch (status) {
case XMLTOOLING_HTTP_STATUS_ERROR: codestr="Status: 500 Server Error"; break;
case XMLTOOLING_HTTP_STATUS_UNAUTHORIZED: codestr="Status: 401 Authorization Required"; break;
case XMLTOOLING_HTTP_STATUS_FORBIDDEN: codestr="Status: 403 Forbidden"; break;
case XMLTOOLING_HTTP_STATUS_NOTFOUND: codestr="Status: 404 Not Found"; break;
case XMLTOOLING_HTTP_STATUS_NOTMODIFIED: codestr="Status: 304 Not Modified"; break;
}
cout << codestr << "\r\n" << hdr << "\r\n";
char buf[1024];
while (in) {
in.read(buf,1024);
cout.write(buf, in.gcount());
}
return SHIB_RETURN_DONE;
}
示例4: returnMimeHandler
/* Return mime handler to pool */
void returnMimeHandler(RecollFilter *handler)
{
typedef multimap<string, RecollFilter*>::value_type value_type;
if (handler == 0) {
LOGERR(("returnMimeHandler: bad parameter\n"));
return;
}
handler->clear();
PTMutexLocker locker(o_handlers_mutex);
LOGDEB(("returnMimeHandler: returning filter for %s cache size %d\n",
handler->get_mime_type().c_str(), o_handlers.size()));
// Limit pool size. The pool can grow quite big because there are
// many filter types, each of which can be used in several copies
// at the same time either because it occurs several times in a
// stack (ie mail attachment to mail), or because several threads
// are processing the same mime type at the same time.
multimap<string, RecollFilter *>::iterator it;
if (o_handlers.size() >= max_handlers_cache_size) {
static int once = 1;
if (once) {
once = 0;
for (it = o_handlers.begin(); it != o_handlers.end(); it++) {
LOGDEB1(("Cache full. key: %s\n", it->first.c_str()));
}
LOGDEB1(("Cache LRU size: %u\n", o_hlru.size()));
}
if (o_hlru.size() > 0) {
it = o_hlru.back();
o_hlru.pop_back();
delete it->second;
o_handlers.erase(it);
}
}
it = o_handlers.insert(value_type(handler->get_id(), handler));
o_hlru.push_front(it);
}
示例5: SaveUnvisitedUrl
/*这个函数在我们强制中断程序的时候,将map_urls
中没有访问完的url放入pse_unvisited_url.txt文件中,
扩充了我们的种子URL库*/
void SaveUnvisitedUrl()
{
ofstream ofs_unvisited_url;
ofs_unvisited_url.open(UNVISITED_FILE.c_str(),
ios::in | ios::out | ios::trunc | ios::binary);//以二进制可追加的方式打开文件
if(!ofs_unvisited_url)//打开文件失败
{
cerr<<"can not open the file "<<UNVISITED_FILE<<endl;
exit(-1);
}
//将map_urls中没有访问完的url放入pse_unvisited.url文件中,扩充了我们的URL种子库
multimap<string,string> ::iterator it;
for(it=map_urls.begin();it != map_urls.end();it++)
{
ofs_unvisited_url<<(*it).second.c_str()<<"\n";
}
ofs_unvisited_url<<endl;
ofs_unvisited_url.close();
}
示例6: book
bool book(int start, int end) {
auto p = make_pair(start, end);
if(isAlreadyBookingTwice(p))
return false;
auto it = intervals.insert(make_pair(p, end));
if(it != intervals.begin()) {
auto prevIt = prev(it);
if(prevIt->second > start) {
auto newOverlap = make_pair(start, min(prevIt->second, end));
overlaps.insert(newOverlap);
}
it->second = max(prevIt->second, end);
}
auto nextIt = next(it);
while(nextIt != intervals.end() && nextIt->first.first < end) {
auto newOverlap = make_pair(nextIt->first.first,
min(nextIt->first.second, end));
overlaps.insert(newOverlap);
nextIt->second = max(nextIt->second, end);
nextIt = next(nextIt);
}
return true;
}
示例7: CasValueProcess
void CCacheThread::CasValueProcess(const multimap<unsigned int, string> &mapRequestValue, multimap<unsigned int, string> &mapStoredValue)
{
CVS_XLOG(XLOG_DEBUG, "CCacheThread::%s\n", __FUNCTION__);
multimap<unsigned int, string>::iterator itr;
multimap<unsigned int, string>::const_iterator citr;
for (citr=mapRequestValue.begin(); citr!=mapRequestValue.end(); ++citr)
{
itr = mapStoredValue.find(citr->first);
if(itr==mapStoredValue.end())
{
mapStoredValue.insert(make_pair(citr->first, citr->second));
}
else
{
unsigned int dwStoreValue = atoi(itr->second.c_str());
unsigned int dwNeedAddValue = atoi(citr->second.c_str());
dwStoreValue += dwNeedAddValue;
char szTemp[32] = {0};
snprintf(szTemp, sizeof(szTemp), "%d", dwStoreValue);
itr->second = szTemp;
}
}
}
示例8: main
int main(){
scanf("%d %s",&n,str);
pi x = pi(0,0);
mp.insert(make_pair(x,0));
for (int i=0; i<n; i++) {
if(str[i] == 'J'){
x.first--;
x.second--;
}
else if(str[i] == 'O') x.first++;
else x.second++;
mp.insert(make_pair(x,i+1));
}
it = mp.begin();
while (it != mp.end()) {
x = (*it).first;
int t = (*it).second;
while ((*it).first == x && it != mp.end()) it++;
it--;
res = max(res,(*it).second - t);
it++;
}
printf("%d",res);
}
示例9: prevNode
multimap<Seg, Triangle*>::iterator prevNode(multimap<Seg, Triangle*>::iterator it) {
return it == S.begin() ? it : --it;
}
示例10: obtainOptimalStateValue
void obtainOptimalStateValue(multimap<double,cEvent>& _event_multimap,vector<cServer>& _server_vec)
{
multimap<double,cEvent>::iterator iter_event_multimap;
counting = -1;
//store the number of accepted requests corresponding to each type of requests
map<requesttype,unsigned int> hosted_requests_type_num_map;
map<requesttype,unsigned int>::iterator iter_find_hosted_request_num_map;
map<ID,cRequest*> hosted_request_map;
map<ID,cRequest*>::iterator iter_find_request_map;
for (iter_event_multimap = _event_multimap.begin();iter_event_multimap != _event_multimap.end();iter_event_multimap++)
{
if (iter_event_multimap->second.getEventType() == DEPARTURE)
{
//set current time
current_time = iter_event_multimap->first;
//delete the request from the hosting list
iter_find_request_map = hosted_request_map.find((iter_event_multimap->second.getRequest())->getID());
if (iter_find_request_map == hosted_request_map.end())
{
cout<<"Error!!!Can not locate the request that should exist in the hosting list!"<<endl;
exit(0);
}
hosted_request_map.erase(iter_find_request_map);
//minus 1 from the entry corresponding the type of currently departing requests in the counting list of hosting requests
iter_find_hosted_request_num_map = hosted_requests_type_num_map.find((iter_event_multimap->second.getRequest())->getRequestType());
if (iter_find_hosted_request_num_map == hosted_requests_type_num_map.end())
{
cout<<"Error!!!Can not locate the request that should exist in the counting list of types of the hosting requests!"<<endl;
exit(0);
}
else
(iter_find_hosted_request_num_map->second)--;
//release the resources allocated to the request
releaseRequest(iter_event_multimap->second.getRequest());
//update the value of current system state after any request departure
//system_state.first = NONE;
//updateStateValueRequDepar(_server_vec,hosted_request_map,hosted_requests_type_num_map);
//system_state.second = calculateRequestDepartureStateIndicator(_server_vec,iter_event_multimap->second.getRequest());
}
else
{
//set current time
current_time = iter_event_multimap->first;
//a request is arriving
counting++;
//update the system state
system_state.first = (iter_event_multimap->second.getRequest())->getRequestType();
//we should determine which action should be take base on the purpose of maximizing the expected profits
//if(obtainOptimalAction(&(iter_event_multimap->second),_server_vec,hosted_requests_type_num_map,hosted_request_map))
if(obtainOptimalAction(&(iter_event_multimap->second),_server_vec,hosted_requests_type_num_map,hosted_request_map))
{
//if the arriving request is accepted, we should allocate physical resources for it and insert a departure event into the event list
(iter_event_multimap->second.getRequest())->setAccepted(true);
allocateRequest(iter_event_multimap->second.getRequest());
insertDepartureEvent(iter_event_multimap->second.getRequest(),_event_multimap);
accepted_requests_num++;
hosted_request_map.insert(make_pair((iter_event_multimap->second.getRequest())->getID(),iter_event_multimap->second.getRequest()));
iter_find_hosted_request_num_map = hosted_requests_type_num_map.find((iter_event_multimap->second.getRequest())->getRequestType());
if (iter_find_hosted_request_num_map == hosted_requests_type_num_map.end())
{
//there is no request in the system which has the same type as currently arriving request
hosted_requests_type_num_map.insert(make_pair((iter_event_multimap->second.getRequest())->getRequestType(),1));
}
else
(iter_find_hosted_request_num_map->second)++;
}
else
{
//do nothing
//the arriving request is rejected due to 1) having not enough residual resources, or 2) maximizing profits policy
(iter_event_multimap->second.getRequest())->setAccepted(false);
//update the value of current system state after any request departure
system_state.first = NONE;
updateStateValueRequDepar(_server_vec,hosted_request_map,hosted_requests_type_num_map);
}
}
}
return ;
}
示例11: IsHighSchool
bool IsHighSchool(const string &record,string &category,multimap<string::size_type,string> &m_keys,string &last_key)
{
int i;
string::size_type pos3 = 0;
for(i = 0; i < HIGHNUM; ++i)
{
if((pos3 = record.find(high_school[i])) != string::npos)
break;
}
if(i == HIGHNUM)
return false;
// 若名称中包含的是"*大"
if(i >= UABBNUM)
{
int j;
for(j = 0; j < UABBNUM; ++j)
{
if(record.find(high_school[j],pos3+2) != string::npos) //"*大"后面是否出现大学类的词
break;
}
if(j >= UABBNUM)
if(category.compare("教育学校:大学") != 0) // 当前分类不属于"大学"分类
return false;
}
if((high_school[i]).compare("大学") == 0)
{
pos3 = record.find(high_school[i]);
if(record.substr(pos3+2,4).compare("学堂") == 0)
return false;
}
/*
if(IsSpecialUniversity(record,last_key) == true)
{
category = school_category[HIGH]["特殊学校"];
return true;
}
*/
string::size_type pos4 = record.find("附属");
if(pos4 != string::npos)
{
if(record.find("校",pos4) != string::npos)
{
last_key = "附属";
category = school_category[HIGH]["附属学校"];
return true;
}
}
/*
pos4 = record.find("学校");
if(pos4 != string::npos && pos4 != pos3+4)
{
category = school_category[HIGH]["附属学校"];
ofile11 << record << "\t" << category << "\n";
return true;
}
*/
string::size_type pos1 = 0,pos2 = 0;
//multimap<string::size_type,string> m_keys;
vector<string>::iterator viter = (school_keys[HIGH]).begin();
while(viter != (school_keys[HIGH]).end())
{
pos1 = 0,pos2 = 0;
while((pos2 = record.find(*viter,pos1)) != string::npos)
{
m_keys.insert(make_pair(pos2,*viter));
pos1 = pos2 + (*viter).size();
}
++viter;
}
string ukey;
for(int i = UNUM; i < HIGHNUM; ++i)
{
pos1 = 0,pos2 = 0;
while((pos2 = record.find(high_school[i],pos1)) != string::npos)
{
ukey = high_school[i];
if(ukey.compare("大学") == 0)
{
if(record.substr(pos2+2,4).compare("学堂") == 0)
ukey = "";
}
if(ukey.compare("大学") != 0 && ukey.find("大") != string::npos)
{
if(record.substr(pos2+2,4).compare("大学") == 0)
ukey = "大学";
}
if(ukey.compare("师范") == 0)
{
string tempstr = record.substr(pos2+4,4);
if(tempstr.compare("大学") == 0 || tempstr.compare("学院") == 0 || tempstr.compare("学校") == 0)
ukey = record.substr(pos2,8);
}
if(ukey.compare("") != 0 && ukey.compare("大学") != 0)
m_keys.insert(make_pair(pos2,ukey));
pos1 = pos2 + (ukey.size());
//.........这里部分代码省略.........
示例12: filter
void STLRepository::filter( Resources& resources, const multimap< string, Bytes >& inclusive_filters, const multimap< string, Bytes >& exclusive_filters ) const
{
for ( auto resource = resources.begin( ); resource not_eq resources.end( ); )
{
bool failed = true;
for ( const auto filter : exclusive_filters )
{
failed = true;
const auto properties = resource->equal_range( filter.first );
for ( auto property = properties.first; property not_eq properties.second; property++ )
{
if ( property->second == filter.second )
{
failed = false;
break;
}
}
if ( failed )
{
break;
}
}
if ( failed and not exclusive_filters.empty( ) )
{
resource = resources.erase( resource );
continue;
}
if ( inclusive_filters.empty( ) )
{
resource++;
continue;
}
failed = true;
for ( auto filter_iterator = inclusive_filters.begin( ); filter_iterator not_eq inclusive_filters.end( ); filter_iterator++ )
{
failed = true;
const auto properties = resource->equal_range( filter_iterator->first );
const auto filters = inclusive_filters.equal_range( filter_iterator->first );
for ( auto filter = filters.first; filter not_eq filters.second; filter++ )
{
for ( auto property = properties.first; property not_eq properties.second; property++ )
{
if ( property->second == filter->second )
{
failed = false;
break;
}
}
if ( not failed )
{
break;
}
}
if ( failed )
{
break;
}
if ( filters.second not_eq inclusive_filters.end( ) )
{
filter_iterator = filters.second;
}
}
if ( failed )
{
resource = resources.erase( resource );
}
else
{
resource++;
}
}
}
示例13: LLParser
//LL PARSER PROGRAM
bool LLParser( string b, multimap<char,parseEntry>& ptable)
{
string stackinput; //to display stack content
string input2,isymbol,top;
input2 = b + "$"; //input symbol
cout << "Input: " << input2 << endl;
stack<char> pstack; //stack of parser
int i=0; // i is iterator of input string
isymbol = input2[i]; //isymbol is current input symbol
top = startsymbol;
//put start symbol on top of stack
pstack.push('$');
stackinput += '$';
pstack.push(startsymbol[0]);
stackinput += startsymbol[0];
//working
cout << "STACK\t\tInput\t\tOutput\n";
cout << "$" << top << "\t\t" << input2 << "\t" << endl ;
while( top[0] != '$' )
{
bool p1 = false;
string production,dummy ; //from parse table.searching the parse table
for (multimap<char,parseEntry>::iterator pit = ptable.begin(); pit != ptable.end(); ++pit)
{
parseEntry temp2 = pit->second;
if ( (pit->first == top[0]) && ((temp2.input) == isymbol))
{
production = temp2.production; //extracting production to be used in rule 3,4
}
}
if ( top == isymbol)
{
//cout << "1\n";
// cout << "\t\tMatch " << top << endl;
dummy = top;
pstack.pop();
int l = stackinput.length()-1;
stackinput.resize(l);
p1 = true;
i++;
isymbol = input2[i];
}
else if ( (terminals.find(top[0])) != string::npos) //top is terminal
{
// cout << "2\n";
return false;
}
else if (production == "")
{
// cout << "3\n";
return false;
}
else if ( production != "")
{
pstack.pop();
int l = stackinput.length()-1;
stackinput.resize(l);
//pushing the production rhs on stack
string p = rhs_cfg(production);
// cout << "RHS OF PRODUCTION: " << p << endl;
for( int i= (p.length()-1); i >=0 ;i--)
{
// cout << "PUSH: " << p[i] << endl;
if ( p[i] != 'e')
{
pstack.push(p[i]);
stackinput += p[i];
}
}
}
top = "";
top = pstack.top();
//display
string inp = input2.substr(i);
if ( p1 )
cout << stackinput << "\t\t" << inp << "\t\t" << "Match " << dummy << endl ;
else
cout << stackinput << "\t\t" << inp << "\t\t" << production << endl ;
}
return true;
}
示例14: parse_error
/// convert infix string into postfix token list
postfix_t infix2postfix(string in)
{
postfix_t out;
stack<token_t> s;
token_t lasttok;
for (auto it = in.cbegin(); it != in.cend();)
{
const unsigned int i = it - in.cbegin(); // index of current character for parse_error purposes
static const string spaces = " \t\r\n";
if (spaces.find(*it) != string::npos)
{
++it;
continue;
}
/*cout << string(it, in.cend()) << endl;
cout << lasttok.first << "/" << lasttok.second << endl;
if (!s.empty())
cout << s.top().first << "/" << s.top().second << endl;*/
// try to parse number
static const string numbers = "0123456789.";
auto it2 = it;
for (; it2 != in.cend() && numbers.find(*it2) != string::npos; ++it2); // TODO: find_first_not_of
if (it2 != it)
{
if (lasttok.first == ")" || (opers.find(lasttok.first) == opers.end() && funcs.find(lasttok.first) != funcs.end()) || lasttok.second == -1)
throw parse_error("Missing operator", i);
out.push_back(lasttok = token_t(string(it, it2), -1));
it = it2;
continue;
}
// try to parse operator
auto lastoper = opers.find(lasttok.first);
bool lunary = lasttok.first == "" || lasttok.first == "(" || lasttok.first == "," || (lastoper != opers.end() && !(lastoper->second.unary && lastoper->second.right)); // true if operator at current location would be left unary
/*cout << unary << endl;
cout << endl;*/
auto oit = opers.begin();
for (; oit != opers.end(); ++oit)
{
if (equal(oit->first.begin(), oit->first.end(), it) && (oit->second.unary == lunary || (oit->second.unary && oit->second.right)))
break;
}
if (oit != opers.end())
{
if (lunary)
{
s.push(lasttok = token_t(oit->first, 1));
}
else if (oit->second.unary && oit->second.right) // right unary operator
{
// allow right unary operators to be used on constants and apply higher prec operators before
while (!s.empty())
{
token_t tok = s.top();
auto oit2 = find_oper(tok.first, true);
if ((oit2 != opers.end() && oit2->second.prec > oit->second.prec) || (oit2 == opers.end() && funcs.find(tok.first) != funcs.end()))
out.push_back(pop(s));
else
break;
}
out.push_back(lasttok = token_t(oit->first, 1)); // needs stack popping before?
}
else
{
insert_binaryoper(out, s, oit);
lasttok = token_t(oit->first, 2);
}
it += oit->first.size();
continue;
}
// try to parse function
auto fit = funcs.begin();
for (; fit != funcs.end(); ++fit)
{
if (opers.find(fit->first) == opers.end() && equal(fit->first.begin(), fit->first.end(), it))
break;
}
if (fit != funcs.end())
{
if (lasttok.first == ")" || (opers.find(lasttok.first) == opers.end() && funcs.find(lasttok.first) != funcs.end()))
throw parse_error("Missing operator", i);
else if (lasttok.second == -1)
insert_implicitmult(out, s);
s.push(lasttok = token_t(fit->first, 0));
it += fit->first.size();
continue;
}
//.........这里部分代码省略.........
示例15: Fetch
void CCrawl::Fetch(void *arg)
{
string str_url,host;
int nGsock = -1;//之前的套接字文件描述符
string strGHost;//之前的主机号
//生成一个PSE file来存放网页数据
//string ofs_name = DATA_PSE_FILE + "." + CStrFunction::itos(GetCurrentThreadId());//PSE.raw+当前线程号
string ofs_name = DATA_PSE_FILE + CStrFunction::itos(GetCurrentThreadId())+ ".txt";//PSE+当前线程号+.txt
CPSEFile pse_file(ofs_name);//创建一个PSE格式的文件,保存为原始网页库
//生成一个link_for_pse file来存放链接数据
ofs_name = DATA_LINK_FOR_PSE_FILE + CStrFunction::itos(GetCurrentThreadId())+ ".txt";//PSE+当前线程号+.txt
CLinkForPSEFile link_for_pse_file(ofs_name);//创建一个网页结构库
int isleep_cnt = 0;//线程运行控制参数
for(;;)
{
WaitForSingleObject(mutex_collection,INFINITE);//互斥锁
int cnt = map_urls.size();
if(cnt > 0)
{
//已经收集的没有访问的url
cout<<"collection has "<<cnt<<" unvisited urls"<<endl;
multimap<string,string>::iterator it = map_urls.begin();
if(it != map_urls.end())
{
//从带访问的url队列中得到一个url进行访问
str_url = (*it).second;
map_urls.erase(it);
ReleaseMutex(mutex_collection);
//分解url
CUrl iurl;
//看看url是否有http://,没有则返回
if(iurl.ParseUrl(str_url) == false)
{
cout<<"parse url false in Fetch"<<str_url<<endl;
continue;
}
//表明现在抓取的网页所在的主机,同之前抓取的网页所在的主机不同
//我们不能利用之前的套接字文件描述符进行CS通信,必须创建新的
//套接字文件描述符进行通信,这是由于循环导致的
if(strGHost != iurl.host_name)
{
closesocket(nGsock);
nGsock = -1;
strGHost = iurl.host_name;
}
//根据URL以及套接字文件描述符抓取URL对应的网页,并保存为原始网页库和网页结构库
((CCrawl *)arg)->DownroadFile(&pse_file,&link_for_pse_file,iurl,nGsock);
cnt = 0;
}else
{
ReleaseMutex(mutex_collection);
}
}else
{
//等待访问的url队列map_urls已经没有url了,这是我们需要挂起线程进行等待
ReleaseMutex(mutex_collection);
Sleep(1000);
isleep_cnt++;
}
if(b_f_over == true && isleep_cnt == 200)//当线程挂起的次数达到两百的时候,结束调用fetch
{
break;
}
}
pse_file.Close();
link_for_pse_file.Close();
}