/* ECP: FILEname=fig10_23.c */ /* 1*/ HashTbl /* 2*/ HaMakeEmpty( HashTbl H ) /* 3*/ { /* 4*/ int i; /* 5*/ const Cell InitCell = { NULL, NotFound }; /* 6*/ if( H != NULL ) /* 7*/ { /* 8*/ for( i = 0; i < H->MaxSize; i++ ) /* 9*/ { /*10*/ free( H->Array[ i ].Word ); /*11*/ H->Array[ i ].Num = NotFound; /*12*/ } /*13*/ H->Size = 0; /*14*/ return H; /*15*/ } /*16*/ free( H ); /* Safe Even if H == NULL */ /*17*/ if( ( H = malloc( sizeof( struct HashStr ) ) ) == NULL ) /*18*/ return NULL; /*19*/ H->Array = malloc( sizeof( Cell ) * HaInitSize ); /*20*/ if( H->Array == NULL ) /*21*/ return NULL; /*22*/ H->Size = 0; /*23*/ H->MaxSize = HaInitSize; /*24*/ for( i = 0; i < H->MaxSize; i++ ) /*25*/ H->Array[ i ] = InitCell; /*26*/ return H; /*27*/ } /* 1*/ void /* 2*/ HaRecycle( HashTbl H ) /* 3*/ { /* 4*/ int i; /* 5*/ HaInsistGood( H ); /* 6*/ for( i = 0; i < H->MaxSize; i++ ) /* 7*/ free( H->Array[ i ].Word ); /* 8*/ free( H->Array ); /* 9*/ free( H ); /*10*/ }