/* ECP: FILEname=fig10_25.c */ /* 1*/ static void /* 2*/ Rehash( HashTbl H ) /* 3*/ { /* 4*/ unsigned int i, Pos, OldSize = H->MaxSize; /* 5*/ Cell *OldArray = H->Array; /* 6*/ const Cell InitCell = { NULL, NotFound }; /* 7*/ H->MaxSize = NextPrime( 2 * OldSize ); /* 8*/ H->Array = malloc( sizeof( Cell ) * H->MaxSize ); /* 9*/ if( H->Array == NULL ) /*10*/ { /*11*/ printf( "Can not rehash\n" ); /*12*/ exit( -1 ); /*13*/ } /*14*/ H->Size = 0; /*15*/ for( i = 0; i < H->MaxSize; i++ ) /*16*/ H->Array[ i ] = InitCell; /*17*/ /* Reinsert Old Elements Into new Table */ /*18*/ for( i = 0; i < OldSize; i++ ) /*19*/ if( OldArray[ i ].Num >= 0 ) /*20*/ { /*21*/ Pos = FindPos( OldArray[ i ].Word, H ); /*22*/ H->Array[ Pos ] = OldArray[ i ]; /*23*/ H->Size++; /*24*/ } /*25*/ free( OldArray ); /*26*/ }