3 static Node
*table
[4096];
8 static Node
*hash_number(cvs_number
*n
)
15 if (key
.c
> 2 && !key
.n
[key
.c
- 2]) {
16 key
.n
[key
.c
- 2] = key
.n
[key
.c
- 1];
21 for (i
= 0, hash
= 0; i
< key
.c
- 1; i
++)
23 hash
= (hash
* 256 + key
.n
[key
.c
- 1]) % 4096;
24 for (p
= table
[hash
]; p
; p
= p
->hash_next
) {
25 if (p
->number
.c
!= key
.c
)
27 for (i
= 0; i
< key
.c
&& p
->number
.n
[i
] == key
.n
[i
]; i
++)
32 p
= calloc(1, sizeof(Node
));
34 p
->hash_next
= table
[hash
];
40 static Node
*find_parent(cvs_number
*n
, int depth
)
48 for (i
= 0, hash
= 0; i
< key
.c
- 1; i
++)
50 hash
= (hash
* 256 + key
.n
[key
.c
- 1]) % 4096;
51 for (p
= table
[hash
]; p
; p
= p
->hash_next
) {
52 if (p
->number
.c
!= key
.c
)
54 for (i
= 0; i
< key
.c
&& p
->number
.n
[i
] == key
.n
[i
]; i
++)
62 void hash_version(cvs_version
*v
)
64 char name
[CVS_MAX_REV_LEN
];
65 v
->node
= hash_number(&v
->number
);
67 fprintf(stderr
, "more than one delta with number %s\n",
68 cvs_number_string(&v
->node
->number
, name
));
72 if (v
->node
->number
.c
& 1) {
73 fprintf(stderr
, "revision with odd depth (%s)\n",
74 cvs_number_string(&v
->node
->number
, name
));
78 void hash_patch(cvs_patch
*p
)
80 char name
[CVS_MAX_REV_LEN
];
81 p
->node
= hash_number(&p
->number
);
83 fprintf(stderr
, "more than one delta with number %s\n",
84 cvs_number_string(&p
->node
->number
, name
));
88 if (p
->node
->number
.c
& 1) {
89 fprintf(stderr
, "patch with odd depth (%s)\n",
90 cvs_number_string(&p
->node
->number
, name
));
94 void hash_branch(cvs_branch
*b
)
96 b
->node
= hash_number(&b
->number
);
102 for (i
= 0; i
< 4096; i
++) {
106 Node
*q
= p
->hash_next
;
115 static int compare(const void *a
, const void *b
)
117 Node
*x
= *(Node
* const *)a
, *y
= *(Node
* const *)b
;
124 for (i
= 0; i
< n
; i
++) {
125 if (x
->number
.n
[i
] < y
->number
.n
[i
])
127 if (x
->number
.n
[i
] > y
->number
.n
[i
])
133 static void try_pair(Node
*a
, Node
*b
)
138 if (n
== b
->number
.c
) {
144 for (i
= n
- 2; i
>= 0; i
--)
145 if (a
->number
.n
[i
] != b
->number
.n
[i
])
155 if ((b
->number
.c
& 1) == 0) {
157 /* can the code below ever be needed? */
158 Node
*p
= find_parent(&b
->number
, 1);
164 void build_branches(void)
166 Node
**v
= malloc(sizeof(Node
*) * entries
), **p
= v
;
169 for (i
= 0; i
< 4096; i
++) {
171 for (q
= table
[i
]; q
; q
= q
->hash_next
)
174 qsort(v
, entries
, sizeof(Node
*), compare
);
176 if (v
[entries
-1]->number
.c
== 2)
177 head_node
= v
[entries
-1];
178 for (p
= v
+ entries
- 2 ; p
>= v
; p
--)
179 try_pair(p
[0], p
[1]);
180 for (p
= v
+ entries
- 1 ; p
>= v
; p
--) {
181 Node
*a
= *p
, *b
= NULL
;
184 b
= find_parent(&a
->number
, 2);
186 char name
[CVS_MAX_REV_LEN
];
187 fprintf(stderr
, "no parent for %s\n",
188 cvs_number_string(&a
->number
, name
));