Ejemplo n.º 1
0
            public void InsertAndExistsAndNotExists()
            {
                var words      = new[] { "Car", "Cat" };
                var strEncoder = Encoding.GetEncoding("iso-8859-1");

                var sut = new Tries <string>(10);

                for (int i = 0; i < words.Length; i++)
                {
                    var b = strEncoder.GetBytes(words[i]);
                    sut.Insert(b, words[i]);
                }

                for (int i = 0; i < words.Length; i++)
                {
                    var b     = strEncoder.GetBytes(words[i]);
                    var match = sut.Search(b);
                    Assert.True(match != null && match.CodeWord == words[i]);
                }

                var wordsNotExist = new[] { "car", "cat", "tac", "rac", "r", "ca", "catastrophe" };

                for (int i = 0; i < wordsNotExist.Length; i++)
                {
                    var b     = strEncoder.GetBytes(wordsNotExist[i]);
                    var match = sut.Search(b);
                    Assert.True(match == null);
                }
            }
Ejemplo n.º 2
0
        private void SubmitButton_Click_1(object sender, EventArgs e)
        {
            var _name         = ListName;
            var languageArray = WordList.LoadList(_name).Languages;
            var answer        = AnswerBox.Text.ToLower();

            AnswerBox.Text = string.Empty;

            if (answer == WordForPractice.Translations[WordForPractice.ToLanguage].ToLower())
            {
                Score++;
                Tries++;
            }
            else
            {
                var caption = "Wrong Answer";
                var message =
                    $"You answered wrong. Your answer was {answer} and the correct answer is {WordForPractice.Translations[WordForPractice.ToLanguage].ToLower()} ";
                var buttons = MessageBoxButtons.OK;
                MessageBox.Show(message, caption, buttons);
                Tries++;
                Fails++;
            }

            PracticeGenerator();
            PracticeWordBox.Text =
                $"Here is the {languageArray[WordForPractice.FromLanguage]} word {WordForPractice.Translations[WordForPractice.FromLanguage]}\r\n Please submit the {languageArray[WordForPractice.ToLanguage]} translation";
            ScoreAmount.Text = Score.ToString();
            FailAmount.Text  = Fails.ToString();
            TriesAmount.Text = Tries.ToString();
        }
Ejemplo n.º 3
0
 public void Init()
 {
     trie = new Tries();
     foreach (string word in words)
     {
         trie.AddWord(word);
     }
 }
Ejemplo n.º 4
0
 void Start()
 {
     temp2 = temp6 = 0;
     tries = new Tries(15, this);
     // 6 is the no. of minigames
     solved         = new Solved(15, this);
     _score         = 0;
     Time.timeScale = 0;
 }
Ejemplo n.º 5
0
        public override void StartGame()
        {
            IsWon     = false;
            IsRunning = true;

            Tries.Clear();
            enigmaFields = new EnigmaField[4];
            SetRandomColors();
            ResetTries();
        }
Ejemplo n.º 6
0
        private void GetAttempts()
        {
            var att      = AttemptsControl.Get(Type);
            var attempts = att.Where(x => x.IdQuestion == Id);

            foreach (var item in attempts)
            {
                Tries.Add(new DateTry(item.Score, item.When));
            }
        }
Ejemplo n.º 7
0
        public void Should_return_number_of_words_when_find_for_prefix()
        {
            var input   = new[] { "CAR", "CARD", "CARDAN", "TRY", "TRIES", "TRIED" };
            var printer = new FakePrinter("{0:#}");
            var tries   = new Tries();

            foreach (var s in input)
            {
                tries.Add(s);
            }

            var cCount = tries.Find("C");

            Assert.Equal(3, cCount);
            var carCount = tries.Find("CAR");

            Assert.Equal(3, carCount);
            var cardCount = tries.Find("CARD");

            Assert.Equal(2, cardCount);
            var cardanCount = tries.Find("CARDAN");

            Assert.Equal(1, cardanCount);

            var tCount = tries.Find("T");

            Assert.Equal(3, tCount);
            var trCount = tries.Find("TR");

            Assert.Equal(3, trCount);
            var tryCount = tries.Find("TRY");

            Assert.Equal(1, tryCount);
            var trieCount = tries.Find("TRIE");

            Assert.Equal(2, trieCount);
            var triesCount = tries.Find("TRIES");

            Assert.Equal(1, triesCount);
            var triedCount = tries.Find("TRIED");

            Assert.Equal(1, triedCount);

            var nCount = tries.Find("N");

            Assert.Equal(0, nCount);

            tries.Print(printer);

            foreach (var s in input)
            {
                Assert.Contains(s, printer.Printed);
            }
            Assert.Equal(6, printer.Printed.Count);
        }
Ejemplo n.º 8
0
        private void LoadChanceToAppear()
        {
            // peso 2
            var daysSince = LastTry != null?DateTime.Now.Subtract(LastTry.When).Days : 100;

            var lastTry_score = 0;

            if (daysSince < 20 && daysSince >= 1)
            {
                lastTry_score = daysSince / 2;
            }
            else if (daysSince == 0)
            {
                Chance         = 1;
                Chance_toolTip = "Question already completed today.";
                return;
            }
            else
            {
                lastTry_score = 20;
            }

            // peso 4
            var inv_avg = 40.0;

            if (daysSince <= 7)
            {
                inv_avg -= ((20 * Avg_week) / 100) + ((15 * Avg_month) / 100) + ((05 * Avg_all) / 100);
            }
            else if (daysSince <= 30)
            {
                inv_avg -= ((30 * Avg_month) / 100) + ((10 * Avg_all) / 100);
            }
            else if (daysSince <= 7)
            {
                inv_avg -= ((40 * Avg_all) / 100);
            }

            // peso 1
            var lastWasWrong = Tries != null && Tries.Any() ? (LastTry.Score == 100 ? 0 : 10) : 10;

            // peso 3
            var imp_score = ScoreHelper.GetScoreFromImportance(Importance) * 3;

            Chance = Math.Round(lastTry_score + inv_avg + lastWasWrong + imp_score, 2);

            Chance_toolTip = inv_avg + " (inv_avg) -> " + (daysSince <= 7 ? "avg_week (20%) + avg_month (15%) + avg_all (5%)" :
                                                           (daysSince <= 30 ? "avg_month (30%) + avg_all (10%)" :
                                                            "avg_all (40%) + ")) + "\n";
            Chance_toolTip += lastTry_score + " (lastTry) + " + lastWasWrong + " (lastWrong) + " + imp_score + " (imp)";
        }
Ejemplo n.º 9
0
            public void InsertAndCount()
            {
                var words      = new[] { "Car", "Cat", "Car", "Cat" };
                var strEncoder = Encoding.GetEncoding("iso-8859-1");

                var sut = new Tries <string>(10);

                for (int i = 0; i < words.Length; i++)
                {
                    var b = strEncoder.GetBytes(words[i]);
                    sut.Insert(b, words[i]);
                }

                Assert.True(sut.Count == words.Distinct().Count());
            }
Ejemplo n.º 10
0
        public void Should_construct_a_valid_tries_when_adding_strings()
        {
            var input   = new[] { "CAR", "CARD", "CARDAN" };
            var printer = new FakePrinter("{0:#}");
            var tries   = new Tries();

            foreach (var s in input)
            {
                tries.Add(s);
            }
            tries.Print(printer);
            Assert.Equal("CAR", printer.Printed[0]);
            Assert.Equal("CARD", printer.Printed[1]);
            Assert.Equal("CARDAN", printer.Printed[2]);

            Assert.Equal(3, printer.Printed.Count);
        }
Ejemplo n.º 11
0
        public async Task <ActionResult> GetTrieAsync()
        {
            var client  = new Client();
            var players = await client.GetAll();

            Tries t = new Tries();

            t.CreateRoot();
            foreach (var player in players)
            {
                var fullName = player.player.FirstName + player.player.LastName;
                t.Add(fullName.ToCharArray(), player);
            }


            var player1 = t.FindPlayer("LebronJames".ToCharArray());

            return(View(player1.player));
        }
Ejemplo n.º 12
0
 public double GetAverageScoreByTime(int lastDays)
 {
     if (!Tries.Any())
     {
         return(0);
     }
     else
     {
         var filtered = Tries.Where(x => x.When >= (DateTime.Now.AddDays(-lastDays)));
         if (filtered.Any())
         {
             return(filtered.Average(x => x.Score) * 10);
         }
         else
         {
             return(0);
         }
     }
 }
Ejemplo n.º 13
0
    public void AddWord(string word)
    {
        var cA = word.ToCharArray();
        var cT = t;
        var pT = t;

        foreach (var c in cA)
        {
            if (cT == null)
            {
                cT = new Tries[26];
            }

            if (cT[(int)(c - 'a')] == null)
            {
                cT[(int)(c - 'a')] = new Tries(c);
            }

            pT = cT;
            cT = cT[(int)(c - 'a')].Next;
        }

        pT[(int)(cA[cA.Length - 1] - 'a')].SetLast(true);
    }
Ejemplo n.º 14
0
        public EnigmaGuessResult GuessColors(EnigmaColor[] colors)
        {
            CheckRunningGame();
            var guessResult = new EnigmaGuessResult();

            if (colors == null || colors.Length != enigmaFields.Length)
            {
                throw new ArgumentException($"Input must be of size {enigmaFields.Length}");
            }

            for (var i = 0; i < enigmaFields.Length; i++)
            {
                guessResult.tries[i] = new EnigmaField(colors[i], enigmaFields[i].Guess(colors[i]));
            }

            Tries.Add(guessResult);

            if (AllColorsGuessed())
            {
                IsRunning = false;
                IsWon     = true;
            }
            else
            {
                CurrentNumberOfTries -= 1;

                if (CurrentNumberOfTries >= 1)
                {
                    return(guessResult);
                }
                IsRunning = false;
                IsWon     = false;
            }

            return(guessResult);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Decodes compressed bytes
        /// </summary>
        /// <param name="codes">Compressed bytes</param>
        /// <param name="nodeInitialCapacity">Node table initial size</param>
        /// <returns>Decompressed data</returns>
        public static byte[] AsLZDecodedUsingTrie(this byte[] codes, int nodeInitialCapacity)
        {
            var decoderDic = new Tries <byte[]>(nodeInitialCapacity);

            return(_asLZDecoded(codes, decoderDic));
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            Arrays arrObj = new Arrays();
            // arrObj.PartitionStringWithUniqueChars();
            // arrObj.MoveZerosAtEnd();
            //arrObj.QueueReconstructionByHeight();
            //arrObj.WallsGates();
            // arrObj.FindMissingInSortedArray();
            // arrObj.GameOfLife();                             //** To Be Completed **
            // arrObj.MaxDistanceOfWaterFromLand();
            // arrObj.WaysToEncode();
            // arrObj.Sort2dArray();                            //** To Be Completed **
            // arrObj.FindOnesInRange();
            // arrObj.DecodeWays();
            // arrObj.MostStonesRemoved();
            // arrObj.DailyTemperatures();
            // arrObj.RemoveStones();
            // arrObj.FindFirstLastPosInArray();
            // arrObj.DailyTemperatures();
            // arrObj.FindInMountainArray();
            // arrObj.MinChairs();
            // arrObj.LongestSubsequenceOfGivenDifference();
            // arrObj.QueensAttackKing();
            // arrObj.OptimalUtilization();
            // arrObj.MaxSquareSumInMatrix();                   //** To be Completed */
            // arrObj.HasCircularLoop();
            // arrObj.RemoveKDigits();
            // arrObj.CheckMountainArray();
            // arrObj.TestHeap();
            // arrObj.SubArraySumK();
            // arrObj.JumpingOnClouds();
            // arrObj.FindPeakElement();
            // arrObj.NoOfBurgers();
            // arrObj.InterleaveFirstHalfWithReversed();
            // arrObj.RotateImage();
            // arrObj.NextPermutation();                      // Revisit
            // arrObj.NonOverlapingIntervals();
            // arrObj.AsteroidCollision();
            // arrObj.RemoveInvalidParanthesis();
            // arrObj.SearchInRotatedSortedArray();
            // arrObj.NextGreaterNumber();
            // arrObj.MedianFromStream();
            // arrObj.MaxConsecutiveOnes();
            // arrObj.MinimumSemesters();
            // arrObj.GCD();
            // arrObj.Permutations();
            //arrObj.ShortestSubArrayWithSumAtleastK();
            // arrObj.TaskScheduler();                              //*Tricky */
            // arrObj.ThreeSum();
            // arrObj.NumberOfCornerRectangle();
            // arrObj.ValidTicTacToe();
            // arrObj.MinMeetingRoomsII();
            // arrObj.MergeIntervals();
            // arrObj.FindIslands();
            // arrObj.InsertInterval();
            // arrObj.SplitLargestSum();
            // arrObj.MinSubArrayLen();
            // arrObj.FirstMissingInSortedArray();
            // arrObj.GetLengthOfOptimalCompression();
            // arrObj.AngleClock();
            // arrObj.TopKFrequent();
            // arrObj.KthLargest();
            // arrObj.MinCostForDeletionToAvoidRepetition();
            // arrObj.FindLengthOfShortestSubarray();
            // arrObj.PossibleBipartition();
            // arrObj.FriendCircles();
            // arrObj.FurthestBuilding();
            // arrObj.FindNumFromSortedArray();
            // arrObj.LetterCombinationsOfPhoneNumber();
            // arrObj.GetPermutation();
            // arrObj.CanReach();
            // arrObj.MinTeachings();
            // arrObj.ShipWithinDays();
            // arrObj.FirstMissingPositive();
            // arrObj.LeftMostColumnWithOne();
            // arrObj.GenerateMatrix();
            // arrObj.LargestIsLand();
            // arrObj.MaxArea();
            // arrObj.IsAlienSorted();
            // arrObj.SortColors();
            //arrObj.CombinationSum();
            // arrObj.CombinationSumII();
            // arrObj.MaxSumTwoNoOverlap();
            // arrObj.MinDeletionSize();
            // arrObj.Subsets();
            // arrObj.SubsetsWithDuplicates();
            // arrObj.LongestIncreasingPath();
            // arrObj.ExclusiveTime();
            // arrObj.FindMedianSortedArrays();
            // arrObj.FriendsOfAppropriateAge();
            // arrObj.FindKthMissingPositive();
            // arrObj.ShortestDistanceFromAllBuildings();
            // arrObj.BestMeetingPoint();
            //arrObj.SearchRange();
            //arrObj.MinSubArraySum();
            // arrObj.MinRotatedSortedArray();
            // arrObj.CombinationSumIV();
            //arrObj.ExpressionAddOperators();                          //TBD: Failing test case
            // arrObj.ThreeSumClosest();                                //TBD
            // arrObj.CountingTriangles();
            // arrObj.CanPartitionKSubsets();
            //arrObj.FindDuplicates();
            // arrObj.MinShuffleToArrange();
            // arrObj.SortArrayWithKPositionDisplaced();
            // arrObj.SolveSudoku();
            // arrObj.OrangesRotting();
            // arrObj.SimplifyPath();
            // arrObj.FindElementInSortedUnboundArray();
            // arrObj.CanMeasureWater();
            // arrObj.PainterPartition();                                  //TBD
            // arrObj.RandomNumber();
            // arrObj.MinAvailableDuration();
            // arrObj.LargestRectangleArea();
            // arrObj.MaximalRectangle();
            // arrObj.FlightCost();
            // arrObj.SlidingWindowMedian();
            // arrObj.PermuteUnique();
            // arrObj.MinimumEffortPath();
            // arrObj.PaintHouseII();
            // arrObj.PaintHouse();
            // arrObj.RemoveCoveredIntervals();

            Trees treeObj = new Trees();
            //treeObj.BalanceTreeNodeValues();
            //treeObj.CheckEqualTree();
            // treeObj.ConstructBinaryTreeFromInAndPreorder();
            //treeObj.VerifyPreOrderSerialization();
            //treeObj.ConstructBSTFromPreOrder();
            // treeObj.SumOfLeftLeaves();
            // treeObj.NextGreater();
            // treeObj.IsValidBST();
            // treeObj.KDistanceBinaryTree(); //Brilliant Sol
            // treeObj.IterateBST();
            // treeObj.ConstructBinaryTreeFromString();
            // treeObj.FlattenTree();
            // treeObj.MinDepth();
            // treeObj.DistributeCoins(); // Brilliant Sol
            // treeObj.BinaryTreeUpsideDown();
            // treeObj.FillNodesWithEqualValues();
            // treeObj.BoundaryOfTree();
            // treeObj.FloorCeiling();
            // treeObj.FindRightNeighbor();
            // treeObj.SubTreeWithDeepestNodes();
            // treeObj.MaximumBinaryTree();
            // treeObj.VerticalOrder();
            // treeObj.PopulateNextRightPointers();
            // treeObj.MaxLevelSum();
            // treeObj.BSTFromPreOrder();
            // treeObj.HeightBalanced();
            // treeObj.RightSibling();
            // treeObj.ReplaceElementByItsRank();
            // treeObj.Serialize();
            // treeObj.ConstructBSTFromPostOrderSequence();
            // treeObj.AllElementsOfBST();
            // treeObj.EvenValuedGrandParent();
            // treeObj.DeleteLeavesWithGivenValue();
            // treeObj.FindMaxNInBST();
            // treeObj.MaxProductOfSplittedBinaryTree();
            // treeObj.BstToDoubleLinkedList();
            // treeObj.FlattenBinaryTreeToSLL();
            // treeObj.LevelOrderTraversal();
            // treeObj.ConstructBSTFromPreInorder();
            // treeObj.DeleteNodes();
            // treeObj.ValidateBST();
            // treeObj.DeleteNode();
            // treeObj.LongestZigZagPathInBinaryTree();
            // treeObj.PopulateNextPointers();
            // treeObj.ConstructBinaryTreeFromPreAndPostOrder();
            // treeObj.RangeSumBST();
            // treeObj.BinaryTreeRightSideView();
            // treeObj.BinaryTreeBoundary();
            // treeObj.KthSmallestInBst();
            // treeObj.GoodNodes();
            // treeObj.LargestValues();
            // treeObj.CountSmallNumbersAfterSelf();
            // treeObj.MinDiffInBST();
            // treeObj.FindNearestRightNode();
            // treeObj.MostFrequentElementInBST();
            // treeObj.MaximumAverageSubTree();
            // treeObj.MaxSumBST();
            // treeObj.BalanceBST();
            // treeObj.RecoverTree();
            // treeObj.CorrectBinaryTree();
            // treeObj.MaxAncestorDiff();
            // treeObj.LCADeepestLeaves();
            // treeObj.HouseRobberIII();
            // treeObj.LongestZigZag();
            // treeObj.CountSmallerNumbersAfterSelf();
            // treeObj.FindDuplicateSubTrees();
            // treeObj.BalanceBSTCre();
            // treeObj.RightSideView();
            // treeObj.Str2tree();
            // treeObj.LCAIII();
            // treeObj.CountNodes();
            // treeObj.LargestBSTSubtree();
            // treeObj.BinaryTreeFromInorderPostOrder();
            // treeObj.DeleteNodeReturnForest();
            // treeObj.MaxPathSum();
            // treeObj.BSTSumEqualsK();
            // treeObj.TrimBST();

            DP dpObj = new DP();
            // dpObj.FindPalindromeSubstrings();
            // dpObj.PartitionKSubsetsMatchingSum();
            // dpObj.WordBreak();
            // dpObj.MinCostToMergeStones();
            // dpObj.FindRectangleCoordinates();
            // dpObj.PoisonousPlants();
            // dpObj.WordBreakII();
            // dpObj.BuySellWithCoolDown();
            // dpObj.BuySellStockII();
            // dpObj.BuySellStockIII();
            // dpObj.CountSquareMatrices();
            // dpObj.SplitIntoPalindromes(); // Brilliant Sol
            // dpObj.MinInsertionStepsToPalindrome();
            // dpObj.MinModificationsToReachEnd();
            // dpObj.MinPathSum();
            // dpObj.NthFibonacci();
            // dpObj.BuySellStock();
            // dpObj.MinSubsetDifference();                       // ** Revisit test case
            // dpObj.KSubsequences();
            // dpObj.DeleteOperationForTwoStrings();
            // dpObj.LongestConsecutiveSequence();
            // dpObj.MinCostToClimbStairs();
            // dpObj.RegexMatch();
            // dpObj.WildCardMatch();
            // dpObj.PascalTriangle();
            // dpObj.BuySellStockIV();
            // dpObj.LongestIncreasingSubsequence();
            // dpObj.LargestNumber();                             // ** Very tricky
            // dpObj.MinCostForMovie();
            // dpObj.KnightDialer();
            // dpObj.EggDrop();
            // dpObj.CombinationSumIV();
            // dpObj.LongestPalindromicSubstring();
            // dpObj.ShortestCommonSuperSequence();

            Graph gObj = new Graph();
            // gObj.BiPartition();
            //gObj.CourseScheduling();
            //gObj.MinCostToConnectNodes();
            // gObj.ValidGraphTree();
            // gObj.CriticalConnections();
            // gObj.AlienDictionary();
            // gObj.AccountsMerge();
            // gObj.TreeDiameter();
            // gObj.CloneGraph();
            // gObj.ReconstructItinerary();
            // gObj.CanFinishCourses();
            // gObj.CourseSchedule();
            // gObj.DisjointSets();
            // gObj.FindCheapestPrice();
            // gObj.RedundantConnection();
            // gObj.CloneGraphCre();
            // gObj.IsBipartite();
            // gObj.CourseScheduleII();

            Strings sObj = new Strings();
            //sObj.StrStr();
            // sObj.SwapForLongestRepeatedChar();
            // sObj.WordBreak();
            // sObj.checkPangram();
            // sObj.DecodeString();
            // sObj.LongestSubstringKDistinctChars();
            // sObj.IsPalindrome();
            // sObj.ReorderLogFiles();                            // ** Fails Leetcode test case
            // sObj.MinWindowsSubstring();
            // sObj.MakeAnagram();
            // sObj.SameCharacterFrequency();
            // sObj.LongestWordInDictionary();
            // sobj.SubstringsNotMatchingAlphabets();               //** TBD
            // sObj.FindAnagrams();
            // sObj.LongestValidParantheses();
            // sObj.StringTransformation();
            // sObj.ShortestPalindrome();
            // sObj.ConstructKPalindromeStrings();
            // sObj.CanPermutePalindrome();
            // sObj.LetterCombinations();
            // sObj.BackspaceCompare();
            // sObj.VerifyAlienDictionary();
            // sObj.ValidPalindromeII();
            // sObj.RemoveAdjacentDuplicates();                     //** Elegant & Consise
            // sObj.ValidPalindromeIII();
            // sObj.FaultyKeyBoard();
            // sObj.FindAllAnagrams();
            // sObj.LongestSubstringWithoutRepeatingChars();
            // sObj.NumberOfSubstringWithOnly1s();
            // sObj.ParseBoolExpr();
            // sObj.NumMatchingSubSeq();                              //** Tricky
            // sObj.RepeatedSubstringPattern();
            // sObj.LongestSubstringWithKRepeatingChars();
            // sObj.AreSentencesSimilar();
            // sObj.WordSearch();
            // sObj.WordSearchII();
            // sObj.ReverseString();
            // sObj.FindAnagramIndices();
            // sObj.AddBinary();
            // sObj.GroupAnagrams();
            // sObj.MinRemoveToMakeValid();
            // sObj.PalindromePartition();                            //TBD
            // sObj.GroupStrings();                                   //Fails LC test case
            // sObj.FindConcatenationOfWords();
            // sObj.MinStickers();                                    // TBD
            // sObj.ShortestPalindrome();

            LinkedList lObj = new LinkedList();
            // lObj.SwapAlternatePairs();
            // lObj.RemoveZeroSumNodes();
            // lObj.ReverseSLL();
            // lObj.PlusOne();
            // lObj.MinCostToMergeStones();
            // lObj.CloneList();
            // lObj.FlattenList();
            // lObj.GetIntersectionNode();
            // lObj.ReverseKGroup();
            // lObj.MergeKSortedList();
            // lObj.RemoveKthNode();
            // lObj.IsPalindrome();                                        // TBD

            // ThreadedQueue thObj = new ThreadedQueue();
            SynchronizedStockMarket syncObj = new SynchronizedStockMarket();
            // syncObj.SimulateThreads();

            Recursion rObj = new Recursion();
            // rObj.ExpressionAddOperators();                      //** To Be Completed **
            // rObj.LetterCombinations();
            // rObj.MaxRegion();
            // rObj.JumpGameIII();
            // rObj.KthLargest();
            // rObj.WordBoggle();
            // rObj.CanFinishCourse();

            Stacks stObj = new Stacks();

            //stObj.ValidateStackSequences();
            stObj.FrequencyStack();

            TicTacToe tObj = new TicTacToe();
            // tObj.MakeMoves();

            Tries trieObj = new Tries();
            // trieObj.AutoSuggest();
            // trieObj.LongestDuplicateSubstring();
        }
Ejemplo n.º 17
0
 public Contacts(IPrint printer)
 {
     _printer  = printer;
     _contacts = new Tries();
 }
        /// <summary>
        /// Encodes bytes using LZ and trie as dictionary
        /// </summary>
        /// <param name="input">Byte array</param>
        /// <param name="nodeInitialCapacity">Node table initial size</param>
        /// <returns></returns>
        public static byte[] BytesAsLZEncodedUsingTrie(this byte[] input, int nodeInitialCapacity)
        {
            var encoderDic = new Tries <int>(nodeInitialCapacity);

            return(_asLZEncoded(input, encoderDic));
        }
        internal void Evaluate(ProcessArgumentBuilder arguments)
        {
            if (Help)
            {
                arguments.Append(this.GetArgumentName(nameof(Help)));
            }

            if (Version)
            {
                arguments.Append(this.GetArgumentName(nameof(Version)));
            }

            if (Url != default)
            {
                arguments.Append(Url.AbsoluteUri);
            }

            if (!string.IsNullOrWhiteSpace(OutputDocument))
            {
                arguments.AppendSwitchQuoted(this.GetArgumentName(nameof(OutputDocument)), SwitchSeparator, OutputDocument);
            }

            if (!string.IsNullOrWhiteSpace(OutputFile))
            {
                arguments.AppendSwitchQuoted(this.GetArgumentName(nameof(OutputFile)), SwitchSeparator, OutputFile);
            }

            if (!string.IsNullOrWhiteSpace(AppendOutput))
            {
                arguments.AppendSwitchQuoted(this.GetArgumentName(nameof(AppendOutput)), SwitchSeparator, AppendOutput);
            }

            if (Quiet)
            {
                arguments.Append(this.GetArgumentName(nameof(Quiet)));
            }

            if (Debug)
            {
                arguments.Append(this.GetArgumentName(nameof(Debug)));
            }

            if (Verbose)
            {
                arguments.Append(this.GetArgumentName(nameof(Verbose)));
            }

            if (NoVerbose)
            {
                arguments.Append(this.GetArgumentName(nameof(NoVerbose)));
            }

            if (!string.IsNullOrWhiteSpace(InputFile))
            {
                arguments.AppendSwitchQuoted(this.GetArgumentName(nameof(InputFile)), SwitchSeparator, InputFile);
            }

            if (ForceHtml)
            {
                arguments.Append(this.GetArgumentName(nameof(ForceHtml)));
            }

            if (!string.IsNullOrWhiteSpace(Base))
            {
                arguments.AppendSwitchQuoted(this.GetArgumentName(nameof(Base)), SwitchSeparator, Base);
            }

            if (!string.IsNullOrWhiteSpace(RejectedLog))
            {
                arguments.AppendSwitchQuoted(this.GetArgumentName(nameof(RejectedLog)), SwitchSeparator, RejectedLog);
            }

            if (Tries != default)
            {
                arguments.AppendSwitch(this.GetArgumentName(nameof(Tries)), SwitchSeparator, Tries.ToString());
            }

            if (!string.IsNullOrWhiteSpace(DirectoryPrefix))
            {
                arguments.AppendSwitchQuoted(this.GetArgumentName(nameof(DirectoryPrefix)), SwitchSeparator, DirectoryPrefix);
            }

            if (LimitRate != null && LimitRate.Value > 0.0)
            {
                arguments.AppendSwitch(
                    this.GetArgumentName(nameof(LimitRate)),
                    SwitchSeparator,
                    LimitRate.GetFormattedLimitRateValue());
            }

            if (RetryConnectionRefused)
            {
                arguments.Append(this.GetArgumentName(nameof(RetryConnectionRefused)));
            }

            if (Recursive)
            {
                arguments.Append(this.GetArgumentName(nameof(Recursive)));
            }

            if (Level != default)
            {
                arguments.AppendSwitch(this.GetArgumentName(nameof(Level)), SwitchSeparator, Level.ToString());
            }

            if (Wait.HasValue)
            {
                arguments.AppendSwitch(
                    this.GetArgumentName(nameof(Wait)),
                    SwitchSeparator,
                    Wait.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
            }

            if (WaitRetry.HasValue)
            {
                arguments.AppendSwitch(
                    this.GetArgumentName(nameof(WaitRetry)),
                    SwitchSeparator,
                    WaitRetry.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
            }

            if (RandomWait)
            {
                arguments.Append(this.GetArgumentName(nameof(RandomWait)));
            }

            if (!string.IsNullOrWhiteSpace(User))
            {
                arguments.AppendSwitchQuoted(this.GetArgumentName(nameof(User)), SwitchSeparator, User);
            }

            if (!string.IsNullOrWhiteSpace(Password))
            {
                arguments.AppendSwitchQuoted(this.GetArgumentName(nameof(Password)), SwitchSeparator, new SecretArgument(new TextArgument(Password)));
            }

            if (!string.IsNullOrWhiteSpace(HttpUser))
            {
                arguments.AppendSwitchQuoted(this.GetArgumentName(nameof(HttpUser)), SwitchSeparator, HttpUser);
            }

            if (!string.IsNullOrWhiteSpace(HttpPassword))
            {
                arguments.AppendSwitchQuoted(this.GetArgumentName(nameof(HttpPassword)), SwitchSeparator, new SecretArgument(new TextArgument(HttpPassword)));
            }

            if (!string.IsNullOrWhiteSpace(FtpUser))
            {
                arguments.AppendSwitchQuoted(this.GetArgumentName(nameof(FtpUser)), SwitchSeparator, FtpUser);
            }

            if (!string.IsNullOrWhiteSpace(FtpPassword))
            {
                arguments.AppendSwitchQuoted(this.GetArgumentName(nameof(FtpPassword)), SwitchSeparator, new SecretArgument(new TextArgument(FtpPassword)));
            }

            if (Continue)
            {
                arguments.Append(this.GetArgumentName(nameof(Continue)));
            }

            if (Timeout.HasValue)
            {
                arguments.AppendSwitch(
                    this.GetArgumentName(nameof(Timeout)),
                    SwitchSeparator,
                    Timeout.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
            }

            if (DnsTimeout.HasValue)
            {
                arguments.AppendSwitch(
                    this.GetArgumentName(nameof(DnsTimeout)),
                    SwitchSeparator,
                    DnsTimeout.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
            }

            if (ConnectTimeout.HasValue)
            {
                arguments.AppendSwitch(
                    this.GetArgumentName(nameof(ConnectTimeout)),
                    SwitchSeparator,
                    ConnectTimeout.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
            }

            if (ReadTimeout.HasValue)
            {
                arguments.AppendSwitch(
                    this.GetArgumentName(nameof(ReadTimeout)),
                    SwitchSeparator,
                    ReadTimeout.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
            }

            if (Background)
            {
                arguments.Append(this.GetArgumentName(nameof(Background)));
            }
        }