This commit is contained in:
eason
2023-12-21 11:00:25 +08:00
parent a967a59145
commit 37ca8ca5bf
4 changed files with 46 additions and 38 deletions

View File

@ -7,18 +7,23 @@
void input(struct State* state){
FILE * table = fopen("routing_table.txt","r");
usize amount=0;
while(true){
char buffer[20]={'\0'};
fgets(buffer,20,table);
if(*buffer=='\0') break;
amount++;
struct SizedSubmask* mask=malloc(sizeof(struct SizedSubmask));
parse_submask(buffer,mask);
if(mask<10000)printf("%zu\n",mask);
state->head=xor_insert_mid(NULL,state->head,mask);
}
printf("The total number of prefixes in the input file is : %zu.\n",amount);
}
void length_distribution(struct State* state){
@ -37,5 +42,5 @@ void length_distribution(struct State* state){
}
for(usize i=0;i<=32;i++)
printf("the number of prefixes with prefix length %zu = %zu\n",i,lens[i]);
printf("the number of prefixes with prefix length %zu = %zu.\n",i,lens[i]);
}

View File

@ -58,7 +58,7 @@ void prefix_insert(struct State* state){
parse_submask(buffer,mask);
struct SizedSubmask* ip=clone_submask(mask);
// record_start
record_start
if(reduce_submask(mask)){
struct Node* ll=hash_pop(state->hashmap,mask);
@ -67,7 +67,7 @@ void prefix_insert(struct State* state){
hash_insert(state->hashmap,mask,new);
}else state->head=xor_insert_mid(NULL,state->head,ip);
// record_end("prefix_insert.csv")
record_end("prefix_insert.csv")
freq++;
}
@ -93,6 +93,9 @@ void prefix_delete(struct State* state){
if(reduce_submask(mask)){
struct Node* ll=hash_pop(state->hashmap,mask);
if(ll==NULL){
log_warn("not found");
}
struct Node* new_head=xor_remove_match(ll,ip,eq_v3);
if(new_head!=NULL)hash_insert(state->hashmap,mask,new_head);
@ -105,7 +108,6 @@ void prefix_delete(struct State* state){
record_end("prefix_delete.csv")
free(ip);
}