Exemple #1
0
        public void Build(StreamReader reader, String indexPath)
        {
            root = new BuildNode('\0', null);
            String line;
            int    count = 0;

            while ((line = reader.ReadLine()) != null)
            {
                line = line.Trim();
                if (IsValid(line))
                {
                    if (count % 1000 == 0)
                    {
                        Console.WriteLine(line);
                    }
                    Add(line);
                    count++;
                }
            }
            Console.WriteLine("Done, added " + count + " words, " + BuildNode.Count + " nodes");
            Console.WriteLine("GetCount() is " + root.GetCount(1));
            Deduplicate();
            Console.WriteLine("GetCount() is " + root.GetCount(2));
            AssignOffsets();
            Console.WriteLine("Offsets assigned");

            using (var indexFile = new FileStream(indexPath, FileMode.Create))
            {
                Console.WriteLine("Attempting to create index of size " + (Node.SIZE * nextOffset));
                using (var indexWriter = new BinaryWriter(indexFile, System.Text.Encoding.UTF32))
                {
                    WriteNode(root, indexWriter, 0);
                    indexWriter.Flush();
                }
            }
        }
Exemple #2
0
        internal int GetCount(int nextMark)
        {
            if (mark == nextMark)
            {
                return(0);
            }
            mark = nextMark;
            int       count = 1;
            BuildNode n     = FirstChild;

            while (n != null)
            {
                count += n.GetCount(mark);
                n      = n.NextSibling;
            }
            return(count);
        }