Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/LZH/HuffStatTmp.cpp

Go to the documentation of this file.
00001 #ifndef __J2K__LZH__HuffStatTmp_HPP__
00002 #define __J2K__LZH__HuffStatTmp_CPP__
00003 
00004 inline int cmpHuffStatTmpStruct( const HuffStatTmpStruct& a,
00005                                  const HuffStatTmpStruct& b )
00006 {
00007   int cmp = b.n - a.n;
00008   return ( cmp ? cmp : b.i - a.i );
00009 }
00010 
00011 inline int operator<( const HuffStatTmpStruct& a,
00012                       const HuffStatTmpStruct& b )
00013 {
00014   return cmpHuffStatTmpStruct( a, b ) < 0;
00015 }
00016 
00017 static int __cdecl _cmpStat( const void* a_, const void* b_ ) {
00018   HuffStatTmpStruct* a = (HuffStatTmpStruct*)a_;
00019   HuffStatTmpStruct* b = (HuffStatTmpStruct*)b_;
00020   return cmpHuffStatTmpStruct( *a, *b );
00021 }
00022 
00023 void shellSort( HuffStatTmpStruct* a, int N ) {
00024   int i, j;
00025   HuffStatTmpStruct v;
00026 
00027   /*
00028     for ( int h = 1; h <= N/9; h = ( 3 * h + 1 ) )// determine the value for h
00029     ;
00030   */
00031 
00032   assert( 13 <= N / 9 );
00033   assert( 40 > N / 9 ); 
00034 
00035   int h = 40;
00036 
00037   for ( ; h > 0; h /= 3 ) {       // h = 40, 13, 4, 1
00038     for ( i = h + 1; i <= N; ++i ) {
00039        v = a[i];
00040        j = i;
00041 
00042        while ( ( j > h ) && ( v < a[j - h] ) ) {
00043           a[j] = a[j-h];
00044           j -= h;
00045        }
00046 
00047        a[j] = v;
00048     }
00049   }
00050 }
00051 
00052 #endif

Generated on Sun Oct 14 18:46:32 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001