Browse Source

cmVectOpsRICode.h : Fixed bug in Rotate().

master
kevin 9 years ago
parent
commit
baca9cd48d
1 changed files with 32 additions and 16 deletions
  1. 32
    16
      vop/cmVectOpsRICode.h

+ 32
- 16
vop/cmVectOpsRICode.h View File

@@ -227,31 +227,47 @@ VECT_OP_TYPE* VECT_OP_FUNC(Replace)(VECT_OP_TYPE* s, unsigned* sn, const VECT_OP
227 227
 
228 228
 
229 229
 
230
-VECT_OP_TYPE* VECT_OP_FUNC(Rotate)( VECT_OP_TYPE* dbp, unsigned dn, int shiftCnt )
230
+VECT_OP_TYPE* VECT_OP_FUNC(Rotate)( VECT_OP_TYPE* v, unsigned n, int i )
231 231
 {
232
-  VECT_OP_TYPE* dep = dbp + dn;
233
-  int           i   = 0;
234
-  unsigned      k   = 0;
235
-  int           n   = dep - dbp;
236
-  VECT_OP_TYPE  t1  = dbp[i];
232
+  int c, j;
233
+
234
+  if(v == NULL || n <= 0) 
235
+    return NULL;
237 236
 
238
-  for(k=0; k<n; ++k)
237
+  if(i < 0 || i >= n) 
239 238
   {
240
-    int          j;  
239
+    i %= n;
240
+    if (i < 0) 
241
+      i += n;
242
+  }
241 243
 
242
-    j = (i + shiftCnt) % n;
244
+  if(i == 0) 
245
+    return 0;
243 246
 
244
-    if( j<0 )
245
-      j += n;
247
+  c = 0;
248
+  for(j = 0; c < n; j++) 
249
+  {
250
+    int t = j, k = j + i;
246 251
 
247
-    VECT_OP_TYPE t2 = dbp[j];
252
+    VECT_OP_TYPE tmp = v[j];
253
+    c++;
248 254
 
249
-    dbp[j] = t1;
250
-    t1     = t2;
251
-    i      = j;
255
+    while( k != j ) 
256
+    {
257
+      v[t] = v[k];
258
+      t    = k;
259
+      k   += i;
260
+
261
+      if( k >= n ) 
262
+        k -= n;
263
+
264
+      c++;
265
+    }
266
+    v[t] = tmp;
252 267
   }
253 268
 
254
-  return dbp;
269
+  return v;
270
+
255 271
 }
256 272
 
257 273
 VECT_OP_TYPE* VECT_OP_FUNC(RotateM)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* sbp, int rShiftCnt, int cShiftCnt  )

Loading…
Cancel
Save