train/swe_with_2nd_randomwalk.c
// Create an adjacent list to represent social graph using user_graph.txt which contains social information
Create an adjacent list to represent social graph using user_graph.txt which contains social information
Create an adjacent list to represent social graph using user_graph . txt which contains social information
void CreateAdjacentList(){
    char word[MAX_STRING];
    FILE *fin;
    long long i, head, friend;
    user_graph = (long long **)malloc(user_size * sizeof(long long *));
    friend_size = (long long *)calloc(user_size, sizeof(long long));
    fin = fopen(user_graph_file, "rb");
    if (fin == NULL) {
        printf("ERROR: user graph file not found!\n");
        exit(1);
    }
    fseek(fin, 0, SEEK_SET);
    while(1) {
        ReadWord(word,fin);
        if (feof(fin)) break;
        head = SearchUser(word);
        if (head == -1) {
            while(1){
                if(strcmp(word,"</s>")==0) break;
                ReadWord(word, fin);
                if (feof(fin)) break;
            }
            continue;
        }
        ReadWord(word, fin);
        friend_size[head] = atoll(word);
        user_graph[head] = (long long*)malloc(friend_size[head] * sizeof(long long));
        i = 0;
        while (i < friend_size[head]) {
            ReadWord(word, fin);
            friend = SearchUser(word);
            if (friend == -1) {
                --friend_size[head];
                continue;
            }
            user_graph[head][i++] = friend;
        }
        qsort(user_graph[head], friend_size[head], sizeof(long long), UserIDCompare);
    }
    fclose(fin);
}
void CreateAdjacentList ( ) { char word [ MAX_STRING ] ; FILE * fin ; long long i , head , friend ; user_graph = ( long long * * ) malloc ( user_size * sizeof ( long long * ) ) ; friend_size = ( long long * ) calloc ( user_size , sizeof ( long long ) ) ; fin = fopen ( user_graph_file , " " ) ; if ( fin == NULL ) { printf ( " \n " ) ; exit ( 1 ) ; } fseek ( fin , 0 , SEEK_SET ) ; while ( 1 ) { ReadWord ( word , fin ) ; if ( feof ( fin ) ) break ; head = SearchUser ( word ) ; if ( head == -1 ) { while ( 1 ) { if ( strcmp ( word , " " ) == 0 ) break ; ReadWord ( word , fin ) ; if ( feof ( fin ) ) break ; } continue ; } ReadWord ( word , fin ) ; friend_size [ head ] = atoll ( word ) ; user_graph [ head ] = ( long long * ) malloc ( friend_size [ head ] * sizeof ( long long ) ) ; i = 0 ; while ( i < friend_size [ head ] ) { ReadWord ( word , fin ) ; friend = SearchUser ( word ) ; if ( friend == -1 ) { -- friend_size [ head ] ; continue ; } user_graph [ head ] [ i ++ ] = friend ; } qsort ( user_graph [ head ] , friend_size [ head ] , sizeof ( long long ) , UserIDCompare ) ; } fclose ( fin ) ; }
Create an adjacent list to represent social graph using user_graph.txt which contains social information
Create an adjacent list to represent social graph using user_graph . txt which contains social information
//read head // the head is not a user