D
Devrobcom
Hi
I have an array with 30 int and another array with 1000 int.
If any of the 30 intergers can be found in the 1000 int array I shall return
true.
The contents of the arrays will also change over time.
I'm looking for a way to do this with good performance.
One way could be to:
bool any_match(int smal[], int smal_sz, int large[], int large_sz)
{
for(int i = 0; i < smal_sz; i++)
{
if ( binary_search(large, large_sz, smal) >= 0) return true;
}
return false;
}
void my_main_thread()
{
//
int large_array[1000];
int smal_array[30]
//
// sort large array when updated
//
// check if any id can be found
if (any_match(smal_array, 30, large_array, 1000) )
{
dowork();
}
}
Since I will do this very frequently I need something that takes little cpu.
The memory size is not a problem.
/Dev
I have an array with 30 int and another array with 1000 int.
If any of the 30 intergers can be found in the 1000 int array I shall return
true.
The contents of the arrays will also change over time.
I'm looking for a way to do this with good performance.
One way could be to:
bool any_match(int smal[], int smal_sz, int large[], int large_sz)
{
for(int i = 0; i < smal_sz; i++)
{
if ( binary_search(large, large_sz, smal) >= 0) return true;
}
return false;
}
void my_main_thread()
{
//
int large_array[1000];
int smal_array[30]
//
// sort large array when updated
//
// check if any id can be found
if (any_match(smal_array, 30, large_array, 1000) )
{
dowork();
}
}
Since I will do this very frequently I need something that takes little cpu.
The memory size is not a problem.
/Dev