Пример #1
0
            public void InsertAndExistsAndNotExists()
            {
                var words      = new[] { "Car", "Cat" };
                var strEncoder = Encoding.GetEncoding("iso-8859-1");

                var sut = new Tries256 <string>();

                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);
                }
            }
Пример #2
0
            public void InsertAndCount()
            {
                var words      = new[] { "Car", "Cat", "Car", "Cat" };
                var strEncoder = Encoding.GetEncoding("iso-8859-1");

                var sut = new Tries256 <string>();

                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());
            }
        /// <summary>
        /// Encodes bytes using LZ and fixed length trie as dictionary
        /// </summary>
        /// <param name="input">Byte array</param>
        /// <returns></returns>
        public static byte[] BytesAsLZEncodedUsingTrie256(this byte[] input)
        {
            var encoderDic = new Tries256 <int>();

            return(_asLZEncoded(input, encoderDic));
        }
Пример #4
0
        /// <summary>
        /// Decodes compressed bytes
        /// </summary>
        /// <param name="codes">Compressed bytes</param>
        /// <returns>Decompressed data</returns>
        public static byte[] AsLZDecodedUsingTrie256(this byte[] codes)
        {
            var decoderDic = new Tries256 <byte[]>();

            return(_asLZDecoded(codes, decoderDic));
        }