private SearchResult Convert(byte[] dict, WordIdx idx) { var buffer = dict.Skip(idx.DataOffset).Take(idx.DataSize).ToArray(); var result = new SearchResult { Word = idx.Word, Data = System.Text.Encoding.Default.GetString(buffer) }; return(result); }
public override int GetHashCode() { var hashCode = 1853776200; hashCode = hashCode * -1521134295 + WordDetailIdx.GetHashCode(); hashCode = hashCode * -1521134295 + WordIdx.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(WordParts); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(WordMeaning); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(WordPronounce); return(hashCode); }
public override int GetHashCode() { var hashCode = 1022877050; hashCode = hashCode * -1521134295 + LangIdx.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(LangName); hashCode = hashCode * -1521134295 + TestGroupIdx.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(TestGroupName); hashCode = hashCode * -1521134295 + TestIdx.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(TestName); hashCode = hashCode * -1521134295 + TestLevelIdx.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(TestLevelName); hashCode = hashCode * -1521134295 + WordIdx.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Word); hashCode = hashCode * -1521134295 + WordDupNo.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <List <ClassWordDetail> > .Default.GetHashCode(WordDetailList); return(hashCode); }
private async Task <Dictionary <string, WordIdx> > GetWordIdxMap(string path) { if (false == File.Exists(path)) { return(null); } var fIdx = File.ReadAllBytes(path); var buffer = new List <byte>(); var isWord = true; var isWordDataOffset = false; var currentWordDataOffset = 0; var isWordDataOffsetBytesCount = 0; var isWordDataSize = false; var currentWordDataSize = 0; var isWordDataSizeBytesCount = 0; var currentWord = ""; var isStop = false; var idxMap = new Dictionary <string, WordIdx>(); foreach (var item in fIdx) { if (item == 0 && isWord) { currentWord = Encoding.Default.GetString(buffer.ToArray()); isWord = false; isWordDataOffset = true; buffer.Clear(); } else if (isStop) { if (item != 0) { throw new Exception(); } isWordDataOffset = true; isStop = false; } else if (isWordDataOffset) { isWordDataOffsetBytesCount++; currentWordDataOffset = currentWordDataOffset * 256 + item; if (isWordDataOffsetBytesCount == DictIdx.IdxOffsetBits / 32) { isWordDataOffset = false; isWordDataSize = true; isWordDataOffsetBytesCount = 0; } } else if (isWordDataSize) { isWordDataSizeBytesCount++; currentWordDataSize = currentWordDataSize * 256 + item; if (isWordDataSizeBytesCount == DictIdx.IdxOffsetBits / 32) { isWordDataSize = false; isWord = true; isWordDataSizeBytesCount = 0; var wi = new WordIdx { Word = currentWord, DataOffset = currentWordDataOffset, DataSize = currentWordDataSize }; // System.Console.WriteLine(wi); if (idxMap.ContainsKey(currentWord) == false) { idxMap.Add(currentWord, wi); } currentWord = ""; currentWordDataOffset = 0; currentWordDataSize = 0; } } else { buffer.Add(item); } } return(await Task.FromResult(idxMap)); }