train/swe_with_2nd_randomwalk.c
// Adds a user id to the user_vocabulary
Adds a user id to the user_vocabulary
Adds a user id to the user_vocabulary
int AddIDToUser(char *word) {
    unsigned int hash, length = strlen(word) + 1;
    if (length > MAX_USER_ID) length = MAX_USER_ID;
    user[user_size] = (char *)calloc(length, sizeof(char));
    strcpy(user[user_size], word);
    user_size++;
    if (user_size + 2 >= user_max_size) {
        user_max_size += 1000;
        user = (char**)realloc(user, user_max_size * sizeof(char*));
        if (user == NULL){
            printf("Not enough memory for user");
        }
    }
    hash = GetUserHash(word); 
    while (user_hash[hash] != -1) hash = (hash + 1) % user_hash_size; 
    user_hash[hash] = user_size - 1; 
    return user_size - 1;
}
int AddIDToUser ( char * word ) { unsigned int hash , length = strlen ( word ) + 1 ; if ( length > MAX_USER_ID ) length = MAX_USER_ID ; user [ user_size ] = ( char * ) calloc ( length , sizeof ( char ) ) ; strcpy ( user [ user_size ] , word ) ; user_size ++ ; if ( user_size + 2 >= user_max_size ) { user_max_size += 1000 ; user = ( char * * ) realloc ( user , user_max_size * sizeof ( char * ) ) ; if ( user == NULL ) { printf ( " " ) ; } } hash = GetUserHash ( word ) ; while ( user_hash [ hash ] != -1 ) hash = ( hash + 1 ) % user_hash_size ; user_hash [ hash ] = user_size - 1 ; return user_size - 1 ; }
Adds a user id to the user_vocabulary
Adds a user id to the user_vocabulary
// Reallocate memory if needed // return the key by some hash function, but it may has conflict. // conflict //no conflict