2 * stats.c - various routines to do stats on the key graph
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2000-2002 Project Purple
17 * initcolour - Clear the key graph ready for use.
18 * @parent: Do we want to clear the parent pointers too?
20 * Clears the parent and colour information on all elements in the key
23 void initcolour(bool parent)
29 * Init the colour/parent values. We get each entry list from the hash
30 * table and walk along it, zeroing the values.
32 for (loop = 0; loop < HASHSIZE; loop++) {
33 curkey = gethashtableentry(loop);
34 while (curkey != NULL) {
35 ((struct stats_key *)curkey->object)->colour = 0;
37 ((struct stats_key *)curkey->object)->parent =
40 curkey = curkey->next;
46 * findpath - Given 2 keys finds a path between them.
47 * @have: The key we have.
48 * @want: The key we want to get to.
50 * This does a breadth first search on the key tree, starting with the
51 * key we have. It returns as soon as a path is found or when we run out
52 * of keys; whichever comes sooner.
54 unsigned long findpath(struct stats_key *have, struct stats_key *want)
56 struct ll *keys = NULL;
57 struct ll *sigs = NULL;
58 struct ll *nextkeys = NULL;
63 keys = lladd(NULL, want);
65 while (keys != NULL && have->colour == 0) {
66 sigs = hash_getkeysigs(((struct stats_key *)
67 keys->object)->keyid);
68 while (sigs != NULL && have->colour == 0) {
70 * Check if we've seen this key before and if not mark
71 * it and add its sigs to the list we want to look at.
73 if (((struct stats_key *)sigs->object)->colour == 0) {
75 ((struct stats_key *)sigs->object)->colour =
77 ((struct stats_key *)sigs->object)->parent =
80 nextkeys = lladd(nextkeys, sigs->object);
95 struct stats_key *furthestkey(struct stats_key *have)
97 unsigned long count = 0;
98 unsigned long curdegree = 0;
99 struct ll *curll, *nextll, *tmp;
100 struct ll *sigs = NULL;
101 struct stats_key *max;
111 curll = lladd(NULL, have);
113 while (curll != NULL) {
114 sigs = hash_getkeysigs(((struct stats_key *)
115 curll->object)->keyid);
116 while (sigs != NULL) {
117 if (((struct stats_key *) sigs->object)->colour == 0) {
119 * We've never seen it. Count it, mark it and
120 * explore its subtree.
123 max = (struct stats_key *)sigs->object;
124 ((struct stats_key *)sigs->object)->colour =
126 ((struct stats_key *)sigs->object)->parent =
127 ((struct stats_key *)
128 curll->object)->keyid;
130 nextll=lladd(nextll, sigs->object);