Skip to content
Snippets Groups Projects
Select Git revision
  • 0683be9c77db4c4ad67a16c06cf7e4561f33bd67
  • master default protected
  • 9.0
  • 8.0
  • nt-tools
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • grubba/wip/sakura/8.0
  • v8.0.2020
  • v8.0.2018
  • v8.0.2016
  • v8.0.2014
  • v8.0.2012
  • v8.0.2008
  • v8.0.2006
  • v8.0.2004
  • v8.0.2002
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
41 results

fsort.c

Blame
  • fsort.c 1.93 KiB
    /*\
    ||| This file a part of Pike, and is copyright by Fredrik Hubinette
    ||| Pike is distributed as GPL (General Public License)
    ||| See the files COPYING and DISCLAIMER for more information.
    \*/
    /* fsort- a smarter quicksort /Hubbe */
    /* Optimized for minimum amount of compares */
    
    #include "global.h"
    #include "fsort.h"
    
    static fsortfun cmpfun;
    static long size;
    static char *tmp_area;
    
    #define SWAP(X,Y) { tmp=*(X); *(X)=*(Y); *(Y)=tmp; }
    #define STEP(X,Y) ((X)+(Y))
    
    #define ID fsort_1
    typedef struct a1 { char b[1]; } b1;
    #define TYPE b1
    #include "fsort_template.h"
    #undef ID
    #undef TYPE
    
    #define ID fsort_2
    typedef struct a2 { char b[2]; } b2;
    #define TYPE b2
    #include "fsort_template.h"
    #undef ID
    #undef TYPE
    
    #define ID fsort_4
    typedef struct a4 { char b[4]; } b4;
    #define TYPE b4
    #include "fsort_template.h"
    #undef ID
    #undef TYPE
    
    
    #define ID fsort_8
    typedef struct a8 { char b[8]; } b8;
    #define TYPE b8
    #include "fsort_template.h"
    #undef ID
    #undef TYPE
    
    #define ID fsort_16
    typedef struct a16 { char b[16]; } b16;
    #define TYPE b16
    #include "fsort_template.h"
    #undef ID
    #undef TYPE
    
    #undef SWAP
    #undef STEP
    
    
    #define SWAP(X,Y) do { \
        MEMCPY(tmp_area,X,size); \
        MEMCPY(X,Y,size); \
        MEMCPY(Y,tmp_area,size); \
     } while(0)
    
    #define STEP(X,Y) ((X)+(Y)*size)
    #define TYPE char
    #define ID fsort_n
    #include "fsort_template.h"
    #undef ID
    #undef TYPE
    #undef SWAP
    #undef STEP
    
    void fsort(void *base,
    	   long elms,
    	   long elmSize,
    	   fsortfun cmpfunc)
    {
    
      if(elms<=0) return;
      cmpfun=cmpfunc;
      size=elmSize;
    
      switch(elmSize)
      {
      case  1:  fsort_1(( b1 *)base,(elms-1)+( b1 *)base); break;
      case  2:  fsort_2(( b2 *)base,(elms-1)+( b2 *)base); break;
      case  4:  fsort_4(( b4 *)base,(elms-1)+( b4 *)base); break;
      case  8:  fsort_8(( b8 *)base,(elms-1)+( b8 *)base); break;
      case 16: fsort_16((b16 *)base,(elms-1)+(b16 *)base); break;
      default:
        tmp_area=(char *)alloca(elmSize);
        fsort_n((char *)base,((char *)base) + size * (elms - 1));
      }
    
    }