-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst_update_tuple.c
64 lines (52 loc) · 1.44 KB
/
first_update_tuple.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//first_update_tuple.c tupleを更新する関数
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "main_canost.h"
// #define TEST_FIRST_UPDATE_TUPLE 1
extern int iatm;
extern int new_atm;
extern struct atom *a1st;
// chain : ひとつの層中の原子の配列
// length : 層中の原子の個数
int first_update_tuple( int *chain, int length, int lower ){
int i,j;
struct bond *bp;
// tupleの初期化
for(i=0;i<length;i++){
for(j=0 ; j < TUPLE_SIZE ; j++){
if( lower > 0 ){
a1st[ chain[i] ].tuple_child[j]=iatm+new_atm+1;
}else{
a1st[ chain[i] ].tuple_child[j]=0;
}
}
}
for(i=0 ; i < length ; i++){
for( bp = a1st[ chain[i] ].adj_list; bp != NULL ; bp=bp->next ){
if( a1st[ bp->alias ].layer == (a1st[ chain[i] ].layer+1) ){
// 挿入ソートにより子に関するtupleを更新
j=TUPLE_SIZE-1;
while( j >= 0 && a1st[ chain[i] ].tuple_child[j] == iatm+new_atm+1 ){
j--;
}
while( j >= 0 && ( a1st[ a1st[ chain[i] ].tuple_child[j] ].grade > a1st[ bp->alias ].grade) ){
a1st[ chain[i] ].tuple_child[ j+1 ]=a1st[ chain[i] ].tuple_child[j];
j--;
}
a1st[ chain[i] ].tuple_child[j+1]=bp->alias;
}
}
}
#ifdef TEST_FIRST_UPDATE_TUPLE
for(i=0;i<length;i++){
printf(" %3d ",chain[i]);
for(j=0; j < TUPLE_SIZE ; j++){
printf(" %3d ",a1st[ chain[i] ].tuple_child[j]);
}
printf("\n");
}
printf("\n");
#endif
return EXIT_SUCCESS;
}