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

67
a.txt
View File

@ -31,39 +31,40 @@ make[2]: Leaving directory '/home/eason/Documents/project/HW11'
[100%] Built target homework_11 [100%] Built target homework_11
make[1]: Leaving directory '/home/eason/Documents/project/HW11' make[1]: Leaving directory '/home/eason/Documents/project/HW11'
/usr/bin/cmake -E cmake_progress_start /home/eason/Documents/project/HW11/CMakeFiles 0 /usr/bin/cmake -E cmake_progress_start /home/eason/Documents/project/HW11/CMakeFiles 0
the number of prefixes with prefix length 0 = 0 The total number of prefixes in the input file is : 84633.
the number of prefixes with prefix length 1 = 0 the number of prefixes with prefix length 0 = 0.
the number of prefixes with prefix length 2 = 0 the number of prefixes with prefix length 1 = 0.
the number of prefixes with prefix length 3 = 1 the number of prefixes with prefix length 2 = 0.
the number of prefixes with prefix length 4 = 0 the number of prefixes with prefix length 3 = 1.
the number of prefixes with prefix length 5 = 1 the number of prefixes with prefix length 4 = 0.
the number of prefixes with prefix length 6 = 3 the number of prefixes with prefix length 5 = 1.
the number of prefixes with prefix length 7 = 4 the number of prefixes with prefix length 6 = 3.
the number of prefixes with prefix length 8 = 107 the number of prefixes with prefix length 7 = 4.
the number of prefixes with prefix length 9 = 3 the number of prefixes with prefix length 8 = 107.
the number of prefixes with prefix length 10 = 5 the number of prefixes with prefix length 9 = 3.
the number of prefixes with prefix length 11 = 9 the number of prefixes with prefix length 10 = 5.
the number of prefixes with prefix length 12 = 47 the number of prefixes with prefix length 11 = 9.
the number of prefixes with prefix length 13 = 70 the number of prefixes with prefix length 12 = 47.
the number of prefixes with prefix length 14 = 164 the number of prefixes with prefix length 13 = 70.
the number of prefixes with prefix length 15 = 317 the number of prefixes with prefix length 14 = 164.
the number of prefixes with prefix length 16 = 6117 the number of prefixes with prefix length 15 = 317.
the number of prefixes with prefix length 17 = 1083 the number of prefixes with prefix length 16 = 6117.
the number of prefixes with prefix length 18 = 1769 the number of prefixes with prefix length 17 = 1083.
the number of prefixes with prefix length 19 = 4489 the number of prefixes with prefix length 18 = 1769.
the number of prefixes with prefix length 20 = 5553 the number of prefixes with prefix length 19 = 4489.
the number of prefixes with prefix length 21 = 4246 the number of prefixes with prefix length 20 = 5553.
the number of prefixes with prefix length 22 = 6090 the number of prefixes with prefix length 21 = 4246.
the number of prefixes with prefix length 23 = 7772 the number of prefixes with prefix length 22 = 6090.
the number of prefixes with prefix length 24 = 43679 the number of prefixes with prefix length 23 = 7772.
the number of prefixes with prefix length 25 = 383 the number of prefixes with prefix length 24 = 43679.
the number of prefixes with prefix length 26 = 387 the number of prefixes with prefix length 25 = 383.
the number of prefixes with prefix length 27 = 439 the number of prefixes with prefix length 26 = 387.
the number of prefixes with prefix length 28 = 338 the number of prefixes with prefix length 27 = 439.
the number of prefixes with prefix length 29 = 989 the number of prefixes with prefix length 28 = 338.
the number of prefixes with prefix length 30 = 454 the number of prefixes with prefix length 29 = 989.
the number of prefixes with prefix length 31 = 1 the number of prefixes with prefix length 30 = 454.
the number of prefixes with prefix length 32 = 113 the number of prefixes with prefix length 31 = 1.
the number of prefixes with prefix length 32 = 113.
| 00000000 | | 00000000 |
| 00000001 | ---> | 1.0.0.0 | | 00000001 | ---> | 1.0.0.0 |
| 00000010 | ---> | 2.0.0.0 | | 00000010 | ---> | 2.0.0.0 |

Binary file not shown.

View File

@ -7,18 +7,23 @@
void input(struct State* state){ void input(struct State* state){
FILE * table = fopen("routing_table.txt","r"); FILE * table = fopen("routing_table.txt","r");
usize amount=0;
while(true){ while(true){
char buffer[20]={'\0'}; char buffer[20]={'\0'};
fgets(buffer,20,table); fgets(buffer,20,table);
if(*buffer=='\0') break; if(*buffer=='\0') break;
amount++;
struct SizedSubmask* mask=malloc(sizeof(struct SizedSubmask)); struct SizedSubmask* mask=malloc(sizeof(struct SizedSubmask));
parse_submask(buffer,mask); parse_submask(buffer,mask);
if(mask<10000)printf("%zu\n",mask); if(mask<10000)printf("%zu\n",mask);
state->head=xor_insert_mid(NULL,state->head,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){ void length_distribution(struct State* state){
@ -37,5 +42,5 @@ void length_distribution(struct State* state){
} }
for(usize i=0;i<=32;i++) 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); parse_submask(buffer,mask);
struct SizedSubmask* ip=clone_submask(mask); struct SizedSubmask* ip=clone_submask(mask);
// record_start record_start
if(reduce_submask(mask)){ if(reduce_submask(mask)){
struct Node* ll=hash_pop(state->hashmap,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); hash_insert(state->hashmap,mask,new);
}else state->head=xor_insert_mid(NULL,state->head,ip); }else state->head=xor_insert_mid(NULL,state->head,ip);
// record_end("prefix_insert.csv") record_end("prefix_insert.csv")
freq++; freq++;
} }
@ -93,6 +93,9 @@ void prefix_delete(struct State* state){
if(reduce_submask(mask)){ if(reduce_submask(mask)){
struct Node* ll=hash_pop(state->hashmap,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); struct Node* new_head=xor_remove_match(ll,ip,eq_v3);
if(new_head!=NULL)hash_insert(state->hashmap,mask,new_head); 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") record_end("prefix_delete.csv")
free(ip); free(ip);
} }