Exemple #1
0
        private static int DoPrint(PrintOptions opts)
        {
            var timer = Stopwatch.StartNew();

            timer.Restart();
            var terms = 0;

            using (var inputFile = new FileStorage(opts.InputFile))
            {
                using (var fst = new PersistentFST <int>(outputType, inputFile))
                {
                    var maxLength = fst.Header == null ? 1024 : fst.Header.MaxLength;
                    if (fst.Header != null)
                    {
                        PrintConsole(ConsoleColor.White, $"FST header terms: {fst.Header.TermCount}, max length: {fst.Header.MaxLength}, states: {fst.Header.States}");
                    }
                    foreach (var term in fst.Match(new WildcardMatcher(opts.Pattern, maxLength)))
                    {
                        if (!fst.TryMatch(term, out int value))
                        {
                            throw new Exception("This is a bug");
                        }

                        ++terms;
                        Console.WriteLine($"{term}->{value}");
                    }
                    PrintConsole(ConsoleColor.White, $"FST print terms: {terms}, time: {timer.Elapsed}");
                }
            }
            return(0);
        }
Exemple #2
0
        private static int DoPrint(PrintOptions opts)
        {
            var timer = Stopwatch.StartNew();

            var bytes    = File.ReadAllBytes(opts.InputFile);
            var fstBytes = bytes.Skip(7).ToArray();
            var fst      = default(FST <int>);

            if (bytes[6] == 'D')
            {
                fst = FST <int> .FromBytes(fstBytes, outputType);
            }
            else if (bytes[6] == 'C')
            {
                fst = FST <int> .FromBytesCompressed(fstBytes, outputType);
            }
            else
            {
                throw new NotSupportedException("FST format is not supported or input is not correct");
            }
            PrintConsole(ConsoleColor.White, $"FST read from: {opts.InputFile}, time: {timer.Elapsed}");

            timer.Restart();
            var terms = 0;

            foreach (var term in fst.Match(new WildcardMatcher(opts.Pattern, 255)))
            {
                if (!fst.TryMatch(term, out int value))
                {
                    throw new Exception("This is a bug");
                }

                ++terms;
                Console.WriteLine($"{term}->{value}");
            }
            PrintConsole(ConsoleColor.White, $"FST print terms: {terms}, time: {timer.Elapsed}");

            return(0);
        }