Browse Source

cmCsv.h/c: CSV reader now uses a hash table rather than symbol table.

master
kevin 10 years ago
parent
commit
2cac6143ad
2 changed files with 25 additions and 25 deletions
  1. 24
    24
      cmCsv.c
  2. 1
    1
      cmCsv.h

+ 24
- 24
cmCsv.c View File

7
 #include "cmMallocDebug.h"
7
 #include "cmMallocDebug.h"
8
 #include "cmLex.h"
8
 #include "cmLex.h"
9
 #include "cmLinkedHeap.h"
9
 #include "cmLinkedHeap.h"
10
-#include "cmSymTbl.h"
10
+#include "cmHashTbl.h"
11
 #include "cmCsv.h"
11
 #include "cmCsv.h"
12
 #include "cmText.h"
12
 #include "cmText.h"
13
 
13
 
48
 typedef struct
48
 typedef struct
49
 {
49
 {
50
   cmErr_t            err;
50
   cmErr_t            err;
51
-  void*              rptDataPtr;     //
52
-  cmLexH             lexH;           // parsing lexer 
53
-  cmSymTblH_t        symTblH;        // all XML identifiers and data is stored as a symbol in this table
51
+  void*              rptDataPtr;   //
52
+  cmLexH             lexH;         // parsing lexer 
53
+  cmHashTblH_t       htH;          // hash table handle
54
   cmLHeapH_t         heapH;
54
   cmLHeapH_t         heapH;
55
   cmCsvBind_t*       bindPtr;      // base of the binder linked list
55
   cmCsvBind_t*       bindPtr;      // base of the binder linked list
56
   cmCsvCell_t*       curRowPtr;    // used by the parser to track the row being filled
56
   cmCsvCell_t*       curRowPtr;    // used by the parser to track the row being filled
95
 
95
 
96
   cmErrSetup(&p->err,&ctx->rpt,"CSV");
96
   cmErrSetup(&p->err,&ctx->rpt,"CSV");
97
 
97
 
98
-  // create the symbol table
99
-  if( cmSymTblIsValid(p->symTblH = cmSymTblCreate(cmSymTblNullHandle,0,ctx)) == false )
98
+  // create the hash table
99
+  if( cmHashTblCreate(ctx,&p->htH,8192) != kOkHtRC )
100
   {
100
   {
101
-    rc = _cmCsvError(p,kSymTblErrCsvRC,"Symbol table creation failed.");
101
+    rc = _cmCsvError(p,kHashTblErrCsvRC,"Hash table creation failed.");
102
     goto errLabel;
102
     goto errLabel;
103
   }
103
   }
104
 
104
 
105
   // allocate the linked heap mgr
105
   // allocate the linked heap mgr
106
-  if( cmLHeapIsValid(p->heapH = cmLHeapCreate(1024,ctx)) == false )
106
+  if( cmLHeapIsValid(p->heapH = cmLHeapCreate(8192,ctx)) == false )
107
   {
107
   {
108
     rc = _cmCsvError(p,kMemAllocErrCsvRC,"Linked heap object allocation failed.");
108
     rc = _cmCsvError(p,kMemAllocErrCsvRC,"Linked heap object allocation failed.");
109
     goto errLabel;
109
     goto errLabel;
161
   if((lexRC = cmLexFinal(&p->lexH)) != kOkLexRC )
161
   if((lexRC = cmLexFinal(&p->lexH)) != kOkLexRC )
162
     return _cmCsvError(p,kLexErrCsvRC,"Lexer finalization failed.\nLexer Error:%s",cmLexRcToMsg(lexRC));
162
     return _cmCsvError(p,kLexErrCsvRC,"Lexer finalization failed.\nLexer Error:%s",cmLexRcToMsg(lexRC));
163
 
163
 
164
-  // free the symbol table
165
-  cmSymTblDestroy(&p->symTblH);
164
+  // free the hash table
165
+  cmHashTblDestroy(&p->htH);
166
 
166
 
167
   // free the handle
167
   // free the handle
168
   cmMemPtrFree(&hp->h);
168
   cmMemPtrFree(&hp->h);
352
   cmCsvRC_t    rc     = kOkCsvRC;
352
   cmCsvRC_t    rc     = kOkCsvRC;
353
 
353
 
354
   // register the token text as a symbol
354
   // register the token text as a symbol
355
-  if((symId = cmSymTblRegisterSymbol(p->symTblH,tokenText)) == cmInvalidId )
356
-    return _cmCsvError(p,kSymTblErrCsvRC,"Symbol registration failed. for '%s' on line %i column %i.",tokenText,lexRow,lexCol);
355
+  if((symId = cmHashTblStoreStr(p->htH,tokenText)) == cmInvalidId )
356
+    return _cmCsvError(p,kHashTblErrCsvRC,"Symbol registration failed. for '%s' on line %i column %i.",tokenText,lexRow,lexCol);
357
 
357
 
358
   // allocate a cell
358
   // allocate a cell
359
   if((rc = _cmCsvAllocCell(p,symId,flags,cellRow,cellCol,&cp,lexTId)) != kOkCsvRC )
359
   if((rc = _cmCsvAllocCell(p,symId,flags,cellRow,cellCol,&cp,lexTId)) != kOkCsvRC )
561
   cmCsv_t*    p = _cmCsvHandleToPtr(h);
561
   cmCsv_t*    p = _cmCsvHandleToPtr(h);
562
   const char* cp;
562
   const char* cp;
563
 
563
 
564
-  if((cp =  cmSymTblLabel(p->symTblH,symId)) == NULL )
565
-    _cmCsvError(p,kSymTblErrCsvRC,"The text associated with the symbol '%i' was not found.",symId);
564
+  if((cp =  cmHashTblStr(p->htH,symId)) == NULL )
565
+    _cmCsvError(p,kHashTblErrCsvRC,"The text associated with the symbol '%i' was not found.",symId);
566
 
566
 
567
   return cp;
567
   return cp;
568
 }
568
 }
573
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
573
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
574
 
574
 
575
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
575
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
576
-    return kSymTblErrCsvRC;
576
+    return kHashTblErrCsvRC;
577
 
577
 
578
   if( cmTextToInt(cp,vp,&p->err) != kOkTxRC )
578
   if( cmTextToInt(cp,vp,&p->err) != kOkTxRC )
579
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to int value failed.");
579
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to int value failed.");
587
   cmCsv_t*    p = _cmCsvHandleToPtr(h);
587
   cmCsv_t*    p = _cmCsvHandleToPtr(h);
588
 
588
 
589
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
589
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
590
-    return kSymTblErrCsvRC;
590
+    return kHashTblErrCsvRC;
591
 
591
 
592
   if( cmTextToUInt(cp,vp,&p->err) != kOkTxRC )
592
   if( cmTextToUInt(cp,vp,&p->err) != kOkTxRC )
593
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to uint value failed.");
593
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to uint value failed.");
601
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
601
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
602
 
602
 
603
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
603
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
604
-    return kSymTblErrCsvRC;
604
+    return kHashTblErrCsvRC;
605
 
605
 
606
   if( cmTextToFloat(cp,vp,&p->err) != kOkTxRC )
606
   if( cmTextToFloat(cp,vp,&p->err) != kOkTxRC )
607
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to float value failed.");
607
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to float value failed.");
615
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
615
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
616
 
616
 
617
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
617
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
618
-    return kSymTblErrCsvRC;
618
+    return kHashTblErrCsvRC;
619
 
619
 
620
   if( cmTextToDouble(cp,vp,&p->err) != kOkTxRC )
620
   if( cmTextToDouble(cp,vp,&p->err) != kOkTxRC )
621
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to double value failed.");
621
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to double value failed.");
695
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
695
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
696
   unsigned    symId;
696
   unsigned    symId;
697
 
697
 
698
-  if((symId = cmSymTblRegisterSymbol(p->symTblH,text)) == cmInvalidId )
699
-    _cmCsvError(p,kSymTblErrCsvRC,"'%s' could not be inserted into the symbol table.",text);
698
+  if((symId = cmHashTblStoreStr(p->htH,text)) == cmInvalidId )
699
+    _cmCsvError(p,kHashTblErrCsvRC,"'%s' could not be inserted into the symbol table.",text);
700
 
700
 
701
   return symId;
701
   return symId;
702
 }
702
 }
1134
       {
1134
       {
1135
         const char* tp;
1135
         const char* tp;
1136
 
1136
 
1137
-        if((tp =  cmSymTblLabel(p->symTblH,cp->symId)) == NULL )
1138
-          return _cmCsvError(p,kSymTblErrCsvRC,"Unable to locate the symbol text for cell at row:%i col:%i.",cp->row,cp->col);
1137
+        if((tp = cmHashTblStr(p->htH,cp->symId)) == NULL )
1138
+          return _cmCsvError(p,kHashTblErrCsvRC,"Unable to locate the symbol text for cell at row:%i col:%i.",cp->row,cp->col);
1139
 
1139
 
1140
         if( cmIsFlag(cp->flags,kTextTMask) )
1140
         if( cmIsFlag(cp->flags,kTextTMask) )
1141
           fprintf(fp,"\"");
1141
           fprintf(fp,"\"");
1179
       {
1179
       {
1180
         const char* tp;
1180
         const char* tp;
1181
 
1181
 
1182
-        if((tp =  cmSymTblLabel(p->symTblH,cp->symId)) == NULL )
1183
-          _cmCsvError(p,kSymTblErrCsvRC,"The text associated with the symbol '%i' was not found.",cp->symId);
1182
+        if((tp =  cmHashTblStr(p->htH,cp->symId)) == NULL )
1183
+          _cmCsvError(p,kHashTblErrCsvRC,"The text associated with the symbol '%i' was not found.",cp->symId);
1184
 
1184
 
1185
         fputs(tp,stdin);
1185
         fputs(tp,stdin);
1186
       }
1186
       }

+ 1
- 1
cmCsv.h View File

11
     kOkCsvRC = 0,
11
     kOkCsvRC = 0,
12
     kMemAllocErrCsvRC,
12
     kMemAllocErrCsvRC,
13
     kLexErrCsvRC,
13
     kLexErrCsvRC,
14
-    kSymTblErrCsvRC,
14
+    kHashTblErrCsvRC,
15
     kSyntaxErrCsvRC,
15
     kSyntaxErrCsvRC,
16
     kFileOpenErrCsvRC,
16
     kFileOpenErrCsvRC,
17
     kFileCreateErrCsvRC,
17
     kFileCreateErrCsvRC,

Loading…
Cancel
Save