update fst core struct
This commit is contained in:
		
							parent
							
								
									20203e47eb
								
							
						
					
					
						commit
						d39f80185f
					
				|  | @ -35,6 +35,7 @@ void fstCountingWriterDestroy(FstCountingWriter *w); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| void fstCountingWriterPackUintIn(FstCountingWriter *writer, uint64_t n,  uint8_t nBytes); | void fstCountingWriterPackUintIn(FstCountingWriter *writer, uint64_t n,  uint8_t nBytes); | ||||||
|  | uint8_t fstCountingWriterPackUint(FstCountingWriter *writer, uint64_t n); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| #define FST_WRITER_COUNT(writer) (writer->count) | #define FST_WRITER_COUNT(writer) (writer->count) | ||||||
|  |  | ||||||
|  | @ -21,9 +21,10 @@ static void fstPackDeltaIn(FstCountingWriter *wrt, CompiledAddr nodeAddr, Compil | ||||||
|   CompiledAddr deltaAddr = (transAddr == EMPTY_ADDRESS) ? EMPTY_ADDRESS : nodeAddr - transAddr; |   CompiledAddr deltaAddr = (transAddr == EMPTY_ADDRESS) ? EMPTY_ADDRESS : nodeAddr - transAddr; | ||||||
|   fstCountingWriterPackUintIn(wrt, deltaAddr, nBytes);  |   fstCountingWriterPackUintIn(wrt, deltaAddr, nBytes);  | ||||||
| } | } | ||||||
| static void fstPackDetla(FstCountingWriter *wrt, CompiledAddr nodeAddr, CompiledAddr transAddr) { | static uint8_t fstPackDetla(FstCountingWriter *wrt, CompiledAddr nodeAddr, CompiledAddr transAddr) { | ||||||
|   uint8_t nBytes = packDeltaSize(nodeAddr, transAddr); |   uint8_t nBytes = packDeltaSize(nodeAddr, transAddr); | ||||||
|   fstPackDeltaIn(wrt, nodeAddr, transAddr, nBytes);  |   fstPackDeltaIn(wrt, nodeAddr, transAddr, nBytes);  | ||||||
|  |   return nBytes; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| FstUnFinishedNodes *fstUnFinishedNodesCreate() { | FstUnFinishedNodes *fstUnFinishedNodesCreate() { | ||||||
|  | @ -213,8 +214,24 @@ void fstStateCompileForOneTransNext(FstCountingWriter *w, CompiledAddr addr, uin | ||||||
|   return; |   return; | ||||||
| } | } | ||||||
| void fstStateCompileForOneTrans(FstCountingWriter *w, CompiledAddr addr, FstTransition* trn) { | void fstStateCompileForOneTrans(FstCountingWriter *w, CompiledAddr addr, FstTransition* trn) { | ||||||
|   Output val = trn->out;    |   Output out = trn->out;    | ||||||
|  |   uint8_t outPackSize = (out == 0 ? 0 : fstCountingWriterPackUint(w, out));         | ||||||
|  |   uint8_t transPackSize = fstPackDetla(w, addr, trn->addr);       | ||||||
|  |   PackSizes packSizes = 0; | ||||||
| 
 | 
 | ||||||
|  |   FST_SET_OUTPUT_PACK_SIZE(packSizes, outPackSize); | ||||||
|  |   FST_SET_TRANSITION_PACK_SIZE(packSizes, transPackSize); | ||||||
|  |   fstCountingWriterWrite(w, (char *)&packSizes, sizeof(packSizes));  | ||||||
|  | 
 | ||||||
|  |   FstState st = fstStateCreate(OneTrans);  | ||||||
|  |    | ||||||
|  |   fstStateSetCommInput(&st, trn->inp); | ||||||
|  |   bool null = false; | ||||||
|  |   uint8_t inp = fstStateCommInput(&st, &null);    | ||||||
|  |   if (null == true) { | ||||||
|  |     fstCountingWriterWrite(w, (char *)&trn->inp, sizeof(trn->inp)); | ||||||
|  |   } | ||||||
|  |   fstCountingWriterWrite(w, (char *)(&(st.val)), sizeof(st.val)); | ||||||
|   return ; |   return ; | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | @ -267,7 +284,7 @@ void fstStateCompileForAnyTrans(FstCountingWriter *w, CompiledAddr addr, FstBuil | ||||||
|     // at that index. (Except when there are 256 transitions.) Namely,
 |     // at that index. (Except when there are 256 transitions.) Namely,
 | ||||||
|     // any value greater than or equal to the number of transitions in
 |     // any value greater than or equal to the number of transitions in
 | ||||||
|     // this node indicates an absent transition.
 |     // this node indicates an absent transition.
 | ||||||
|     uint8_t *index = malloc(sizeof(uint8_t) * 256);  |     uint8_t *index = (uint8_t *)malloc(sizeof(uint8_t) * 256);  | ||||||
|     for (uint8_t i = 0; i < 256; i++) { |     for (uint8_t i = 0; i < 256; i++) { | ||||||
|       index[i] = 255; |       index[i] = 255; | ||||||
|     } |     } | ||||||
|  | @ -277,6 +294,7 @@ void fstStateCompileForAnyTrans(FstCountingWriter *w, CompiledAddr addr, FstBuil | ||||||
|       fstCountingWriterWrite(w, (char *)index, sizeof(index));  |       fstCountingWriterWrite(w, (char *)index, sizeof(index));  | ||||||
|       //fstPackDeltaIn(w, addr, t->addr, tSize);
 |       //fstPackDeltaIn(w, addr, t->addr, tSize);
 | ||||||
|     } |     } | ||||||
|  |     free(index); | ||||||
|   } |   } | ||||||
|   fstCountingWriterWrite(w, (char *)&packSizes, 1); |   fstCountingWriterWrite(w, (char *)&packSizes, 1); | ||||||
|   bool null = false; |   bool null = false; | ||||||
|  |  | ||||||
|  | @ -13,6 +13,7 @@ | ||||||
|  * along with this program. If not, see <http://www.gnu.org/licenses/>.
 |  * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | ||||||
|  */ |  */ | ||||||
| #include "tutil.h" | #include "tutil.h" | ||||||
|  | #include "index_fst_util.h" | ||||||
| #include "index_fst_counting_writer.h" | #include "index_fst_counting_writer.h" | ||||||
| 
 | 
 | ||||||
| FstCountingWriter *fstCountingWriterCreate(void *wrt) { | FstCountingWriter *fstCountingWriterCreate(void *wrt) { | ||||||
|  | @ -42,7 +43,21 @@ int fstCountingWriterFlush(FstCountingWriter *write) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void fstCountingWriterPackUintIn(FstCountingWriter *writer, uint64_t n,  uint8_t nBytes) { | void fstCountingWriterPackUintIn(FstCountingWriter *writer, uint64_t n,  uint8_t nBytes) { | ||||||
|  |   assert(1 <= nBytes && nBytes <= 8); | ||||||
|  |   uint8_t *buf = calloc(8, sizeof(uint8_t));   | ||||||
|  |   for (uint8_t i = 0; i < nBytes; i++) { | ||||||
|  |     buf[i] = (uint8_t)n;  | ||||||
|  |     n = n >> 8; | ||||||
|  |   } | ||||||
|  |   fstCountingWriterWrite(writer, buf, nBytes); | ||||||
|  |   free(buf); | ||||||
|   return; |   return; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | uint8_t fstCountingWriterPackUint(FstCountingWriter *writer, uint64_t n) { | ||||||
|  |   uint8_t nBytes = packSize(n); | ||||||
|  |   fstCountingWriterPackUintIn(writer, n, nBytes); | ||||||
|  |   return nBytes;  | ||||||
|  | }  | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue