2 * stats.c - various routines to do stats on the key graph
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2000-2002 Project Purple
18 * initcolour - Clear the key graph ready for use.
19 * @parent: Do we want to clear the parent pointers too?
21 * Clears the parent and colour information on all elements in the key
24 void initcolour(bool parent)
30 * Init the colour/parent values. We get each entry list from the hash
31 * table and walk along it, zeroing the values.
33 for (loop = 0; loop < HASHSIZE; loop++) {
34 curkey = gethashtableentry(loop);
35 while (curkey != NULL) {
36 ((struct stats_key *)curkey->object)->colour = 0;
38 ((struct stats_key *)curkey->object)->parent =
41 curkey = curkey->next;
47 * findpath - Given 2 keys finds a path between them.
48 * @have: The key we have.
49 * @want: The key we want to get to.
51 * This does a breadth first search on the key tree, starting with the
52 * key we have. It returns as soon as a path is found or when we run out
53 * of keys; whichever comes sooner.
55 unsigned long findpath(struct stats_key *have, struct stats_key *want)
57 struct ll *keys = NULL;
58 struct ll *sigs = NULL;
59 struct ll *nextkeys = NULL;
64 keys = lladd(NULL, want);
66 while (keys != NULL && have->colour == 0) {
67 sigs = hash_getkeysigs(((struct stats_key *)
68 keys->object)->keyid);
69 while (sigs != NULL && have->colour == 0) {
71 * Check if we've seen this key before and if not mark
72 * it and add its sigs to the list we want to look at.
74 if (((struct stats_key *)sigs->object)->colour == 0) {
76 ((struct stats_key *)sigs->object)->colour =
78 ((struct stats_key *)sigs->object)->parent =
81 nextkeys = lladd(nextkeys, sigs->object);
91 fprintf(stderr, "Hash contains %ld keys.\n", hashelements());
97 struct stats_key *furthestkey(struct stats_key *have)
99 unsigned long count = 0;
100 unsigned long curdegree = 0;
101 struct ll *curll, *nextll, *tmp;
102 struct ll *sigs = NULL;
103 struct stats_key *max;
113 curll = lladd(NULL, have);
115 while (curll != NULL) {
116 sigs = hash_getkeysigs(((struct stats_key *)
117 curll->object)->keyid);
118 while (sigs != NULL) {
119 if (((struct stats_key *) sigs->object)->colour == 0) {
121 * We've never seen it. Count it, mark it and
122 * explore its subtree.
125 max = (struct stats_key *)sigs->object;
126 ((struct stats_key *)sigs->object)->colour =
128 ((struct stats_key *)sigs->object)->parent =
129 ((struct stats_key *)
130 curll->object)->keyid;
132 nextll=lladd(nextll, sigs->object);