/[pspp]/pspp/src/algorithm.c
ViewVC logotype

Diff of /pspp/src/algorithm.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by jmd, Fri Apr 29 01:02:13 2005 UTC revision 1.15 by blp, Mon May 2 06:21:20 2005 UTC
# Line 393  remove_element (void *array, size_t coun Line 393  remove_element (void *array, size_t coun
393    remove_range (array, count, size, idx, 1);    remove_range (array, count, size, idx, 1);
394  }  }
395    
396    /* Moves an element in ARRAY, which consists of COUNT elements of
397       SIZE bytes each, from OLD_IDX to NEW_IDX, shifting around
398       other elements as needed.  Runs in O(abs(OLD_IDX - NEW_IDX))
399       time. */
400    void
401    move_element (void *array_, size_t count, size_t size,
402                  size_t old_idx, size_t new_idx)
403    {
404      assert (array_ != NULL || count == 0);
405      assert (old_idx < count);
406      assert (new_idx < count);
407      
408      if (old_idx != new_idx)
409        {
410          char *array = array_;
411          char *element = xmalloc (size);
412          char *new = array + new_idx * size;
413          char *old = array + old_idx * size;
414    
415          memcpy (element, old, size);
416          if (new < old)
417            memmove (new + size, new, (old_idx - new_idx) * size);
418          else
419            memmove (old, old + size, (new_idx - old_idx) * size);
420          memcpy (new, element, size);
421    
422          free (element);
423        }
424    }
425    
426  /* A predicate and its auxiliary data. */  /* A predicate and its auxiliary data. */
427  struct pred_aux  struct pred_aux
428    {    {

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26