1/*******************************************************************************
2
3X-UIDL: 61064e07c8942a325fa988badcbf9ead
4X-Mozilla-Status: 0011
5X-Mozilla-Status2: 00000000
6Received: from smtp02.roc.gblx.net (smtp02.roc.gblx.net [209.130.222.197])
7	by smtp-local.globalcrossing.net (8.8.8a/8.8.8) with ESMTP id PAA109666
8	for <jerome@smtp-local.globalcrossing.net>; Sun, 23 Feb 2003 15:32:15 -0500
9Received: (from daemon@localhost)
10	by smtp02.roc.gblx.net (8.9.3/8.9.3) id PAA92782
11	for <jerome@globalcrossing.net>; Sun, 23 Feb 2003 15:32:15 -0500
12Received: from hermes.epita.fr(163.5.255.10), claiming to be "epita.fr"
13 via SMTP by smtp02.roc.gblx.net, id smtpdqr1CMa; Sun Feb 23 15:32:11 2003
14Received: from pipe.epita.fr (pipe [10.42.22.42])
15	by epita.fr id h1NKW0t08158 for <jerome@globalcrossing.net>
16	EPITA Paris France Sun, 23 Feb 2003 21:32:02 +0100 (MET)
17To: jerome@globalcrossing.net
18Subject: Re: Your hash lib
19From: Manu <emmanuel.alliel@epitech.net>
20Organization: arnac & Co
21URL: http://www.windar.fr.st
22Warning: PINE c'est mal (http://www.epita.fr:8000/~le-che_e/pine.html)
23X-Face: AUbo[a?<7\Ee:1%wJy4.iO+Y;%K2'Q[t?LbFjLY^vmDe%pQdH/{mA%ZxLam&N~6a?#35+gf
24 !{dm9Qf6UbZFr0,8w{7if~E__nBg!g^qW9V,+_kIRZqTj(K2$)C_)w[*c-ad1{k32#wqFE"{,gcNji
25 BX
26Date: Sun, 23 Feb 2003 21:32:01 +0100
27In-Reply-To: <3E57B341.6010909@globalcrossing.net> (Douglas Jerome's message
28 of "Sat, 22 Feb 2003 10:28:33 -0700")
29Message-ID: <87ssmuerb5q.fsf@epitech.net>
30User-Agent: Gnus/5.090016 (Oort Gnus v0.16) Emacs/21.2
31References: <87sn0kpy83w.fsf@epitech.net>
32	<3E564623.2060407@globalcrossing.net> <87sznopmx87.fsf@epitech.net>
33	<3E57B341.6010909@globalcrossing.net>
34MIME-Version: 1.0
35Content-Type: text/plain; charset=us-ascii
36X-UIDL: 61064e07c8942a325fa988badcbf9ead
37
38Hi,
39for my school I have to do a project using hash tables. The goal is to
40go as fast as posible. I tryed with your library, but it is slower
41than using perl or the glib.
42This is my code, maybe I am wrong somewhere:
43
44The subject is to do a program that reads on the stdin a string. For
45example if the string is:
46test 42
47the program put test and 42 on the hash table, and print:
48test 42
49and after if I print:
50test ?
51the program has to print:
52test 42
53
54--
55Manu - alliel_e@epitech.net
56uin 58000566
57Tek 2
58
59*******************************************************************************/
60
61
62/* ************************************************************************* */
63/*                                                                           */
64/*      Included Files                                                       */
65/*                                                                           */
66/* ************************************************************************* */
67
68#include	<stdio.h>
69#include	<unistd.h>
70#include	"libcsc.h"
71
72
73/* ************************************************************************* */
74/*                                                                           */
75/*      Executable Code - MAIN                                               */
76/*                                                                           */
77/* ************************************************************************* */
78
79int   main (void)
80   {
81   int                stat     = 0;
82   char*              hashName = "Hash Table";
83   CSCmemListType     memlist;
84   CSCtimerType       timer;
85   double             duration;
86   CSChashTableType   hashTable;
87   CSChashKeyUnion    key;
88   char*              inbuf;
89   char*              keyPtr;
90
91   memlist = CSCmemInit ("mem list", NULL, NULL, NULL, CSC_NO_PROFILING);
92   if (memlist == NULL)
93      {
94      (void)fprintf (stderr, "Can't create mem list.\n");
95      (void)exit (1);
96      }
97
98   timer = CSCtimerInit();
99   if (timer == NULL)
100      {
101      (void)fprintf (stderr, "Can't create new timer.\n");
102      (void)exit (1);
103      }
104
105   (void)printf ("=> Creating empty hash table ... ");
106   (void)fflush (stdout);
107   (void)CSCtimerMark (timer);
108   hashTable = CSChashNew (
109                          /* table name       */ hashName,
110                          /* key type         */ CSC_HASH_INT32_KEY,
111                          /* table size       */ 0,
112                          /* monitor function */ NULL,
113                          /* monitor data     */ NULL,
114                          /* profiling flag   */ CSC_NO_PROFILING
115                          );
116   (void)CSCtimerDiff (timer, &duration);
117   (void)printf ("done. [%9.6f seconds]\n", duration);
118   if (hashTable == NULL)
119      {
120      (void)fprintf (stderr, "Can't create new hash table \"%s\".\n", hashName);
121      (void)exit (1);
122      }
123
124   while (CSCioReadLine(STDIN_FILENO,&inbuf,memlist,0) > 0)
125      {
126      keyPtr = strchr (inbuf, ' ');
127      if (keyPtr != NULL)
128         {
129         *keyPtr++ = '\0';
130         key.integer = (int32)atoi (keyPtr);
131         if (inbuf[0] == '?')
132            {
133            char*    itemPtr;
134            size_t   itemSize;
135            (void)printf ("=> GET from the hash table ... ");
136            (void)fflush (stdout);
137            (void)CSCtimerMark (timer);
138            stat = CSChashEntryGet (
139                                   hashTable,
140                                   &key,
141                                   (void**)&itemPtr,
142                                   &itemSize,
143                                   NULL
144                                   );
145            (void)CSCtimerDiff (timer, &duration);
146            (void)printf ("done. [%9.6f seconds]\n", duration);
147            if (stat == 0)
148               {
149              (void)printf ("=> key,value = %d,\"%s\"\n", key.integer, itemPtr);
150              (void)free (itemPtr);
151               }
152            else
153               {
154               (void)printf (
155                          "=> No entry with key %d in hash table \"%s\": %s.\n",
156                          key.integer,
157                          hashName,
158                          CSCstatStr(stat)
159                            );
160               }
161            }
162         else
163            {
164            (void)printf ("=> PUT from the hash table ... ");
165            (void)fflush (stdout);
166            (void)CSCtimerMark (timer);
167            stat = CSChashEntryPut (hashTable, &key, inbuf, strlen(inbuf)+1);
168            (void)CSCtimerDiff (timer, &duration);
169            (void)printf ("done. [%9.6f seconds]\n", duration);
170            if (stat != 0)
171               {
172               (void)fprintf (
173                           stderr,
174                           "Can't add entry \"%s\" to hash table \"%s\": %s.\n",
175                           inbuf,
176                           hashName,
177                           CSCstatStr(stat)
178                             );
179               }
180            }
181         }
182      else
183         {
184         (void)printf ("=> Bad input, try again.\n");
185         }
186      (void)CSCmemFree (memlist, (void**)&inbuf, 0);
187      }
188
189   /*
190    * Remove the table.
191    */
192   (void)printf ("=> Deleting the hash table ... ");
193   (void)fflush (stdout);
194   (void)CSCtimerMark (timer);
195   stat = CSChashDel (hashTable);
196   (void)CSCtimerDiff (timer, &duration);
197   (void)printf ("done. [%9.6f seconds]\n", duration);
198   if (stat != 0)
199      {
200      (void)fprintf (
201                    stderr,
202                    "Can't delete hash table \"%s\": %s.\n",
203                    hashName,
204                    CSCstatStr(stat)
205                    );
206      }
207
208   /*
209    * All done.
210    */
211   (void)printf ("\nThanks for flying libcsc airlines.\n");
212   exit (0);
213   }
214
215
216/* End of file. */
217