When writting a pure fucntion involving C non pure functions like memcpy() and memset() , what could be the way around? Should I re-write these and make them pure?

The code am converting is as below :-

int ag_cmatch(const string pattern, const string text, int[char] bmBc , int[size] bmGs ) pure { //Start of AG search algorithm
                int i,j,k , s, shift;
                int[size] skip;
                int[size]  suff;
                int m = to!int(pattern.length);
                int n = to!int(text.length);

                int position = -1;

                /* Preprocessing   */

                memset(&skip[0], 0, m* int.sizeof); // Initialise skip table
                
                                
                /* searching   */
                j = 0;
                while(j<=n-m){
                        i=m-1;
                        while( i >= 0){  // Start inner while
                                k = skip[i];
                                s = suff[i];
                                
                                if( k > 0)
                                if( k > s){
                                        //writeln(" Int Size 3 ", int.sizeof);
                                        if(i+1 == s)
                                                i = (-1);
                                        else {
                                                i -=s;
                                                //writeln("Innner while loop 
.....Found............... ");
                                                break;
                                        }
                                }
                                else{
                                        i-=k;
                                        if( k < s ){
// writeln("Innner while loop .....Found<<<<<< 1 >>>>>>............... ");
                                                //getchar();
                                                break;
                                        }
                                }
                                else {
                                        if ( pattern[i] == text[i+j]){
                                                --i;
                                                //writeln("Innner while loop .....Found<<<<<<  2  
>>>>>> ");
                                        }
                                        else
                                                break;
                                }
                        }// End inner while
                        
                        if ( i< 0){
                                //writeln(" AG Pattern found at :", j);
                                position = j;//Added for display / reporting
                                //getchar();
                                
// Manually added to cause a pattern found stop(Not in documentation)
                                skip[m-1] = m;
                                shift = bmGs[0];
                                break;
                        }
                        else{
                                skip[ m-1 ] = m -1 -i;
shift = bmGs[i] > (bmBc[text[i+j]] - m + 1 + i) ? bmGs[i] : (bmBc[text[i+j]] - m + 1 + i ) ;
                        }
                        
                        j+=shift;
                        //      writeln(" j Before memcpy== : ", j);
                        memcpy(&skip[0], &skip[0]+shift, 
(m-shift)*(int.sizeof));
                        memset(&skip[0]+(m-shift),0, shift*(int.sizeof));
                        
                }//End outer while
      return position ;

}//End AG search

Reply via email to