<commit_before>//
// Created by hrl on 9/21/15.
//

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "set_functions.h"
#include "sns_functions.h"
#include "set_structs.h"
#include "sns_structs.h"
#include "set_defines.h"
#include "sns_defines.h"

int people_compar(const void *a, const void *b){
    People *A, *B;
    A = (People*)a;
    B = (People*)b;
    return A->id - B->id;
}

int sns_init(Sns **self){
    if(*self != NULL){
        return SNS_INITED_ERROR;
    }

    *self = (Sns*)malloc(sizeof(Sns));
    if(*self == NULL) {
        return SNS_INIT_FAIL_ERROR;
    }

    (*self)->id_max = 0;
    (*self)->_peoples = NULL;

    int result;
    result = set_init(&((*self)->_peoples));
    if(result != SET_OP_SUCCESS) return SNS_INIT_FAIL_ERROR;

    return SNS_OP_SUCCESS;
}

int sns_del(Sns **self){
    if(*self == NULL){
        return SNS_OP_SUCCESS;
    }

    set_del(&((*self)->_peoples));
    free(*self);
    *self = NULL;

    return SNS_OP_SUCCESS;
}

int sns_search(Sns *self, People *people, People **result_people, int *result_found){
    if(self == NULL){
        return SNS_UNINIT_ERROR;
    }

    int result;
    result = set_search(self->_peoples, people, result_people, result_found, people_compar);
    if(result != SET_OP_SUCCESS) return SNS_SEARCH_ERROR;

    return SNS_OP_SUCCESS;
}

int sns_insert(Sns *self, People *people){
    if(self == NULL){
        return SNS_UNINIT_ERROR;
    }

    if(people == NULL){
        return PEOPLE_UNINIT_ERROR;
    }

    people->id = self->id_max + 1;

    int result;
    result = set_insert(&(self->_peoples), people, people_compar);
    if(result != SET_OP_SUCCESS) return SNS_INSERT_FAIL_ERROR;
    self->id_max++;

    return SNS_OP_SUCCESS;
}

int sns_delete(Sns *self, People *people){
    if(self == NULL){
        return SNS_UNINIT_ERROR;
    }
<commit_msg>sns: fix pointer in sns_search<commit_after>//
// Created by hrl on 9/21/15.
//

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "set_functions.h"
#include "sns_functions.h"
#include "set_structs.h"
#include "sns_structs.h"
#include "set_defines.h"
#include "sns_defines.h"

int people_compar(const void *a, const void *b){
    People *A, *B;
    A = (People*)a;
    B = (People*)b;
    return A->id - B->id;
}

int sns_init(Sns **self){
    if(*self != NULL){
        return SNS_INITED_ERROR;
    }

    *self = (Sns*)malloc(sizeof(Sns));
    if(*self == NULL) {
        return SNS_INIT_FAIL_ERROR;
    }

    (*self)->id_max = 0;
    (*self)->_peoples = NULL;

    int result;
    result = set_init(&((*self)->_peoples));
    if(result != SET_OP_SUCCESS) return SNS_INIT_FAIL_ERROR;

    return SNS_OP_SUCCESS;
}

int sns_del(Sns **self){
    if(*self == NULL){
        return SNS_OP_SUCCESS;
    }

    set_del(&((*self)->_peoples));
    free(*self);
    *self = NULL;

    return SNS_OP_SUCCESS;
}

int sns_search(Sns *self, People *people, People **result_people, int *result_found){
    if(self == NULL){
        return SNS_UNINIT_ERROR;
    }

    int result;
    result = set_search(self->_peoples, people, (void **)result_people, result_found, people_compar);
    if(result != SET_OP_SUCCESS) return SNS_SEARCH_ERROR;

    return SNS_OP_SUCCESS;
}

int sns_insert(Sns *self, People *people){
    if(self == NULL){
        return SNS_UNINIT_ERROR;
    }

    if(people == NULL){
        return PEOPLE_UNINIT_ERROR;
    }

    people->id = self->id_max + 1;

    int result;
    result = set_insert(&(self->_peoples), people, people_compar);
    if(result != SET_OP_SUCCESS) return SNS_INSERT_FAIL_ERROR;
    self->id_max++;

    return SNS_OP_SUCCESS;
}

int sns_delete(Sns *self, People *people){
    if(self == NULL){
        return SNS_UNINIT_ERROR;
    }

{'fraction_non_alphanumeric': 0.14693333333333333, 'fraction_numerical': 0.0037333333333333333, 'mean_word_length': 3.1957494407158835, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '383523', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1411, 'n_words': 297}