Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9303875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:35:06+00:00 2026-06-18T23:35:06+00:00

i am trying to design a chord system.. the problem is my system works

  • 0

i am trying to design a chord system..

the problem is my system works fine if the size is like 10-20 lines of addPeer, removePeer etc..

but when i test it with a like 5000 lines of command file.

the first few hundreds was pretty fast, but as the program load more and more lines, it start to get slow..

As the requirement of the program is to test my program design, i cannot use threading.

I heard pointer is a good way to get things done faster, but how do i use pointer for my case.

This is my class headers..

class chord 
{
public:
chord();
~chord();

struct fingerTable {
int index;
int key;
};

struct node {
int nodeid;
vector<fingerTable> fTable;
vector<string> data;
};

void addPeer(int);

vector<node> cNode;
vector<fingerTable> fTable;

/* SOME more functions ..*/
};

This is my addPeer Function

void chord::addPeer(int id)
{
//id = node ID
int fIndex,nextNode;
node newNode;
vector<fingerTable> ft1;
vector<string> data1;
//increment indexCounter
//indexCounter++;

newNode.nodeid = id;
//insert a blank fingerTable first.
newNode.fTable = ft1;
//insert a blank data first.
newNode.data = data1;

//push back node to vector chord Index Node
cNode.push_back(newNode);
//indexCounter++;
//perform finger table computation

//sort it base on its NodeID
sort(cNode.begin(),cNode.end(),sortByNodeID);

for(int i=0;i<cNode.size();i++)
{
if(cNode[i].nodeid==id)
{
fIndex=i;
}
}//end for loop to loop finding index of node

if(fIndex!=cNode.size()-1)
{
//if not last element
nextNode=fIndex+1;
}
else
{
nextNode=0;
}

//now we get the message vector of the next node and do a datashift on it.
data1 = cNode[nextNode].data;
//clear its data away so we can empty it and re-arrange it.
cNode[nextNode].data.clear();
//performing data shift function
dataShift(data1,fIndex-1);

if(id!=0)
{
cout << "PEER " << id << " inserted."<< endl;
}

}//end addPeer

My question is, which part can i improvise on for this function addPeer to make the whole program execute the lines faster. as it get really slow when execute a few hundreds line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T23:35:07+00:00Added an answer on June 18, 2026 at 11:35 pm

    This is slowing down because you are constantly sorting. You should prob. be using a sorted structure like std::map<int,node> .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to design an easily extendable form system in javascript, but am having
I'm trying to design a theme on WordPress (version 3.3.2) but I am having
I am trying to design an IDE-like (Non-Editable) program with a richtextbox control. Basically,
I am trying to design my Class Diagram. But I get stuck on this
I am trying to design a menu and submenu like this . I tried
I am trying to design a chat UI with Swing, but I am too
I am trying to design a signal and slot system in c++. The mechanism
I'm trying to design one multiserver updates deployment system, I was thinking if there
Hi I am trying to design a database for an e-commerce website but I
I'm trying to design a two factor authentication system (on PHP) using SMS as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.