本文整理汇总了C++中deque类的典型用法代码示例。如果您正苦于以下问题:C++ deque类的具体用法?C++ deque怎么用?C++ deque使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了deque类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printTour
void printTour(deque<int> tour) {
printf("Tour: ");
for(deque<int>::iterator it=tour.begin(); it!=tour.end(); it++) printf("%d ",*it);
printf("\n");
}
示例2: build_subgraph
int build_subgraph(deque<set<int> > & E, const deque<int> & nodes, const deque<int> & degrees) {
/*
cout<<"nodes"<<endl;
prints(nodes);
cout<<"degrees"<<endl;
prints(degrees);
*/
if(degrees.size()<3) {
cerr<<"it seems that some communities should have only 2 nodes! This does not make much sense (in my opinion) Please change some parameters!"<<endl;
return -1;
}
// this function is to build a network with the labels stored in nodes and the degree seq in degrees (correspondence is based on the vectorial index)
// the only complication is that you don't want the nodes to have neighbors they already have
// labels will be placed in the end
deque<set<int> > en; // this is the E of the subgraph
{
set<int> first;
for(int i=0; i<nodes.size(); i++)
en.push_back(first);
}
multimap <int, int> degree_node;
for(int i=0; i<degrees.size(); i++)
degree_node.insert(degree_node.end(), make_pair(degrees[i], i));
int var=0;
while (degree_node.size() > 0) {
multimap<int, int>::iterator itlast= degree_node.end();
itlast--;
multimap <int, int>::iterator itit= itlast;
deque <multimap<int, int>::iterator> erasenda;
int inserted=0;
for (int i=0; i<itlast->first; i++) {
if(itit!=degree_node.begin()) {
itit--;
en[itlast->second].insert(itit->second);
en[itit->second].insert(itlast->second);
inserted++;
erasenda.push_back(itit);
}
else
break;
}
for (int i=0; i<erasenda.size(); i++) {
if(erasenda[i]->first>1)
degree_node.insert(make_pair(erasenda[i]->first - 1, erasenda[i]->second));
degree_node.erase(erasenda[i]);
}
var+= itlast->first - inserted;
degree_node.erase(itlast);
}
// ----------------------------------------------------------
deque<int> degree_list;
for(int kk=0; kk<degrees.size(); kk++)
for(int k2=0; k2<degrees[kk]; k2++)
degree_list.push_back(kk);
// this is to randomize the subgraph -------------------------------------------------------------------
for(int run=0; run<10; run++) for(int node_a=0; node_a<degrees.size(); node_a++) for(int krm=0; krm<en[node_a].size(); krm++) {
//.........这里部分代码省略.........
示例3: while
Segment*
Segment::new_segment(MorphoStream &ms, TransferRules* tr, TaggerData &td) {
TaggerWord *word=NULL;
set<TTag> tags;
set<TTag>::iterator itag;
vector<TTag> auxvec;
static int index_start=1;
static deque<TaggerWord> wordsbuffer;
static bool first_call=true;
static bool end_of_corpus_reached=false;
if (first_call) {
TaggerWord eosword;
eosword.add_tag(td.getTagIndex()[L"TAG_SENT"], L"", td.getPreferRules());
wordsbuffer.push_back(eosword);
//Fill the buffer of words
while (wordsbuffer.size()<TAGGER_WORD_BUFFER_SIZE) {
word=ms.get_next_word();
if(word==NULL) {
end_of_corpus_reached=true;
break;
}
wordsbuffer.push_back(*word);
delete word;
}
first_call=false;
}
/*
cerr<<"BUFFER (begining): ";
for (int i=0; i<wordsbuffer.size(); i++) {
cerr<<"["<<wordsbuffer[i].get_superficial_form()<<"] ";
}
cerr<<"\n";
cerr<<"Buffer size (begining): "<<wordsbuffer.size()<<"\n";
cerr<<"Index start (begining): "<<index_start<<"\n";
*/
Segment* seg=new Segment();
int number_of_paths=1;
int segmentation_point=-1;
int advance; //Number of word that can be skipped when looking for a segmentation point
for(size_t i=index_start; i<wordsbuffer.size(); i++) {
if (tr->is_segmentation_point(tag_index[L"TAG_kEOF"], wordsbuffer, i, advance)) {
segmentation_point=i;
break;
} else{
i+=advance;
}
}
if ((segmentation_point==-1) && (!end_of_corpus_reached)) {
cerr<<"Error: No segmentation point was found.\n";
cerr<<"Try making the buffer longer, current maximum size is "<<TAGGER_WORD_BUFFER_SIZE<<"\n";
cerr<<"See Segment.H, TAGGER_WORD_BUFFER_SIZE constant\n";
exit(EXIT_FAILURE);
}
//cerr<<"Segmentation point: "<<segmentation_point<<"\n";
//The segment to return is from index_start to segmentation_point
for(int i=index_start; i<=segmentation_point; i++) {
tags=wordsbuffer[i].get_tags();
seg->contador_caminos.push_back(auxvec);
if (tags.size()>0) {
number_of_paths*=tags.size();
for(itag=tags.begin(); itag!=tags.end(); itag++)
seg->contador_caminos.back().push_back(*itag);
} else {
//seg->contador_caminos.back().push_back(-1); //Palabra desconocida
tags=td.getOpenClass();
number_of_paths*=tags.size();
for(itag=tags.begin(); itag!=tags.end(); itag++)
seg->contador_caminos.back().push_back(*itag);
}
seg->vwords.push_back(wordsbuffer[i]);
}
//Calculate which words can be removed from the buffer, we need some
//words before the segment being return, more concretely, from the
//last non-ambiguous word until the first word of the segment being
//returned
int preserve_word_from=-1;
for (int i=(index_start-1); i>=0; i--) {
if (wordsbuffer[i].get_tags().size()==1) {
preserve_word_from=i;
break;
}
}
//cerr<<"Preserve words from index: "<<preserve_word_from<<"\n";
//.........这里部分代码省略.........
示例4: erase_links
int erase_links(deque<set<int> > & E, const deque<deque<int> > & member_list, const bool excess, const bool defect, const double mixing_parameter) {
int num_nodes= member_list.size();
int eras_add_times=0;
if (excess) {
for (int i=0; i<num_nodes; i++) {
while ( (E[i].size()>1) && double(internal_kin(E, member_list, i))/E[i].size() < 1 - mixing_parameter) {
//---------------------------------------------------------------------------------
cout<<"degree sequence changed to respect the option -sup ... "<<++eras_add_times<<endl;
deque<int> deqar;
for (set<int>::iterator it_est=E[i].begin(); it_est!=E[i].end(); it_est++)
if (!they_are_mate(i, *it_est, member_list))
deqar.push_back(*it_est);
if(deqar.size()==E[i].size()) { // this shouldn't happen...
cerr<<"sorry, something went wrong: there is a node which does not respect the constraints. (option -sup)"<<endl;
return -1;
}
int random_mate=deqar[irand(deqar.size()-1)];
E[i].erase(random_mate);
E[random_mate].erase(i);
}
}
}
if (defect) {
for (int i=0; i<num_nodes; i++)
while ( (E[i].size()<E.size()) && double(internal_kin(E, member_list, i))/E[i].size() > 1 - mixing_parameter) {
//---------------------------------------------------------------------------------
cout<<"degree sequence changed to respect the option -inf ... "<<++eras_add_times<<endl;
int stopper_here=num_nodes;
int stopper_=0;
int random_mate=irand(num_nodes-1);
while ( ( (they_are_mate(i, random_mate, member_list)) || E[i].find(random_mate)!=E[i].end()) && (stopper_<stopper_here) ) {
random_mate=irand(num_nodes-1);
stopper_++;
}
if(stopper_==stopper_here) { // this shouldn't happen...
cerr<<"sorry, something went wrong: there is a node which does not respect the constraints. (option -inf)"<<endl;
return -1;
}
E[i].insert(random_mate);
E[random_mate].insert(i);
}
}
//------------------------------------ Erasing links ------------------------------------------------------
return 0;
}
示例5: build_bipartite_network
int build_bipartite_network(deque<deque<int> > & member_matrix, const deque<int> & member_numbers, const deque<int> &num_seq) {
// this function builds a bipartite network with num_seq and member_numbers which are the degree sequences. in member matrix links of the communities are stored
// this means member_matrix has num_seq.size() rows and each row has num_seq[i] elements
deque<set<int> > en_in; // this is the Ein of the subgraph
deque<set<int> > en_out; // this is the Eout of the subgraph
{
set<int> first;
for(int i=0; i<member_numbers.size(); i++) {
en_in.push_back(first);
}
}
{
set<int> first;
for(int i=0; i<num_seq.size(); i++) {
en_out.push_back(first);
}
}
multimap <int, int> degree_node_out;
deque<pair<int, int> > degree_node_in;
for(int i=0; i<num_seq.size(); i++)
degree_node_out.insert(make_pair(num_seq[i], i));
for(int i=0; i<member_numbers.size(); i++)
degree_node_in.push_back(make_pair(member_numbers[i], i));
sort(degree_node_in.begin(), degree_node_in.end());
deque<pair<int, int> >::iterator itlast = degree_node_in.end();
/*
for (int i=0; i<degree_node_in.size(); i++)
cout<<degree_node_in[i].first<<" "<<degree_node_in[i].second<<endl;
*/
while (itlast != degree_node_in.begin()) {
itlast--;
multimap <int, int>::iterator itit= degree_node_out.end();
deque <multimap<int, int>::iterator> erasenda;
for (int i=0; i<itlast->first; i++) {
if(itit!=degree_node_out.begin()) {
itit--;
en_in[itlast->second].insert(itit->second);
en_out[itit->second].insert(itlast->second);
erasenda.push_back(itit);
}
else
return -1;
}
//cout<<"degree node out before"<<endl;
//prints(degree_node_out);
for (int i=0; i<erasenda.size(); i++) {
if(erasenda[i]->first>1)
degree_node_out.insert(make_pair(erasenda[i]->first - 1, erasenda[i]->second));
degree_node_out.erase(erasenda[i]);
}
//cout<<"degree node out after"<<endl;
//prints(degree_node_out);
}
//.........这里部分代码省略.........
示例6: push
void push(deque<p>& q,uc x,uc y){
p p1;p1.x=x;p1.y=y;q.push_back(p1);
}
示例7: ridgeIdsForFacet
void convexHull4d::createNewFacets(deque<long>& horizonRidges, vertex4d* furthest, vector<long>& facetIdList, deque<long>& bucketLessVertices, double testNormal[4])
{
// cout<<"size of horizon ridgeS when creating:"<<horizonRidges.size()<<endl;
for(deque<long>::iterator hrit=horizonRidges.begin(); hrit!= horizonRidges.end(); hrit++)
{
vector<long> vertexIndices;
vector<long> ridgeIdsForFacet(4);
vertexIndices.push_back(tempRidges.find((*hrit))->second.getVertexList()[0]);
vertexIndices.push_back(tempRidges.find((*hrit))->second.getVertexList()[1]);
vertexIndices.push_back(tempRidges.find((*hrit))->second.getVertexList()[2]);
vertexIndices.push_back(furthest->getId());
sort(vertexIndices.begin(), vertexIndices.end());
long facetId = generateId(&vertexIndices);
vertexIndices.clear();
facet *newFacet = new facet();
newFacet->setId(facetId);
tempFacets.insert(pair<long,facet>(facetId, *newFacet));
newFacet=&tempFacets.find(facetId)->second;
if(tempRidges.find((*hrit))->second.getNeighbour1())
{
tempRidges.find((*hrit))->second.setNeighbour2(newFacet->getId());
newFacet->insertContaining2dSimplex(*hrit);
}
else
{
tempRidges.find((*hrit))->second.setNeighbour1(newFacet->getId());
newFacet->insertContaining2dSimplex(*hrit);
}
for(int i=0; i<3; i++)
{
for(int j=0,k=0; k<2; j++,k++)
{
if(j==i)
{
k--;
continue;
}
vertexIndices.push_back(tempRidges.find((*hrit))->second.getVertexList()[j]);
}
vertexIndices.push_back(furthest->getId());
sort(vertexIndices.begin(),vertexIndices.end());
ridge *newRidge;
// newRidge->setId(&vertexIndices);
long tempId = generateId(&vertexIndices);
if(tempRidges.find(tempId)==tempRidges.end())
{
newRidge = new ridge();
newRidge->setId(tempId);
tempRidges.insert(pair<long,ridge>(tempId,*newRidge));
newRidge = &tempRidges.find(tempId)->second;
for(vector<long>::iterator viter = vertexIndices.begin(); viter!=vertexIndices.end(); viter++)
{
newRidge->getVertexList().push_back(*viter);
}
}
else
{
newRidge = &tempRidges.find(tempId)->second;
}
vertexIndices.clear();
if(newRidge->getNeighbour1()==0)
newRidge->setNeighbour1(newFacet->getId());
else
newRidge->setNeighbour2(newFacet->getId());
newFacet->insertContaining2dSimplex(newRidge->getId());
}
deque<vertex4d>::pointer v[4];
v[0]= &(verticesOfHull.find(furthest->getId())->second);
for(int i=1; i<4; i++)
{
v[i]=&(verticesOfHull.find(tempRidges.find(*hrit)->second.getVertexList()[i-1])->second);
}
newFacet->calcNormOffset(v, centroid);
facetIdList.push_back(newFacet->getId());
for(deque<long>::iterator blvit=bucketLessVertices.begin(); blvit!=bucketLessVertices.end(); blvit++)
{
if(!verticesOfHull.find(*blvit)->second.getBucketAssignmentStatus() &&verticesOfHull.find(*blvit)->second.isAbove(newFacet))
{
newFacet->putInBucket((*blvit));
verticesOfHull.find(*blvit)->second.insertVisibleFacet(newFacet->getId());
verticesOfHull.find(*blvit)->second.setAssignedToBucket(true);
}
}
setFurthestPoint(newFacet->getId());
}
for(deque<long>::iterator blvit=bucketLessVertices.begin(); blvit!=bucketLessVertices.end(); blvit++)
{
if(verticesOfHull.find(*blvit)->second.getBucketAssignmentStatus()==false)
{
verticesOfHull.find(*blvit)->second.getVisibleFacets().clear();
verticesOfHull.find(*blvit)->second.setAssignedToBucket(true);
}
}
}
示例8: center_mat
deque<deque<int>> center_mat(deque<deque<int>> src_mat){
deque<deque<int>> t_mat;
deque<int> vec_zero;
int marge_gauche=0;
int marge_droite=0;
int marge_haut=0;
int marge_bas=0;
int delta_x = 0;
int delta_y = 0;
int temp_size;
bool stop;
stop = false;
//Marge Gauche
for(int i=0;i<src_mat.size();i++){
for(int j=0;j<src_mat[i].size();j++){
if(!stop && src_mat[j][i]){
marge_gauche = i;
stop = true;
}
}
}
stop = false;
//Marge Droite
for(int i=src_mat.size()-1;i>=0;i--){
for(int j=0;j<src_mat[i].size();j++){
if(!stop && src_mat[j][i]){
marge_droite = src_mat.size()-i;
stop = true;
}
}
}
stop = false;
//Marge Haut
for(int i=0;i<src_mat.size();i++){
for(int j=0;j<src_mat[i].size();j++){
if(!stop && src_mat[i][j]){
marge_haut = i;
stop = true;
}
}
}
stop = false;
//Marge Bas
for(int i=src_mat.size()-1;i>=0;i--){
for(int j=0;j<src_mat[i].size();j++){
if(!stop && src_mat[i][j]){
marge_bas = src_mat.size()-i;
stop = true;
}
}
}
delta_x = (marge_droite-marge_gauche)/2;
delta_y = (marge_bas-marge_haut)/2;
cout << delta_x << endl;
cout << delta_y << endl;
vec_zero.resize(src_mat.size());
temp_size = src_mat.size();
// Lignes de zeros
if(delta_y>0){
for(int i=0;i<delta_y;i++){
src_mat.push_front(vec_zero);
}
src_mat.resize(temp_size);
}else{
for(int i=0;i<-delta_y+1;i++){
src_mat.push_back(vec_zero);
}
src_mat.erase(src_mat.begin(),src_mat.begin()-delta_y);
}
// Colonnes de zeros
if(delta_x>0){
for (int i=0; i<src_mat.size(); i++){
for(int j=0;j<delta_x;j++){
src_mat[i].push_front(0);
}
src_mat[i].resize(temp_size);
}
}else{
for (int i=0; i<src_mat.size(); i++){
for(int j=0;j<-delta_x+1;j++){
src_mat[i].push_back(0);
src_mat[i].erase(src_mat[i].begin());
}
}
}
return src_mat;
}
示例9: waypoints_loop1
/*
* flightLoop
* 1) Initialise copter systems
* 2) Wait for user allowance to fly.
* 3) Read in list of waypoints
* 4) Fly to first waypoint, wait, fly to next, etc..
* 5) If the end is reached, stop.
*
* The user may stop the flight at any time. It will continue if the user resumes. At any
* point, the user may stop the current flight path and change the waypoint configuration. Upon
* resuming flight, the copter will read in the new list of waypoints and start at the
* beginning.
*/
void waypoints_loop1(hardware &hardware_list, Logger &log, deque<coord> &waypoints_list, string config_filename) {
cout << "\033[1;32m[WAYPTS]\033[0m Waypoints thread initiated, travelling to the following waypoints:" << endl;
char str_buf[BUFSIZ];
log.clearLog();
time_t start, now, last_displayed;
time(&start);
time(&now);
time(&last_displayed);
//Grab references to hardware
FlightBoard *fb = hardware_list.fb;
GPS *gps = hardware_list.gps;
IMU *imu = hardware_list.imu;
bool useimu = hardware_list.IMU_Working;
double yaw = 0;
//Configure configurable variables (if file is given)
if(!config_filename.empty()) {
loadParameters(config_filename);
}
//Construct PID controller
PID controller = PID(-Kp, -Ki, -Kd, MAIN_LOOP_DELAY, 3, 0.95);
//Construct buzzer
Buzzer cowbell;
cowbell.needs_more();
usleep((int)(BUZZER_DURATION*1.1)*1000*1000);
//Print list of waypoints
for(size_t i = 0; i != waypoints_list.size(); i++) {
cout << " " << i+1 << ": (" << setprecision(6) << waypoints_list[i].lat << ", " << setprecision(6) << waypoints_list[i].lon << ")" << endl;
}
//Wait here for auto mode and conduct bearing test if necessary
state = 6;
cout << "\033[1;33m[WAYPTS]\033[0m Waiting for auto mode." << endl;
while ( !gpio::isAutoMode() && !exitProgram) usleep(500*1000);
cout << "\033[1;31m[WAYPTS]\033[0m Auto mode engaged." << endl;
if (!useimu && !exitProgram) {
cowbell.playBuzzer(0.25, 10, 100);
cout << "\033[1;31m[WAYPTS]\033[0m Conducting bearing test..." << endl;
state = 5;
yaw = inferBearing(fb, gps);
cout << "\033[1;31m[WAYPTS]\033[0m Bearing test complete." << endl;
}
state = 1;
//Initialise loop variables
coord currentCoord = {-1, -1};
double distanceToNextWaypoint;
double bearingToNextWaypoint;
FB_Data course = {0, 0, 0, 0};
int pastState = -1;
velocity flightVector = {-1, -1};
cout << "\033[1;32m[WAYPTS]\033[0m Starting main loop." << endl;
try { // Check for any errors, and stop the copter.
while(!exitProgram) {
currentCoord = getCoord(gps);
//Write data for Michael
time(&now);
if (!waypoints_list.empty()) {
sprintf(str_buf, "%.f,%3.6f,%3.6f,%3.6f,%3.6f", difftime(now, start), currentCoord.lat, currentCoord.lon, waypoints_list[wp_it].lat, waypoints_list[wp_it].lon);
} else {
sprintf(str_buf, "%.f,%3.6f,%3.6f,,", difftime(now, start), currentCoord.lat, currentCoord.lon);
}
log.writeLogLine(str_buf, false);
if(!waypoints_list.empty()) {
distanceToNextWaypoint = calculate_distance(currentCoord, waypoints_list[wp_it]);
bearingToNextWaypoint = calculate_bearing(currentCoord, waypoints_list[wp_it]);
}
if (useimu) yaw = getYaw(imu);
/* State 4: Manual mode. */
if (!gpio::isAutoMode()) {
state = 4;
//.........这里部分代码省略.........
示例10: extract_variables
vector<float> extract_variables(deque<deque<int>> img){
vector<float> variables;
vector<float> variables_temp_pi;
deque<deque<int>> m_img = mirror_mat_horizontal(img);
int sumHist = 0;
//Horizontal Histogram
for(int i=0;i<img.size();i++){
for(int j=0;j<img.size();j++){
sumHist+=img[i][j];
}
variables.push_back(sumHist);
sumHist = 0;
}
//Vertical Histogram
for(int i=0;i<img.size();i++){
for(int j=0;j<img.size();j++){
sumHist+=img[j][i];
}
variables.push_back(sumHist);
sumHist = 0;
}
//+pi/4 Histogram
for (int i = 0; i < 2 * 8 - 1; ++i) {
int z = i < 8 ? 0 : i - 8 + 1;
for (int j = z; j <= i - z; ++j) {
sumHist+=img[j][i - j];
}
variables_temp_pi.push_back(sumHist);
sumHist = 0;
}
reverse(variables_temp_pi.begin(),variables_temp_pi.end());
variables.insert(variables.end(),variables_temp_pi.begin(),variables_temp_pi.end());
variables_temp_pi.clear();
//-pi/4 Histogram
for (int i = 0; i < 2 * 8 - 1; ++i) {
int z = i < 8 ? 0 : i - 8 + 1;
for (int j = z; j <= i - z; ++j) {
sumHist+=m_img[j][i - j];
}
variables_temp_pi.push_back(sumHist);
sumHist = 0;
}
reverse(variables_temp_pi.begin(),variables_temp_pi.end());
variables.insert(variables.end(),variables_temp_pi.begin(),variables_temp_pi.end());
//quadrans
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
for(int k=0;k<4;k++){
for(int l=0;l<4;l++){
sumHist+=img[4*i+k][4*j+l];
}
}
variables.push_back(sumHist);
sumHist = 0;
}
}
//taux de presence
for(int i=0;i<img.size();i++){
for(int j=0;j<img.size();j++){
if(img[i][j]){
sumHist+=img[i][j];
}
}
}
variables.push_back(sumHist/1024.0);
//Deletes useless variables (all zero)
variables.erase(variables.begin() + 45);
variables.erase(variables.begin() + 39);
variables.erase(variables.begin() + 31);
variables.erase(variables.begin() + 30);
variables.erase(variables.begin() + 17);
variables.erase(variables.begin() + 16);
variables.erase(variables.begin() + 15);
variables.erase(variables.begin() + 7);
return variables;
}
示例11: f
void f(deque<Card>& dc, My_rand& r)
{
random_shuffle(dc.begin(), dc.end(), r);
}
示例12: printRegions
void LinkMap::printRegions(ostream &os, deque<Region *> ®ions, Offset globalOffset) {
deque<Region *>::iterator reg_it;
for(reg_it = regions.begin(); reg_it != regions.end(); ++reg_it) {
printRegion(os, *reg_it, globalOffset);
}
}
示例13: if
int
main(int argc, char* argv[]) {
const int test_case = 2;
signal(SIGINT, &signal_handler);
#ifndef WIN32
void* (*AppServer[test_case])(void*);
#else
DWORD (WINAPI *AppServer[test_case])(LPVOID);
#endif
AppServer[0] = AppServer_TCP;
AppServer[1] = AppServer_UDT;
cout << "Start AppServer Mode # Callee" << endl;
UDT::startup();
#ifndef WIN32
pthread_t srv_udt, srv_tcp;
pthread_create(&srv_tcp, NULL, AppServer[0], NULL);
pthread_create(&srv_udt, NULL, AppServer[1], NULL);
//pthread_join(srv_udt, NULL);
//pthread_join(srv_tcp, NULL);
#else
HANDLE srv_udt, srv_tcp;
srv_tcp = CreateThread(NULL, 0, AppServer[0], NULL, 0, NULL);
srv_udt = CreateThread(NULL, 0, AppServer[1], NULL, 0, NULL);
//WaitForSingleObject(srv_udt, INFINITE);
//WaitForSingleObject(srv_tcp, INFINITE);
#endif
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
cout << "Run Task loop ...\n";
main_running = 1;
while (main_running)
{
if (!taskQueue.empty())
{
switch (taskQueue.front()->header.cmd)
{
case CMD_C_DISCONNECT:
{
connectMap_iter = connectMapKeyC.find(taskQueue.front()->header.cliFD);
if (connectMap_iter != connectMapKeyC.end())
{
UDT::epoll_remove_ssock(tcp_eid, connectMap_iter->second);
#ifndef WIN32
close(connectMap_iter->second);
#else
closesocket(connectMap_iter->second);
#endif
}
taskQueue.pop_front();
}
break;
case CMD_CONNECT:
{
pTcp_sock = new SYSSOCKET;
if (createTCPSocket(*pTcp_sock, 0) < 0) {
cout << "\tcan't create tcp socket!" << endl;
}
map_insert(&connectMapKeyC, taskQueue.front()->header.cliFD, *pTcp_sock);
map_insert(&connectMapKeyS, *pTcp_sock, taskQueue.front()->header.cliFD);
if (tcp_connect(*pTcp_sock, REMOTE_PORT) < 0) {
printf("\tCan't connect local port 80\n");
}
UDT::epoll_add_ssock(tcp_eid, *pTcp_sock);
taskQueue.pop_front();
}
break;
case CMD_S_DISCONNECT:
{
char* buftmp = (char*)(taskQueue.front());
int res = 0;
int ssize = 0;
//UDT::perfmon(client, &trace);
while (ssize < udtsize)
{
//int scv_size;
//int var_size = sizeof(int);
//UDT::getsockopt(client, 0, UDT_SNDDATA, &scv_size, &var_size);
if (UDT::ERROR == (res = UDT::send(client, buftmp + ssize, udtsize - ssize, 0)))
{
cout << "send:" << UDT::getlasterror().getErrorMessage() << endl;
break;
}
ssize += res;
}
//printf("ok.[%d]\n", res);
//UDT::perfmon(client, &trace);
//cout << "\tspeed = " << trace.mbpsSendRate << "Mbits/sec" << endl;
taskQueue.pop_front();
}
break;
case CMD_DATA_S2T:
{
//.........这里部分代码省略.........
示例14: getMin
int getMin() {
//Returns minimum of current existing elements of queue
//Complexity - O(1)
return Min.front();
}
示例15: putIntoTour
int putIntoTour(int length, int **adjacencyMatrix, const int &n, int vertex) {
tour.insert(findClosest(vertex, adjacencyMatrix),vertex);
return 0;
}