Esempio n. 1
0
File: Trie.cs Progetto: rejc2/utils
        public void WriteToFile(MyBinaryWriter writer, Action <MyBinaryWriter, T> writeData)
        {
            writer.Write7BitEncodedInt(m_Subtries.Count);
            foreach (KeyValuePair <char, Trie <T> > subtrie in m_Subtries)
            {
                writer.WriteUTF16(subtrie.Key);
                subtrie.Value.WriteToFile(writer, writeData);
            }

            writer.Write7BitEncodedInt(Items.Count);
            foreach (T item in Items)
            {
                writeData(writer, item);
            }
        }
Esempio n. 2
0
File: Trie.cs Progetto: rejc2/utils
        /// <summary>
        /// Where 8 or fewer different characters are used to make up the strings,
        /// we can write a more efficient kind of file.
        /// Falls back to normal file if there are more than 8 different
        /// characters used.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="writeData"></param>
        /// <remarks>Used for the stroke finder</remarks>
        public void WriteToMiniFile(MyBinaryWriter writer, Action <MyBinaryWriter, T> writeData)
        {
            var usedChars = new Set <char>();

            GetUsedChars(usedChars);
            if (usedChars.Count > 8)
            {
                writer.Write(string.Empty);
                WriteToFile(writer, writeData);
                return;
            }
            StringBuilder charIndexBuilder = new StringBuilder(usedChars.Count);

            foreach (char ch in usedChars)
            {
                charIndexBuilder.Append(ch);
            }
            string charIndex = charIndexBuilder.ToString();

            writer.Write(charIndex);

            WriteToMiniFile(charIndex, writer, writeData);
        }
Esempio n. 3
0
File: Trie.cs Progetto: rejc2/utils
        private void WriteToMiniFile(string charIndex, MyBinaryWriter writer, Action <MyBinaryWriter, T> writeData)
        {
            Debug.Assert(charIndex.Length <= 8);

            byte subTries = 0;

            for (int i = 0; i < charIndex.Length; i++)
            {
                if (m_Subtries.ContainsKey(charIndex[i]))
                {
                    subTries |= (byte)(1 << i);
                }
            }

            writer.Write(subTries);

            //writer.Write7BitEncodedInt(m_Subtries.Count);
            //foreach (KeyValuePair<char, Trie<T>> subtrie in m_Subtries)
            for (int i = 0; i < charIndex.Length; i++)
            {
                if ((subTries & (1 << i)) == 0)
                {
                    continue;
                }

                var subtrie = m_Subtries[charIndex[i]];

                //writer.WriteUTF16(subtrie.Key);
                subtrie.WriteToMiniFile(charIndex, writer, writeData);
            }

            writer.Write7BitEncodedInt(Items.Count);
            foreach (T item in Items)
            {
                writeData(writer, item);
            }
        }