ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Algorithm-FEC/FEC.xs
(Generate patch)

Comparing Algorithm-FEC/FEC.xs (file contents):
Revision 1.5 by root, Sat Sep 13 21:02:28 2003 UTC vs.
Revision 1.7 by root, Sat Sep 13 21:58:36 2003 UTC

26 26
27 void **b_addr; 27 void **b_addr;
28 void **b_mmap; 28 void **b_mmap;
29 int *b_sz; 29 int *b_sz;
30 SV **b_sv; 30 SV **b_sv;
31 int **idx; /* the decoding indices */ 31 int *idx; /* the decoding indices */
32} *Algorithm__FEC; 32} *Algorithm__FEC;
33 33
34static void 34static void
35chk_array (SV *sv, int size, const char *func, const char *var) 35chk_array (SV *sv, int size, const char *func, const char *var)
36{ 36{
227void 227void
228set_decode_blocks (self, blocks, indices) 228set_decode_blocks (self, blocks, indices)
229 Algorithm::FEC self 229 Algorithm::FEC self
230 SV * blocks 230 SV * blocks
231 SV * indices 231 SV * indices
232 ALIAS:
233 shuffle = 1
232 CODE: 234 CODE:
233{ 235{
234 int i; 236 int i;
237 int *idx;
235 238
236 chk_array (blocks, self->dp, "set_decode_blocks", "blocks"); 239 chk_array (blocks, self->dp, "set_decode_blocks", "blocks");
237 chk_array (indices, self->dp, "set_decode_blocks", "indices"); 240 chk_array (indices, self->dp, "set_decode_blocks", "indices");
238 241
239 Newz (0, self->idx, self->dp, int); 242 Newz (0, idx, self->dp, int);
240 243
241 /* copy and check */ 244 /* copy and check */
242 for (i = 0; i < self->dp; i++) 245 for (i = 0; i < self->dp; i++)
243 { 246 {
244 self->idx[i] = SvIV (*av_fetch ((AV *)SvRV (indices), i, 1)); 247 idx[i] = SvIV (*av_fetch ((AV *)SvRV (indices), i, 1));
245 248
246 if (self->idx[i] < 0 || self->idx[i] >= self->ep) 249 if (idx[i] < 0 || idx[i] >= self->ep)
247 { 250 {
248 free_files (); 251 Safefree (idx);
249 croak ("index %d in array out of bounds (0 <= %d < %d != true)", 252 croak ("index %d in array out of bounds (0 <= %d < %d != true)",
250 i, self->idx[i], self->ep); 253 i, idx[i], self->ep);
251 } 254 }
252 } 255 }
253 256
254 /* 257 /*
255 * do the same shuffling as fec_decode does here, 258 * do the same shuffling as fec_decode does here,
256 * so we know the order. 259 * so we know the order.
257 */ 260 */
258 for (i = 0; i < self->dp; i++) 261 for (i = 0; i < self->dp; i++)
259 while (self->idx[i] < self->dp && self->idx[i] != i) 262 while (idx[i] < self->dp && idx[i] != i)
260 { 263 {
261 SV **a, **b, **e, **f; 264 SV **a, **b, **e, **f;
262 int d; 265 int d;
263 void *p; 266 void *p;
264 SV *s; 267 SV *s;
265 int j = self->idx[i]; 268 int j = idx[i];
266 269
267 if (self->idx[j] == j) 270 if (idx[j] == j)
268 { 271 {
269 free_files (); 272 Safefree (idx);
270 croak ("error while shuffling, duplicate indices?"); 273 croak ("error while shuffling, duplicate indices?");
271 } 274 }
272 275
273 a = av_fetch ((AV *)SvRV (indices), i, 1); 276 a = av_fetch ((AV *)SvRV (indices), i, 1);
274 b = av_fetch ((AV *)SvRV (indices), j, 1); 277 b = av_fetch ((AV *)SvRV (indices), j, 1);
275 e = av_fetch ((AV *)SvRV (blocks ), i, 1); 278 e = av_fetch ((AV *)SvRV (blocks ), i, 1);
276 f = av_fetch ((AV *)SvRV (blocks ), j, 1); 279 f = av_fetch ((AV *)SvRV (blocks ), j, 1);
277 280
278 d = self->idx[i]; self->idx[i] = self->idx[j]; self->idx[j] = d; 281 d = idx[i]; idx[i] = idx[j]; idx[j] = d;
279 s = *a; *a = *b; *b = s; 282 s = *a; *a = *b; *b = s;
280 s = *e; *e = *f; *f = s; 283 s = *e; *e = *f; *f = s;
281 } 284 }
282 285
286 if (ix)
287 Safefree (idx);
288 else
289 {
283 open_files (self, (AV *)SvRV (blocks), 1); 290 open_files (self, (AV *)SvRV (blocks), 1);
291 self->idx = idx;
292 }
284} 293}
285 294
286void 295void
287decode (self) 296decode (self)
288 Algorithm::FEC self 297 Algorithm::FEC self
289 CODE: 298 CODE:
290 299
291 if (!self->idx) 300 if (!self->idx)
292 croak ("index array must be set by a prior call to set_decode_blocks"; 301 croak ("index array must be set by a prior call to set_decode_blocks");
293 302
294 force_addrs (self, self->dp); 303 force_addrs (self, self->dp);
295 self->imp->fec_decode (self->code, self->b_addr, self->idx, self->sz); 304 self->imp->fec_decode (self->code, self->b_addr, self->idx, self->sz);
296 free_files (self); 305 free_files (self);
297 306

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines