Optimisation of algorithms. - page 8

 
Try something more interesting.
graph sin t^2 - Wolfram|Alpha
  • www.wolframalpha.com
x
 
I consider the topic of finding an extremum closed.
 

I searched the whole Internet looking for string array sorting http://ru.wikipedia.org/wiki/Быстрая_сортировка.

I ended up redesigning QuickSort to suit a string array.

I'd also like to include a mode for discarding unique records.

int OnInit()
{
string N[8];
N[0]="123";
N[1]="asdfgg";
N[2]="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa5";
N[3]="548";
N[4]="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa6";
N[5]="***";
N[6]="asdfg";
N[7]="+++++";
StrQuickSort(N);
Comment(
N[0]+"\n",
N[1]+"\n",
N[2]+"\n",
N[3]+"\n",
N[4]+"\n",
N[5]+"\n",
N[6]+"\n",
N[7]
);


return(0);
}

void StrQuickSort(string &A[])
{
QuickSort(A,0,ArrayRange(A,0)-1);
}
//void QuickSort(double &A[],int &r[],int from,int to)
//void CLONGArray::QuickSort(long &m_data[],Cint2D &index,int beg,int end,bool mode=0)
void QuickSort(string &A[],int from,int to)
  {
   int i,j;//,itemp;
   string x,temp;
   if(from>=to)return;
   i=from;
   j=to;
   x=A[(from+to)>>1];
   while(i<=j)
     {
      while(A[i]<x)i++; 
      while(A[j]>x)j--;
      if(i<=j)
        {
         temp=A[i]; A[i]=A[j]; A[j]=temp;
         //itemp=r[i]; r[i]=r[j]; r[j]=itemp;
         i++;
         j--;
        }
     }
   QuickSort(A,from,j);
   //QuickSort(A,r,from,j);
   QuickSort(A,i,to);  
   //QuickSort(A,r,i,to);
  }
Быстрая сортировка — Википедия
  • ru.wikipedia.org
Быстрая сортировка (англ.  ), часто называемая qsort по имени реализации в стандартной библиотеке языка Си — широко известный алгоритм сортировки, разработанный английским информатиком Чарльзом Хоаром во время его работы в МГУ в 1960 году. Один из самых быстрых известных универсальных алгоритмов сортировки массивов (в среднем O(n log n) обменов...
 
Greetings!
I'm bogged down with the logic of the algorithm for synchronizing the tick history of two or more symbols, so that each moment in time would have a corresponding symbol price, suggestion, colleagues.
 
Andrey Dik:
Greetings!
I'm bogged down with the logic of the algorithm for synchronizing the tick history of two or more symbols, so that each moment in time would have a corresponding symbol price, suggestion, colleagues.
Do you know about iBarShift?
 
Vladimir Tkach:
Do you know about iBarShift?
I know, how will it help me?
 
Andrey Dik:
Greetings!
I'm bogged down with the logic of the algorithm for synchronizing the tick history of two or more symbols, so that each moment in time would have a corresponding symbol price, suggestion, colleagues.
If I've got it right: I'm thinking of doing this - break it into separate objects by days, so that each stores arrays of ticks of all symbols, (for each day is not so many ticks), and then just from sorted by time array give by request "less or equal".
 
Create an additional array. Write the time from all the characters there. Sort in ascending order. Remove duplicates. Synchronize the tools using this array. If there is no exact match, take the time of the nearest tick.
 
Rorschach:
Create an additional array. There write the time from all symbols. Sort in ascending order. Remove duplicates. Synchronize the tools using this array. If there is no exact match, take the time of the nearest tick.
Yeah, that's what I did.
but there are often ticks on the same character with the same time, when there are several ticks in a millisecond
This is where I get stuck in the logic.
 
Andrey Dik:
Yeah, that's what I did.
but there are often ticks on the same character with the same time, when there are several ticks in a millisecond
That's where I get stuck in the logic.

You can think of a few options. Take the average price per ms. Take the last price per ms. Artificially increase resolution to µs, e.g. 3 ticks came in one ms, make time of the first tick 10µs, the second 20µs, etc. Time information is lost, there is no better option. Taking the last price would be the most usual, like millisecond bars would work out.