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,7 +7,7 @@
7 7
 #include "cmMallocDebug.h"
8 8
 #include "cmLex.h"
9 9
 #include "cmLinkedHeap.h"
10
-#include "cmSymTbl.h"
10
+#include "cmHashTbl.h"
11 11
 #include "cmCsv.h"
12 12
 #include "cmText.h"
13 13
 
@@ -48,9 +48,9 @@ typedef struct cmCsvUdef_str
48 48
 typedef struct
49 49
 {
50 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 54
   cmLHeapH_t         heapH;
55 55
   cmCsvBind_t*       bindPtr;      // base of the binder linked list
56 56
   cmCsvCell_t*       curRowPtr;    // used by the parser to track the row being filled
@@ -95,15 +95,15 @@ cmCsvRC_t cmCsvInitialize( cmCsvH_t *hp, cmCtx_t* ctx )
95 95
 
96 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 102
     goto errLabel;
103 103
   }
104 104
 
105 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 108
     rc = _cmCsvError(p,kMemAllocErrCsvRC,"Linked heap object allocation failed.");
109 109
     goto errLabel;
@@ -161,8 +161,8 @@ cmCsvRC_t cmCsvFinalize(   cmCsvH_t *hp )
161 161
   if((lexRC = cmLexFinal(&p->lexH)) != kOkLexRC )
162 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 167
   // free the handle
168 168
   cmMemPtrFree(&hp->h);
@@ -352,8 +352,8 @@ cmCsvRC_t _cmCsvCreateCell( cmCsv_t* p, const char* tokenText, unsigned flags, u
352 352
   cmCsvRC_t    rc     = kOkCsvRC;
353 353
 
354 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 358
   // allocate a cell
359 359
   if((rc = _cmCsvAllocCell(p,symId,flags,cellRow,cellCol,&cp,lexTId)) != kOkCsvRC )
@@ -561,8 +561,8 @@ const char* cmCsvCellSymText(   cmCsvH_t h, unsigned symId )
561 561
   cmCsv_t*    p = _cmCsvHandleToPtr(h);
562 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 567
   return cp;
568 568
 }
@@ -573,7 +573,7 @@ cmCsvRC_t   cmCsvCellSymInt(    cmCsvH_t h, unsigned symId, int* vp )
573 573
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
574 574
 
575 575
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
576
-    return kSymTblErrCsvRC;
576
+    return kHashTblErrCsvRC;
577 577
 
578 578
   if( cmTextToInt(cp,vp,&p->err) != kOkTxRC )
579 579
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to int value failed.");
@@ -587,7 +587,7 @@ cmCsvRC_t  cmCsvCellSymUInt(   cmCsvH_t h, unsigned symId, unsigned* vp )
587 587
   cmCsv_t*    p = _cmCsvHandleToPtr(h);
588 588
 
589 589
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
590
-    return kSymTblErrCsvRC;
590
+    return kHashTblErrCsvRC;
591 591
 
592 592
   if( cmTextToUInt(cp,vp,&p->err) != kOkTxRC )
593 593
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to uint value failed.");
@@ -601,7 +601,7 @@ cmCsvRC_t   cmCsvCellSymFloat(  cmCsvH_t h, unsigned symId, float* vp )
601 601
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
602 602
 
603 603
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
604
-    return kSymTblErrCsvRC;
604
+    return kHashTblErrCsvRC;
605 605
 
606 606
   if( cmTextToFloat(cp,vp,&p->err) != kOkTxRC )
607 607
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to float value failed.");
@@ -615,7 +615,7 @@ cmCsvRC_t    cmCsvCellSymDouble( cmCsvH_t h, unsigned symId, double* vp )
615 615
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
616 616
 
617 617
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
618
-    return kSymTblErrCsvRC;
618
+    return kHashTblErrCsvRC;
619 619
 
620 620
   if( cmTextToDouble(cp,vp,&p->err) != kOkTxRC )
621 621
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to double value failed.");
@@ -695,8 +695,8 @@ unsigned   cmCsvInsertSymText(   cmCsvH_t h, const char* text )
695 695
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
696 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 701
   return symId;
702 702
 }
@@ -1134,8 +1134,8 @@ cmCsvRC_t  cmCsvWrite( cmCsvH_t h, const char* fn )
1134 1134
       {
1135 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 1140
         if( cmIsFlag(cp->flags,kTextTMask) )
1141 1141
           fprintf(fp,"\"");
@@ -1179,8 +1179,8 @@ cmCsvRC_t  cmCsvPrint( cmCsvH_t h, unsigned rowCnt )
1179 1179
       {
1180 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 1185
         fputs(tp,stdin);
1186 1186
       }

+ 1
- 1
cmCsv.h View File

@@ -11,7 +11,7 @@ extern "C" {
11 11
     kOkCsvRC = 0,
12 12
     kMemAllocErrCsvRC,
13 13
     kLexErrCsvRC,
14
-    kSymTblErrCsvRC,
14
+    kHashTblErrCsvRC,
15 15
     kSyntaxErrCsvRC,
16 16
     kFileOpenErrCsvRC,
17 17
     kFileCreateErrCsvRC,

Loading…
Cancel
Save