pike.git / src / array.c

version» Context lines:

pike.git/src/array.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: array.c,v 1.136 2003/11/09 02:40:42 mast Exp $ + || $Id: array.c,v 1.137 2004/04/14 22:04:37 mast Exp $   */      #include "global.h"   #include "svalue.h"   #include "array.h"   #include "object.h"   #include "las.h"   #include "stralloc.h"   #include "interpret.h"   #include "opcodes.h"
pike.git/src/array.c:18:   #include "fsort.h"   #include "builtin_functions.h"   #include "pike_memory.h"   #include "gc.h"   #include "main.h"   #include "security.h"   #include "stuff.h"   #include "bignum.h"   #include "cyclic.h"    - RCSID("$Id: array.c,v 1.136 2003/11/09 02:40:42 mast Exp $"); + RCSID("$Id: array.c,v 1.137 2004/04/14 22:04:37 mast Exp $");      PMOD_EXPORT struct array empty_array=   {    PIKE_CONSTANT_MEMOBJ_INIT(1), /* Never free */    &weak_empty_array, /* Next */    &weak_shrink_empty_array, /* previous (circular) */    0, /* Size = 0 */    0, /* malloced Size = 0 */    0, /* no types */    0, /* no flags */
pike.git/src/array.c:647:    if(d_flag > 1) array_check_type_field(v);   #endif    return -1;   }      static int internal_cmpfun(INT32 *a,    INT32 *b,    cmpfun current_cmpfun,    struct svalue *current_array_p)   { -  return current_cmpfun(current_array_p + *a, current_array_p + *b); +  int res = current_cmpfun(current_array_p + *a, current_array_p + *b); +  /* If the comparison considers the elements equal we compare their +  * positions. Thus we get a stable sort function. */ +  return res ? res : *a - *b;   }      #define CMP(X,Y) internal_cmpfun((X),(Y),current_cmpfun, current_array_p)   #define TYPE INT32   #define ID get_order_fsort   #define EXTRA_ARGS ,cmpfun current_cmpfun, struct svalue *current_array_p   #define XARGS ,current_cmpfun, current_array_p   #include "fsort_template.h"   #undef CMP   #undef TYPE   #undef ID   #undef EXTRA_ARGS   #undef XARGS    -  + /* The sort is stable. */   INT32 *get_order(struct array *v, cmpfun fun)   {    INT32 e, *current_order;    ONERROR tmp;       if(!v->size) return 0;       current_order=(INT32 *)xalloc(v->size * sizeof(INT32));    SET_ONERROR(tmp, free, current_order);    for(e=0; e<v->size; e++) current_order[e]=e;