I hate homework requirement change on daily basic
This commit is contained in:
parent
9a4de9225d
commit
406e6052ce
|
@ -0,0 +1,257 @@
|
|||
The total number of prefixes in the input file is : 84633.
|
||||
The number of prefixes in group 0 = 0
|
||||
The number of prefixes in group 1 = 1
|
||||
The number of prefixes in group 2 = 1
|
||||
The number of prefixes in group 3 = 1
|
||||
The number of prefixes in group 4 = 221
|
||||
The number of prefixes in group 5 = 1
|
||||
The number of prefixes in group 6 = 10
|
||||
The number of prefixes in group 7 = 1
|
||||
The number of prefixes in group 8 = 1
|
||||
The number of prefixes in group 9 = 0
|
||||
The number of prefixes in group 10 = 1
|
||||
The number of prefixes in group 11 = 0
|
||||
The number of prefixes in group 12 = 1042
|
||||
The number of prefixes in group 13 = 13
|
||||
The number of prefixes in group 14 = 0
|
||||
The number of prefixes in group 15 = 32
|
||||
The number of prefixes in group 16 = 14
|
||||
The number of prefixes in group 17 = 18
|
||||
The number of prefixes in group 18 = 1
|
||||
The number of prefixes in group 19 = 0
|
||||
The number of prefixes in group 20 = 39
|
||||
The number of prefixes in group 21 = 0
|
||||
The number of prefixes in group 22 = 0
|
||||
The number of prefixes in group 23 = 1
|
||||
The number of prefixes in group 24 = 2211
|
||||
The number of prefixes in group 25 = 1
|
||||
The number of prefixes in group 26 = 0
|
||||
The number of prefixes in group 27 = 1
|
||||
The number of prefixes in group 28 = 0
|
||||
The number of prefixes in group 29 = 0
|
||||
The number of prefixes in group 30 = 0
|
||||
The number of prefixes in group 31 = 1
|
||||
The number of prefixes in group 32 = 365
|
||||
The number of prefixes in group 33 = 1
|
||||
The number of prefixes in group 34 = 0
|
||||
The number of prefixes in group 35 = 1
|
||||
The number of prefixes in group 36 = 1
|
||||
The number of prefixes in group 37 = 1
|
||||
The number of prefixes in group 38 = 58
|
||||
The number of prefixes in group 39 = 0
|
||||
The number of prefixes in group 40 = 35
|
||||
The number of prefixes in group 41 = 1
|
||||
The number of prefixes in group 42 = 1
|
||||
The number of prefixes in group 43 = 10
|
||||
The number of prefixes in group 44 = 4
|
||||
The number of prefixes in group 45 = 1
|
||||
The number of prefixes in group 46 = 0
|
||||
The number of prefixes in group 47 = 30
|
||||
The number of prefixes in group 48 = 0
|
||||
The number of prefixes in group 49 = 1
|
||||
The number of prefixes in group 50 = 1
|
||||
The number of prefixes in group 51 = 0
|
||||
The number of prefixes in group 52 = 3
|
||||
The number of prefixes in group 53 = 4
|
||||
The number of prefixes in group 54 = 0
|
||||
The number of prefixes in group 55 = 2
|
||||
The number of prefixes in group 56 = 5
|
||||
The number of prefixes in group 57 = 84
|
||||
The number of prefixes in group 58 = 1
|
||||
The number of prefixes in group 59 = 1
|
||||
The number of prefixes in group 60 = 1
|
||||
The number of prefixes in group 61 = 1313
|
||||
The number of prefixes in group 62 = 1565
|
||||
The number of prefixes in group 63 = 3158
|
||||
The number of prefixes in group 64 = 4212
|
||||
The number of prefixes in group 65 = 3417
|
||||
The number of prefixes in group 66 = 6483
|
||||
The number of prefixes in group 67 = 2474
|
||||
The number of prefixes in group 68 = 2740
|
||||
The number of prefixes in group 69 = 1137
|
||||
The number of prefixes in group 70 = 1
|
||||
The number of prefixes in group 71 = 1
|
||||
The number of prefixes in group 72 = 1
|
||||
The number of prefixes in group 73 = 1
|
||||
The number of prefixes in group 74 = 1
|
||||
The number of prefixes in group 75 = 1
|
||||
The number of prefixes in group 76 = 1
|
||||
The number of prefixes in group 77 = 1
|
||||
The number of prefixes in group 78 = 1
|
||||
The number of prefixes in group 79 = 1
|
||||
The number of prefixes in group 80 = 1103
|
||||
The number of prefixes in group 81 = 784
|
||||
The number of prefixes in group 82 = 419
|
||||
The number of prefixes in group 83 = 8
|
||||
The number of prefixes in group 84 = 1
|
||||
The number of prefixes in group 85 = 1
|
||||
The number of prefixes in group 86 = 1
|
||||
The number of prefixes in group 87 = 1
|
||||
The number of prefixes in group 88 = 1
|
||||
The number of prefixes in group 89 = 1
|
||||
The number of prefixes in group 90 = 1
|
||||
The number of prefixes in group 91 = 1
|
||||
The number of prefixes in group 92 = 1
|
||||
The number of prefixes in group 93 = 1
|
||||
The number of prefixes in group 94 = 1
|
||||
The number of prefixes in group 95 = 1
|
||||
The number of prefixes in group 96 = 1
|
||||
The number of prefixes in group 97 = 1
|
||||
The number of prefixes in group 98 = 1
|
||||
The number of prefixes in group 99 = 1
|
||||
The number of prefixes in group 100 = 1
|
||||
The number of prefixes in group 101 = 1
|
||||
The number of prefixes in group 102 = 1
|
||||
The number of prefixes in group 103 = 1
|
||||
The number of prefixes in group 104 = 1
|
||||
The number of prefixes in group 105 = 1
|
||||
The number of prefixes in group 106 = 1
|
||||
The number of prefixes in group 107 = 1
|
||||
The number of prefixes in group 108 = 1
|
||||
The number of prefixes in group 109 = 1
|
||||
The number of prefixes in group 110 = 1
|
||||
The number of prefixes in group 111 = 1
|
||||
The number of prefixes in group 112 = 1
|
||||
The number of prefixes in group 113 = 1
|
||||
The number of prefixes in group 114 = 1
|
||||
The number of prefixes in group 115 = 1
|
||||
The number of prefixes in group 116 = 1
|
||||
The number of prefixes in group 117 = 1
|
||||
The number of prefixes in group 118 = 1
|
||||
The number of prefixes in group 119 = 1
|
||||
The number of prefixes in group 120 = 1
|
||||
The number of prefixes in group 121 = 1
|
||||
The number of prefixes in group 122 = 1
|
||||
The number of prefixes in group 123 = 1
|
||||
The number of prefixes in group 124 = 1
|
||||
The number of prefixes in group 125 = 0
|
||||
The number of prefixes in group 126 = 1
|
||||
The number of prefixes in group 127 = 0
|
||||
The number of prefixes in group 128 = 419
|
||||
The number of prefixes in group 129 = 567
|
||||
The number of prefixes in group 130 = 297
|
||||
The number of prefixes in group 131 = 277
|
||||
The number of prefixes in group 132 = 156
|
||||
The number of prefixes in group 133 = 146
|
||||
The number of prefixes in group 134 = 457
|
||||
The number of prefixes in group 135 = 75
|
||||
The number of prefixes in group 136 = 256
|
||||
The number of prefixes in group 137 = 324
|
||||
The number of prefixes in group 138 = 307
|
||||
The number of prefixes in group 139 = 296
|
||||
The number of prefixes in group 140 = 478
|
||||
The number of prefixes in group 141 = 386
|
||||
The number of prefixes in group 142 = 715
|
||||
The number of prefixes in group 143 = 249
|
||||
The number of prefixes in group 144 = 253
|
||||
The number of prefixes in group 145 = 173
|
||||
The number of prefixes in group 146 = 648
|
||||
The number of prefixes in group 147 = 280
|
||||
The number of prefixes in group 148 = 585
|
||||
The number of prefixes in group 149 = 235
|
||||
The number of prefixes in group 150 = 299
|
||||
The number of prefixes in group 151 = 253
|
||||
The number of prefixes in group 152 = 1488
|
||||
The number of prefixes in group 153 = 130
|
||||
The number of prefixes in group 154 = 14
|
||||
The number of prefixes in group 155 = 374
|
||||
The number of prefixes in group 156 = 155
|
||||
The number of prefixes in group 157 = 254
|
||||
The number of prefixes in group 158 = 303
|
||||
The number of prefixes in group 159 = 341
|
||||
The number of prefixes in group 160 = 220
|
||||
The number of prefixes in group 161 = 264
|
||||
The number of prefixes in group 162 = 510
|
||||
The number of prefixes in group 163 = 242
|
||||
The number of prefixes in group 164 = 612
|
||||
The number of prefixes in group 165 = 525
|
||||
The number of prefixes in group 166 = 335
|
||||
The number of prefixes in group 167 = 392
|
||||
The number of prefixes in group 168 = 501
|
||||
The number of prefixes in group 169 = 184
|
||||
The number of prefixes in group 170 = 587
|
||||
The number of prefixes in group 171 = 47
|
||||
The number of prefixes in group 172 = 35
|
||||
The number of prefixes in group 173 = 1
|
||||
The number of prefixes in group 174 = 1
|
||||
The number of prefixes in group 175 = 1
|
||||
The number of prefixes in group 176 = 1
|
||||
The number of prefixes in group 177 = 1
|
||||
The number of prefixes in group 178 = 1
|
||||
The number of prefixes in group 179 = 1
|
||||
The number of prefixes in group 180 = 1
|
||||
The number of prefixes in group 181 = 1
|
||||
The number of prefixes in group 182 = 1
|
||||
The number of prefixes in group 183 = 1
|
||||
The number of prefixes in group 184 = 1
|
||||
The number of prefixes in group 185 = 1
|
||||
The number of prefixes in group 186 = 1
|
||||
The number of prefixes in group 187 = 1
|
||||
The number of prefixes in group 188 = 1
|
||||
The number of prefixes in group 189 = 1
|
||||
The number of prefixes in group 190 = 0
|
||||
The number of prefixes in group 191 = 0
|
||||
The number of prefixes in group 192 = 6415
|
||||
The number of prefixes in group 193 = 3705
|
||||
The number of prefixes in group 194 = 3171
|
||||
The number of prefixes in group 195 = 3006
|
||||
The number of prefixes in group 196 = 686
|
||||
The number of prefixes in group 197 = 1
|
||||
The number of prefixes in group 198 = 4505
|
||||
The number of prefixes in group 199 = 3583
|
||||
The number of prefixes in group 200 = 4679
|
||||
The number of prefixes in group 201 = 26
|
||||
The number of prefixes in group 202 = 3390
|
||||
The number of prefixes in group 203 = 0
|
||||
The number of prefixes in group 204 = 0
|
||||
The number of prefixes in group 205 = 0
|
||||
The number of prefixes in group 206 = 0
|
||||
The number of prefixes in group 207 = 0
|
||||
The number of prefixes in group 208 = 0
|
||||
The number of prefixes in group 209 = 0
|
||||
The number of prefixes in group 210 = 0
|
||||
The number of prefixes in group 211 = 0
|
||||
The number of prefixes in group 212 = 0
|
||||
The number of prefixes in group 213 = 0
|
||||
The number of prefixes in group 214 = 0
|
||||
The number of prefixes in group 215 = 0
|
||||
The number of prefixes in group 216 = 0
|
||||
The number of prefixes in group 217 = 0
|
||||
The number of prefixes in group 218 = 0
|
||||
The number of prefixes in group 219 = 0
|
||||
The number of prefixes in group 220 = 0
|
||||
The number of prefixes in group 221 = 0
|
||||
The number of prefixes in group 222 = 0
|
||||
The number of prefixes in group 223 = 0
|
||||
The number of prefixes in group 224 = 0
|
||||
The number of prefixes in group 225 = 0
|
||||
The number of prefixes in group 226 = 0
|
||||
The number of prefixes in group 227 = 0
|
||||
The number of prefixes in group 228 = 0
|
||||
The number of prefixes in group 229 = 0
|
||||
The number of prefixes in group 230 = 0
|
||||
The number of prefixes in group 231 = 0
|
||||
The number of prefixes in group 232 = 0
|
||||
The number of prefixes in group 233 = 0
|
||||
The number of prefixes in group 234 = 0
|
||||
The number of prefixes in group 235 = 0
|
||||
The number of prefixes in group 236 = 0
|
||||
The number of prefixes in group 237 = 0
|
||||
The number of prefixes in group 238 = 0
|
||||
The number of prefixes in group 239 = 0
|
||||
The number of prefixes in group 240 = 0
|
||||
The number of prefixes in group 241 = 0
|
||||
The number of prefixes in group 242 = 0
|
||||
The number of prefixes in group 243 = 0
|
||||
The number of prefixes in group 244 = 0
|
||||
The number of prefixes in group 245 = 0
|
||||
The number of prefixes in group 246 = 0
|
||||
The number of prefixes in group 247 = 0
|
||||
The number of prefixes in group 248 = 0
|
||||
The number of prefixes in group 249 = 0
|
||||
The number of prefixes in group 250 = 0
|
||||
The number of prefixes in group 251 = 0
|
||||
The number of prefixes in group 252 = 0
|
||||
The number of prefixes in group 253 = 0
|
||||
The number of prefixes in group 254 = 0
|
||||
The number of prefixes in group 255 = 0
|
BIN
homework_11
BIN
homework_11
Binary file not shown.
|
@ -17,6 +17,8 @@ struct SizedSubmask
|
|||
usize display_submask(struct SizedSubmask *mask);
|
||||
usize display_ip(struct SizedSubmask *mask);
|
||||
void parse_submask(char* cstr, struct SizedSubmask *mask);
|
||||
void parse_ip(char* cstr, union Submask *mask);
|
||||
struct SizedSubmask* scale(union Submask* mask);
|
||||
struct SizedSubmask* clone_submask(struct SizedSubmask *mask);
|
||||
bool reduce_submask(struct SizedSubmask* source);
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ struct Node* xor_insert_condition(struct Node* head,void* val,bool (*cmp)(void *
|
|||
usize amount=0;
|
||||
while(current!=NULL){
|
||||
struct Node* next=xor_next(previous,current);
|
||||
if(!cmp(val,current->val)){
|
||||
if(cmp(val,current->val)){
|
||||
xor_insert_mid(current,next,val);
|
||||
return head;
|
||||
}
|
||||
|
|
|
@ -13,11 +13,11 @@ int main()
|
|||
state.head=NULL;
|
||||
|
||||
input(&state);
|
||||
length_distribution(&state);
|
||||
// length_distribution(&state);
|
||||
segment(&state);
|
||||
// prefix_insert(&state);
|
||||
// prefix_delete(&state);
|
||||
search(&state);
|
||||
// search(&state);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
14
src/state.c
14
src/state.c
|
@ -48,6 +48,20 @@ void parse_submask(char* cstr, struct SizedSubmask *mask){
|
|||
}else mask->len=parse_number(&cstr);
|
||||
}
|
||||
|
||||
void parse_ip(char* cstr, union Submask *mask){
|
||||
for (usize i=0;i<4;i++){
|
||||
mask->mask[3-i]=(u8)parse_number(&cstr);
|
||||
cstr++;
|
||||
}
|
||||
}
|
||||
struct SizedSubmask* scale(union Submask* mask){
|
||||
struct SizedSubmask* result=malloc(sizeof(struct SizedSubmask));
|
||||
|
||||
result->mask.raw=(((mask->raw)>>(32-D))<<(32-D));
|
||||
result->len=D;
|
||||
return result;
|
||||
}
|
||||
|
||||
struct SizedSubmask* clone_submask(struct SizedSubmask *mask){
|
||||
struct SizedSubmask *new=malloc(sizeof(struct SizedSubmask));
|
||||
new->len=mask->len;
|
||||
|
|
56
src/v2.c
56
src/v2.c
|
@ -60,43 +60,45 @@ void segment(struct State* state){
|
|||
mask.len=D;
|
||||
mask.mask.raw=i<<(32-D);
|
||||
|
||||
printf("| ");
|
||||
print_binary(i);
|
||||
printf(" |");
|
||||
struct Node* head=hash_get(state->hashmap,&mask);
|
||||
printf("The number of prefixes in group %zu = %zu\n",i,xor_count(head));
|
||||
// printf("| ");
|
||||
// print_binary(i);
|
||||
// printf(" |");
|
||||
|
||||
struct Node* current=hash_get(state->hashmap,&mask);
|
||||
struct Node* previous=NULL;
|
||||
// struct Node* current=hash_get(state->hashmap,&mask);
|
||||
// struct Node* previous=NULL;
|
||||
|
||||
while(current!=NULL){
|
||||
struct Node* next=xor_next(previous,current);
|
||||
// while(current!=NULL){
|
||||
// struct Node* next=xor_next(previous,current);
|
||||
|
||||
printf(" ---> | ");
|
||||
display_ip(current->val);
|
||||
printf(" |");
|
||||
// printf(" ---> | ");
|
||||
// display_ip(current->val);
|
||||
// printf(" |");
|
||||
|
||||
previous=current;
|
||||
current=next;
|
||||
}
|
||||
printf("\n");
|
||||
// previous=current;
|
||||
// current=next;
|
||||
// }
|
||||
// printf("\n");
|
||||
}
|
||||
|
||||
{
|
||||
printf("--------special group--------\n");
|
||||
// {
|
||||
// printf("--------special group--------\n");
|
||||
|
||||
struct Node* current=state->head;
|
||||
struct Node* previous=NULL;
|
||||
// struct Node* current=state->head;
|
||||
// struct Node* previous=NULL;
|
||||
|
||||
while(current!=NULL){
|
||||
struct Node* next=xor_next(previous,current);
|
||||
// while(current!=NULL){
|
||||
// struct Node* next=xor_next(previous,current);
|
||||
|
||||
display_ip(current->val);
|
||||
printf("\n");
|
||||
// display_ip(current->val);
|
||||
// printf("\n");
|
||||
|
||||
previous=current;
|
||||
current=next;
|
||||
}
|
||||
// previous=current;
|
||||
// current=next;
|
||||
// }
|
||||
|
||||
printf("-----------------------------\n");
|
||||
}
|
||||
// printf("-----------------------------\n");
|
||||
// }
|
||||
|
||||
}
|
56
src/v3.c
56
src/v3.c
|
@ -13,6 +13,14 @@ bool eq_v3(void* a,void* b){
|
|||
return mask_a->mask.raw==mask_b->mask.raw;
|
||||
}
|
||||
|
||||
bool eq_v3_subset(void* val,void* target){
|
||||
struct SizedSubmask* mask=val;
|
||||
union Submask* ip=target;
|
||||
usize r_bit=32-(mask->len);
|
||||
return (mask->mask.raw<<r_bit)==(ip->raw<<r_bit);
|
||||
}
|
||||
|
||||
|
||||
// remove match element, return new head
|
||||
struct Node* xor_remove_match(struct Node* head,void* target,bool (*eq)(void *,void *)){
|
||||
struct Node* previous=NULL;
|
||||
|
@ -124,49 +132,23 @@ void search(struct State* state){
|
|||
fgets(buffer,20,table);
|
||||
if(*buffer=='\0') break;
|
||||
|
||||
struct SizedSubmask* mask=malloc(sizeof(struct SizedSubmask));
|
||||
parse_submask(buffer,mask);
|
||||
struct SizedSubmask* ip=clone_submask(mask);
|
||||
|
||||
record_start
|
||||
union Submask ip;
|
||||
parse_ip(buffer,&ip);
|
||||
struct SizedSubmask* mask=scale(&ip);
|
||||
|
||||
freq++;
|
||||
|
||||
if(reduce_submask(mask)){
|
||||
struct Node* ll=hash_pop(state->hashmap,mask);
|
||||
record_start
|
||||
|
||||
record_end("search.csv")
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
if (xor_contain(ll,ip,eq_v3)) printf("successful\n");
|
||||
else printf("failed\n");
|
||||
hash_insert(state->hashmap,mask,ll);
|
||||
}else{
|
||||
if (xor_contain(state->head,ip,eq_v3)) printf("successful\n");
|
||||
else printf("failed\n");
|
||||
free(mask);
|
||||
}
|
||||
struct Node* ll=hash_get(state->hashmap,mask);
|
||||
|
||||
record_end("search.csv")
|
||||
free(ip);
|
||||
|
||||
// if(reduce_submask(mask))ll=hash_get(state->hashmap,mask);
|
||||
// else ll=state->head;
|
||||
|
||||
// freq++;
|
||||
|
||||
// record_end("search.csv")
|
||||
|
||||
// printf("head: %zu\n",ll);
|
||||
|
||||
// fflush(stdout);
|
||||
|
||||
// if (xor_contain(ll,ip,eq_v3)) printf("successful\n");
|
||||
// else printf("failed\n");
|
||||
if (xor_contain(ll,&ip,eq_v3_subset)||xor_contain(state->head,&ip,eq_v3_subset))
|
||||
printf("successful\n");
|
||||
else printf("failed\n");
|
||||
|
||||
// free(ip);
|
||||
// free(mask);
|
||||
record_end("search.csv")
|
||||
|
||||
free(mask);
|
||||
}
|
||||
|
||||
clock_end
|
||||
|
|
Loading…
Reference in New Issue