Repositories » libk0
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

The Post struct was renamed to KPost to avoid naming conflicts
elsewhere.

Changeset f0804ee3b290

Parent d19e9247ecd1

by Rup Palchowdhury

Changes to 3 files · Browse files at f0804ee3b290 Showing diff from parent d19e9247ecd1 Diff from another changeset...

Change 1 of 1 Show Entire File kpost.c Stacked
 
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
 
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
@@ -3,39 +3,39 @@
 #include <string.h>  #include "kpost.h"   -Post *newpost(char *s, int f) +KPost *newkpost(char *s, int f)  { - Post *t; - t = (Post *)malloc(sizeof(Post)); + KPost *t; + t = (KPost *)malloc(sizeof(KPost));   t->s = s;   t->f = f;   return t;  }   -int postcmp(void *t, void *t1) +int kpostcmp(void *t, void *t1)  { - return strcmp(((Post *)t)->s, ((Post *)t1)->s); + return strcmp(((KPost *)t)->s, ((KPost *)t1)->s);  }   -int post_match_handler(void *t, void *t1) +int kpost_match_handler(void *t, void *t1)  { - ((Post *)t)->f += ((Post *)t1)->f; + ((KPost *)t)->f += ((KPost *)t1)->f;   return 1;  }   -void freepost(void *t) +void freekpost(void *t)  {   free(t);  }   -void printpost(void *d, void *arg) +void printkpost(void *d, void *arg)  {   char *fmt;   fmt = (char *)arg; - printf(fmt, ((Post *)d)->s, ((Post *)d)->f); + printf(fmt, ((KPost *)d)->s, ((KPost *)d)->f);  }   -unsigned int hashpost(unsigned int (*fn)(char*, int), void *data, int modulo) +unsigned int hashkpost(unsigned int (*fn)(char*, int), void *data, int modulo)  { - return (*fn)(((Post *)data)->s, modulo); + return (*fn)(((KPost *)data)->s, modulo);  }
Change 1 of 1 Show Entire File kpost.h Stacked
 
1
 
2
3
 
4
5
6
7
8
9
10
11
12
13
 
 
 
 
 
 
 
 
1
2
 
3
4
5
6
7
 
 
 
 
 
 
8
9
10
11
12
13
@@ -1,13 +1,13 @@
-typedef struct Post Post; +typedef struct KPost KPost;   -struct Post { +struct KPost {   char *s;   int f;  };   -Post *newpost(char*, int); -int postcmp(void*, void*); -int post_match_handler(void*, void*); -void freepost(void*); -void printpost(void*, void*); -unsigned int hashpost(unsigned int (*fn)(char*, int), void*, int); +KPost *newkpost(char*, int); +int kpostcmp(void*, void*); +int kpost_match_handler(void*, void*); +void freekpost(void*); +void printkpost(void*, void*); +unsigned int hashkpost(unsigned int (*fn)(char*, int), void*, int);
Change 1 of 3 Show Entire File test.c Stacked
 
16
17
18
19
 
20
21
22
23
24
25
26
 
27
28
 
29
30
31
32
33
34
35
 
36
37
38
 
41
42
43
44
 
45
46
 
47
48
49
 
56
57
58
59
60
61
 
 
 
62
63
64
 
 
65
66
 
67
68
69
70
 
71
72
73
 
74
75
76
77
78
79
80
81
 
 
82
83
84
 
 
85
86
87
88
 
 
89
90
91
92
 
 
93
94
95
96
 
 
97
98
99
 
16
17
18
 
19
20
21
22
23
24
25
 
26
27
 
28
29
30
31
32
33
34
 
35
36
37
38
 
41
42
43
 
44
45
 
46
47
48
49
 
56
57
58
 
 
 
59
60
61
62
 
 
63
64
65
 
66
67
68
69
 
70
71
72
 
73
74
75
76
77
78
79
 
 
80
81
82
 
 
83
84
85
86
 
 
87
88
89
90
 
 
91
92
93
94
 
 
95
96
97
98
99
@@ -16,23 +16,23 @@
    int i, c;   Node *np; - Post *pp; + KPost *pp;     /* hash table test */     const int NHASH = 3;   Hash *h;   - h = newhash(NHASH, &postcmp, &hash); + h = newhash(NHASH, &kpostcmp, &hash);   for (i = 0; i < 6; i++) - np = hlookup(h, newnode(newpost(w[i], i)), 1); + np = hlookup(h, newnode(newkpost(w[i], i)), 1);   c = 0;   for (i = 0; i < NHASH; i++) {   if (h->tab[i] != NULL) {   c++;   printf("%-3d htab[%d]: ", c, i);   for (np = h->tab[i]; np != NULL; np = np->next) { - pp = (Post *)np->data; + pp = (KPost *)np->data;   printf("%s,%d ", pp->s, pp->f);   }   printf("\n"); @@ -41,9 +41,9 @@
    hstats(h, NHASH);   - np = hlookup(h, newnode(newpost(w[3], 0)), 0); + np = hlookup(h, newnode(newkpost(w[3], 0)), 0);   if (np != NULL) { - pp = (Post *)(np->data); + pp = (KPost *)(np->data);   printf("Found: %s %d\n", pp->s, pp->f);   }   else @@ -56,44 +56,44 @@
    t = NULL;   for (i = 0; i < NUMNODES; i++) - t = nrinsert(t, newtnode(newpost(s[i], 1)), - postcmp, post_match_handler); - found = tlookup(t, newtnode(newpost("h", 1)), postcmp); + t = nrinsert(t, newtnode(newkpost(s[i], 1)), + kpostcmp, kpost_match_handler); + found = tlookup(t, newtnode(newkpost("h", 1)), kpostcmp);   if (found != NULL) - printpost(found->data, "tlookup: %s %d\n"); - found = nrtlookup(t, newtnode(newpost("h", 1)), postcmp); + printkpost(found->data, "tlookup: %s %d\n"); + found = nrtlookup(t, newtnode(newkpost("h", 1)), kpostcmp);   if (found != NULL) - printpost(found->data, "nrtlookup: %s %d\n"); + printkpost(found->data, "nrtlookup: %s %d\n");       printf("inorder:\n"); - applyinorder(t, printpost, "%s %d\n"); + applyinorder(t, printkpost, "%s %d\n");   printf("\n");   printf("postorder:\n"); - applypostorder(t, printpost, "%s %d\n"); + applypostorder(t, printkpost, "%s %d\n");   */     /* list test */   /*   Node *lt, *n, *tmp;   - n = newnode((void *)newpost(s[1], 1)); - lt = newnode((void *)newpost(s[0], 0)); + n = newnode((void *)newkpost(s[1], 1)); + lt = newnode((void *)newkpost(s[0], 0));   for (i = 1; i < 3; i++) - lt = addfront(lt, newnode((void *)newpost(s[i], i))); - apply(lt, printpost, "%s %f\n"); + lt = addfront(lt, newnode((void *)newkpost(s[i], i))); + apply(lt, printkpost, "%s %f\n");   printf("\n");   - addend(lt, newnode((void *)newpost(s[3], 3))); - apply(lt, printpost, "%s %f\n"); + addend(lt, newnode((void *)newkpost(s[3], 3))); + apply(lt, printkpost, "%s %f\n");   printf("\n");   - tmp = lookup(lt, n, postcmp); - printpost(tmp->data, "%s %f\n"); + tmp = lookup(lt, n, kpostcmp); + printkpost(tmp->data, "%s %f\n");   printf("\n");   - delnode(lt, n, postcmp, freepost); - apply(lt, printpost, "%s %f\n"); + delnode(lt, n, kpostcmp, freekpost); + apply(lt, printkpost, "%s %f\n");   printf("\n");     freelist(lt, NULL);