Re: Efficient Vector Comparison
- From: Yao Qi <qiyaoltc@xxxxxxxxx>
- Date: Fri, 29 Jun 2007 22:03:48 +0800
user923005 <dcorbit@xxxxxxxxx> writes:
On Jun 28, 1:48 am, Yao Qi <qiyao...@xxxxxxxxx> wrote:
In our program, we will compare every two vectors. In currentthe
implementation, we compare every element of that vector until we get
comparison result. It is not any more efficient way to do this?
b.t.w the length of vector is variable.
Do you have to sort the vectors?
Yeah, what I want is to sort the vectors. Unfortunately, our code base
is written in C, and we use a dynamic array to represent a vector.
After profiling, I find that the vector comparison is not so efficient.
Why not something simple like:
#include <vector>
#include <iostream>
using namespace std;
int main(void)
{
vector < double > a;
vector < double > b;
a.resize(100);
b.resize(100);
size_t index;
for (index = 0; index < 100; index++)
{
a[index] = (double)index;
b[index] = (double) index;
if (index == 99) b[index]+=1.0;
}
if (a < b)
cout << "a is less than b" << endl;
else if (a > b)
cout << "a is greater than b" << endl;
else
cout << "a is equal to b" << endl;
return 0;
}
Best Regards
--
Yao Qi <qiyaoltc@xxxxxxxxx> GNU/Linux Developer
http://duewayqi.googlepages.com/
Live within your income, even if you have to borrow to do so.
-- Josh Billings
.
- Follow-Ups:
- Re: Efficient Vector Comparison
- From: Robert Maas, see http://tinyurl.com/uh3t
- Re: Efficient Vector Comparison
- From: Jon Harrop
- Re: Efficient Vector Comparison
- References:
- Efficient Vector Comparison
- From: Yao Qi
- Re: Efficient Vector Comparison
- From: user923005
- Efficient Vector Comparison
- Prev by Date: Re: Efficient Vector Comparison
- Next by Date: Re: The software I wish I had
- Previous by thread: Re: Efficient Vector Comparison
- Next by thread: Re: Efficient Vector Comparison
- Index(es):
Relevant Pages
|