Пример #1
0
        public static void TestCase14()
        {
            TestBaseConfig.Seed = 1;
            Int32Class a = ShiboSerializer.Initialize <Int32Class>(53456158);

            byte[]     bytes = ShiboSerializer.BinarySerialize(a);
            Int32Class b     = ShiboSerializer.BinaryDeserialize <Int32Class>(bytes);

            //Console.WriteLine(ShiboComparer.Compare<List<string>>(a, b));
            Console.WriteLine(JsonConvert.SerializeObject(a) == JsonConvert.SerializeObject(b));

            ObjectWriter bf = new ObjectWriter(50);
            Stopwatch    w  = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                //bytes = ShiboSerializer.BinarySerialize(a);
                //b = ShiboSerializer.BinaryDeserialize<List<string>>(bytes);
                bf.Reset();
                ShiboSerializer.BinarySerialize(bf, a);
            }
            w.Stop();
            Console.WriteLine(w.ElapsedMilliseconds);
            //Console.WriteLine(JsonConvert.SerializeObject(b.Count));
        }
Пример #2
0
        public static void TestCase1()
        {
            //Guid guid = new Guid("e92b8e30-a6e5-41f6-a6b9-188230a23dd2");
            //byte[] buffer = guid.ToByteArray();
            //Console.WriteLine(BitConverter.ToString(buffer));
            Dictionary <int, string> v = new Dictionary <int, string>();

            v.Add(1, null);

            TestBaseConfig.Seed = 1;
            Int32Class a  = ShiboSerializer.Initialize <Int32Class>();// Int32Class.Init();
            string     s1 = ShiboSerializer.Serialize(a);
            string     s2 = null;

            byte[] buffer = ShiboSerializer.BinarySerialize(a);
            a  = ShiboSerializer.BinaryDeserialize <Int32Class>(buffer);
            s2 = ShiboSerializer.Serialize(a);
            Console.WriteLine(BitConverter.ToString(buffer));
            Console.WriteLine(s1 == s2);
            //Console.ReadLine();
            Test(a);

            //Int32FieldClass a = Int32FieldClass.Init();
            //byte[] buffer = ShiboSerializer.BinSerialize(a);
            ////byte[] b = new byte[400];
            ////Buffer.BlockCopy(buffer, 0, b, 0, 4);
            //a = ShiboSerializer.BinDeserialize<Int32FieldClass>(buffer);
            //Console.WriteLine(BitConverter.ToString(buffer));
            //Console.WriteLine(ShiboSerializer.Serialize(a));
            Console.ReadLine();
        }
Пример #3
0
        public static void RunCsvArrayTest()
        {
            //ShiboSerializer.Serialize(os, graph, sets);

            //List<int> v = new List<int>();
            //v.Add(123);
            //v.Add(456);

            //IList<bool> v = new List<bool>();
            //v.Add(true);
            //v.Add(false);

            //IList<Int32Class> v = new List<Int32Class>();
            //v.Add(new Int32Class());
            //v.Add(new Int32Class());

            int n = 100;
            var v = new Int32Class[n];

            for (int i = 0; i < n; i++)
            {
                v[i] = ShiboSerializer.Initialize <Int32Class>();
            }
            var csv = ShiboSerializer.ToCsv(v);

            //CsvHelper.CsvWriter c = new CsvHelper.CsvWriter();
            Console.WriteLine(csv);
        }
Пример #4
0
        public override int GetOrdinal(FacetLabel cp)
        {
            EnsureOpen();
            if (cp.Length == 0)
            {
                return(ROOT_ORDINAL);
            }

            // First try to find the answer in the LRU cache:

            // LUCENENET: Lock was removed here because the underlying cache is thread-safe,
            // and removing the lock seems to make the performance better.
            Int32Class res = ordinalCache.Get(cp);

            if (res != null)
            {
                if ((int)res.Value < indexReader.MaxDoc)
                {
                    // Since the cache is shared with DTR instances allocated from
                    // doOpenIfChanged, we need to ensure that the ordinal is one that
                    // this DTR instance recognizes.
                    return((int)res.Value);
                }
                else
                {
                    // if we get here, it means that the category was found in the cache,
                    // but is not recognized by this TR instance. Therefore there's no
                    // need to continue search for the path on disk, because we won't find
                    // it there too.
                    return(TaxonomyReader.INVALID_ORDINAL);
                }
            }

            // If we're still here, we have a cache miss. We need to fetch the
            // value from disk, and then also put it in the cache:
            int      ret  = TaxonomyReader.INVALID_ORDINAL;
            DocsEnum docs = MultiFields.GetTermDocsEnum(indexReader, null, Consts.FULL, new BytesRef(FacetsConfig.PathToString(cp.Components, cp.Length)), 0);

            if (docs != null && docs.NextDoc() != DocIdSetIterator.NO_MORE_DOCS)
            {
                ret = docs.DocID;

                // we only store the fact that a category exists, not its inexistence.
                // This is required because the caches are shared with new DTR instances
                // that are allocated from doOpenIfChanged. Therefore, if we only store
                // information about found categories, we cannot accidently tell a new
                // generation of DTR that a category does not exist.

                // LUCENENET: Lock was removed here because the underlying cache is thread-safe,
                // and removing the lock seems to make the performance better.
                ordinalCache.Put(cp, new Int32Class {
                    Value = Convert.ToInt32(ret)
                });
            }

            return(ret);
        }
Пример #5
0
        public void TestInt32Bytes()
        {
            var data = new Int32Class[10];

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = ShiboSerializer.Initialize <Int32Class>();
            }
            var expected = ServiceStack.Text.CsvSerializer.SerializeToCsv(data);
            var actual   = Encoding.UTF8.GetString(ShiboSerializer.ToCsvUtf8(data));

            Assert.AreEqual(expected, actual);
        }
Пример #6
0
        public void TestNextInt64Range()
        {
            IDictionary <long, Int32Class> valueToCount = new Dictionary <long, Int32Class>();
            long minValue = 3000000000;
            long maxValue = 3000000010;
            int  tries    = 1000000 * 10;

            for (int i = 0; i < tries; i++)
            {
                long value = r.NextInt64(minValue, maxValue);
                if (valueToCount.TryGetValue(value, out Int32Class times))
                {
                    times.Value++;
                }
                else
                {
                    valueToCount[value] = new Int32Class {
                        Value = 1
                    }
                };
            }


            long minRunValue = long.MaxValue, maxRunValue = long.MinValue;

            foreach (var count in valueToCount.Values)
            {
                if (minRunValue > count.Value)
                {
                    minRunValue = count.Value;
                }
                if (maxRunValue < count.Value)
                {
                    maxRunValue = count.Value;
                }
            }

            long maxDeviation = maxRunValue - minRunValue;

            double variance = (double)maxDeviation / (double)tries;

            if (variance > 0.01d)
            {
                Assert.Fail($"Variance was higher than 1%: {variance}");
            }
        }
Пример #7
0
        public static void TestCase2()
        {
            TestBaseConfig.Seed = 1;
            Int32Class a = ShiboSerializer.Initialize <Int32Class>(); //Int32Class.Init();

            byte[]     buffer = ShiboSerializer.BinarySerialize(a);
            Int32Class b      = ShiboSerializer.BinaryDeserialize <Int32Class>(buffer);
            Stopwatch  w      = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                buffer = ShiboSerializer.BinarySerialize(a);
                //b = ShiboSerializer.BinDeserialize<Int32Class>(buffer);
            }
            w.Stop();
            Console.WriteLine(w.ElapsedMilliseconds);
            Console.WriteLine(JsonConvert.SerializeObject(a) == JsonConvert.SerializeObject(b));
        }
Пример #8
0
        public void TestInt32()
        {
            var data = new Int32Class[100];

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = ShiboSerializer.Initialize <Int32Class>();
            }
            var ret   = ShiboSerializer.ToColumns(data);
            var bytes = new int[data.Length];

            for (int i = 0; i < data.Length; i++)
            {
                bytes[i] = data[i].V0;
            }
            var v1 = Csv((int[])ret[0].Value);
            var v2 = Csv(bytes);

            Assert.AreEqual(v1, v2);
        }
Пример #9
0
        public static void TestCase3()
        {
            TestBaseConfig.Seed = 1;
            Int32Class a    = ShiboSerializer.Initialize <Int32Class>(); //Int32Class.Init();
            string     json = ShiboSerializer.Serialize(a);
            Int32Class b    = ShiboSerializer.Deserialize <Int32Class>(json);

            b = JsonConvert.DeserializeObject <Int32Class>(json);
            //Test(a);

            Stopwatch w = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                //json = JsonConvert.SerializeObject(a);
                //json = ShiboSerializer.Serialize(a);
                ShiboSerializer.SerializeToBuffer(a);
                //b = ShiboSerializer.Deserialize<Int32Class>(json);
                //b = JsonConvert.DeserializeObject<Int32Class>(json);
            }
            w.Stop();
            Console.WriteLine(w.ElapsedMilliseconds);
            Console.WriteLine(JsonConvert.SerializeObject(a) == JsonConvert.SerializeObject(b));
        }