train/swe_with_2nd_randomwalk.c
// Adds a word to the vocabulary
Adds a word to the vocabulary
Adds a word to the vocabulary
int AddWordToVocab(char *word) {
    unsigned int hash, length = strlen(word) + 1;
    if (length > MAX_STRING) length = MAX_STRING;
    vocab[vocab_size].word = (char *)calloc(length, sizeof(char));
    strcpy(vocab[vocab_size].word, word);
    vocab[vocab_size].cn = 0;
    vocab_size++;
    if (vocab_size + 2 >= vocab_max_size) {
        vocab_max_size += 1000;
        vocab = (struct vocab_word *)realloc(vocab, vocab_max_size * sizeof(struct vocab_word));
    }
    hash = GetWordHash(word); 
    while (vocab_hash[hash] != -1) hash = (hash + 1) % vocab_hash_size; 
    vocab_hash[hash] = vocab_size - 1; 
    return vocab_size - 1;
}
int AddWordToVocab ( char * word ) { unsigned int hash , length = strlen ( word ) + 1 ; if ( length > MAX_STRING ) length = MAX_STRING ; vocab [ vocab_size ] . word = ( char * ) calloc ( length , sizeof ( char ) ) ; strcpy ( vocab [ vocab_size ] . word , word ) ; vocab [ vocab_size ] . cn = 0 ; vocab_size ++ ; if ( vocab_size + 2 >= vocab_max_size ) { vocab_max_size += 1000 ; vocab = ( struct vocab_word * ) realloc ( vocab , vocab_max_size * sizeof ( struct vocab_word ) ) ; } hash = GetWordHash ( word ) ; while ( vocab_hash [ hash ] != -1 ) hash = ( hash + 1 ) % vocab_hash_size ; vocab_hash [ hash ] = vocab_size - 1 ; return vocab_size - 1 ; }
Adds a word to the vocabulary
Adds a word to the vocabulary
// Reallocate memory if needed // return the key by some hash function, but it may has conflict. // conflict //no conflict