private void dictLine(string line, bool cedict, BinWriter bw) { if (line == "" || line.StartsWith("#")) { return; } // Parse entry CedictEntry entry = parser.ParseEntry(line, 0, null); // Verify that simp, trad and pinyin are equal length if (entry != null) { if (entry.ChSimpl.Length != entry.ChTrad.Length || entry.ChSimpl.Length != entry.PinyinCount) { entry = null; } } // Just count if failed to parse if (entry == null) { if (cedict) { ++cedictDropped; } else { ++hddDropped; } return; } // Serialize int fpos = bw.Position; // First: hash chain: next entry in file with same hash. Will fill later. bw.WriteInt(0); // Then, entry itself entry.Serialize(bw); // Hash simplified and remember file position int hash = CedictEntry.Hash(entry.ChSimpl); List <int> poss; Dictionary <int, List <int> > hashPoss = cedict ? cedictHashPoss : hddHashPoss; if (!hashPoss.ContainsKey(hash)) { poss = new List <int>(); hashPoss[hash] = poss; } else { poss = hashPoss[hash]; } poss.Add(fpos); }
protected int indexEntry(CedictEntry entry) { MemoryStream ms = new MemoryStream(); BinWriter bw = new BinWriter(ms); entry.Serialize(bw); cmdInsBinaryEntry.Parameters["@data"].Value = ms.ToArray(); cmdInsBinaryEntry.ExecuteNonQuery(); int binId = (int)cmdInsBinaryEntry.LastInsertedId; // Index different parts of the entry indexHanzi(entry, binId); indexPinyin(entry, binId); return(binId); }