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.