working
This commit is contained in:
parent
02e0d1d86f
commit
a967a59145
BIN
homework_11
BIN
homework_11
Binary file not shown.
|
@ -91,17 +91,18 @@ void debug_head(struct Node* head){
|
|||
struct Node* previous=NULL;
|
||||
struct Node* current=head;
|
||||
|
||||
printf("start of address:");
|
||||
// printf("start of address:");
|
||||
while(current!=NULL){
|
||||
struct Node* next=xor_next(previous,current);
|
||||
struct SizedSubmask* mask=current->val;
|
||||
|
||||
printf("%zu ,",current);
|
||||
// printf("%zu ,",current);
|
||||
// fflush(stdout);
|
||||
|
||||
previous=current;
|
||||
current=next;
|
||||
}
|
||||
printf("\n");
|
||||
// printf("\n");
|
||||
}
|
||||
// int test()
|
||||
// {
|
||||
|
|
58
src/v3.c
58
src/v3.c
|
@ -33,17 +33,11 @@ struct Node* xor_remove_match(struct Node* head,void* target,bool (*eq)(void *,v
|
|||
else return head;
|
||||
}
|
||||
|
||||
bool xor_contain(struct Node* head,void* target,bool (*eq)(void *,void *)){
|
||||
bool xor_contain(struct Node* current,void* target,bool (*eq)(void *,void *)){
|
||||
struct Node* previous=NULL;
|
||||
struct Node* current=head;
|
||||
usize round=0;
|
||||
while(current!=NULL){
|
||||
// if(current<((usize)100000)) break;
|
||||
// printf("current: %zu, previous: %zu, round: %zu\n",current,previous, ++round);
|
||||
struct Node* next=xor_next(previous,current);
|
||||
if(eq(current->val,target)){
|
||||
return true;
|
||||
}
|
||||
if(eq(current->val,target))return true;
|
||||
previous=current;
|
||||
current=next;
|
||||
}
|
||||
|
@ -64,15 +58,16 @@ 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);
|
||||
|
||||
struct Node* new=xor_insert_mid(NULL,ll,ip);
|
||||
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++;
|
||||
}
|
||||
|
@ -99,7 +94,8 @@ void prefix_delete(struct State* state){
|
|||
if(reduce_submask(mask)){
|
||||
struct Node* ll=hash_pop(state->hashmap,mask);
|
||||
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);
|
||||
}else{
|
||||
struct Node* ll=state->head;
|
||||
struct Node* new_head=xor_remove_match(ll,ip,eq_v3);
|
||||
|
@ -109,6 +105,7 @@ void prefix_delete(struct State* state){
|
|||
|
||||
record_end("prefix_delete.csv")
|
||||
|
||||
|
||||
free(ip);
|
||||
}
|
||||
|
||||
|
@ -131,22 +128,49 @@ void search(struct State* state){
|
|||
|
||||
record_start
|
||||
|
||||
struct Node* ll;
|
||||
if(reduce_submask(mask))ll=hash_get(state->hashmap,mask);
|
||||
else ll=state->head;
|
||||
|
||||
if(reduce_submask(mask)){
|
||||
struct Node* ll=hash_pop(state->hashmap,mask);
|
||||
freq++;
|
||||
|
||||
record_end("search.csv")
|
||||
|
||||
debug_head(ll);
|
||||
fflush(stdout);
|
||||
|
||||
if (xor_contain(ll,ip,eq_v3)) printf("successful\n");
|
||||
else printf("failed\n");
|
||||
hash_insert(state->hashmap,mask,ll);
|
||||
}else{
|
||||
struct Node* ll=state->head;
|
||||
|
||||
free(ip);
|
||||
freq++;
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
if (xor_contain(ll,ip,eq_v3)) printf("successful\n");
|
||||
else printf("failed\n");
|
||||
free(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");
|
||||
|
||||
// free(ip);
|
||||
// free(mask);
|
||||
}
|
||||
|
||||
clock_end
|
||||
}
|
1365
trace_file.txt
1365
trace_file.txt
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue