This is my iterator position code
struct node {
int nodeid;
vector<fingerTable> fTable;
vector<string> data;
};
vector<node> cNode;
vector<node>::iterator position = find(cNode.begin(),cNode.end(), id);
I got about 100 objects, i am trying to find the index/element/position of e.g nodeid "80" assuming that my object is all sorted in ascending order by nodeid.
my concern is speed and memory usage, i was previously using
for(int i=0;i<cNode.size();i++)
{
//if logic-- match nodeid with the nodeid input.. then assign the i to an integer..
}
but now i am trying to use and iterator, i heard its faster.. any suggestion on getting it fix or is there a better way to find my vector index by its value "nodeid"
i know map is a good std container for my case but i a bit run out of time to do the changes so i got to stick with vector..
vector<node>::iterator position = find(cNode.begin(),cNode.end(), id);
Error output when i try compile the iterator line above.
In member function ‘void chord::removePeer(int)’:
testfile.cpp:532:69: error: no matching function for call to ‘chord::find(std::vector<chord::node>::iterator, std::vector<chord::node>::iterator, int&)’
testfile.cpp:532:69: note: candidate is:
testfile.cpp:177:5: note: int chord::find(int, int, bool)
testfile.cpp:177:5: note: no known conversion for argument 1 from ‘std::vector<chord::node>::iterator {aka __gnu_cxx::__normal_iterator<chord::node*, std::vector<chord::node> >}’ to ‘int’