/* ECP: FILEname=fig10_24.c */ /* 1*/ static int /* 2*/ FindPos( const char *Key, const HashTbl H ) /* 3*/ { /* 4*/ unsigned int Pos; /* 5*/ Pos = Hash( Key, H->MaxSize ); /* 6*/ while( H->Array[ Pos ].Num != NotFound && /* 7*/ strcmp( H->Array[ Pos ].Word, Key ) ) /* 8*/ if( ++Pos == H->MaxSize ) /* 9*/ Pos = 0; /*10*/ return Pos; /*11*/ } /* 1*/ int /* 2*/ Find( const char *Key, const HashTbl H ) /* 3*/ { /* 4*/ return H->Array[ FindPos( Key, H ) ].Num; /* 5*/ } /* 1*/ /* Insert A new Key Into H, Making A Duplicate */ /* 2*/ int /* 3*/ Insert( const char *Key, HashTbl H ) /* 4*/ { /* 5*/ unsigned int Pos; /* 6*/ if( H->Size > H->MaxSize / 2 ) /* 7*/ Rehash( H ); /* 8*/ Pos = FindPos( Key, H ); /* 9*/ if( H->Array[ Pos ].Num == NotFound ) /*10*/ { /*11*/ H->Array[ Pos ].Word = Strdup( Key ); /*12*/ H->Array[ Pos ].Num = H->Size++; /*13*/ } /*14*/ return H->Array[ Pos ].Num; /*15*/ }