Exemplo n.º 1
0
        public void TestCompare()
        {
            var path = CleanTestDB();

            var options = new Options {
                CreateIfMissing = true
            };

            options.Comparator = Comparator.Create(
                "integers mod 2",
                (xs, ys) => LexicographicalCompare(((NativeArray <int>)xs).Select(x => x % 2),
                                                   ((NativeArray <int>)ys).Select(y => y % 2)));

            using (var db = new DB(options, path))
            {
                db.Put(1, new[] { 1, 2, 3 }, new WriteOptions());
                Console.WriteLine("put 1, [1,2,3]");

                var key = NativeArray.FromArray(new int[] { 3 });
                using (var xs = db.GetRaw <int>(key))
                {
                    Console.WriteLine("get {0} => [{1}]", key[0], string.Join(",", xs));
                    Assert.IsTrue(
                        new[] { 1, 2, 3 }.Zip(xs, (x, y) => x == y)
                        .All(b => b)
                        );
                }
            }
        }
Exemplo n.º 2
0
        public ChromiumDbWrapper(string directory)
        {
            _comparator = Comparator.Create("idb_cmp1",
                                            (xs, ys) => Compare(new StringPiece(xs), new StringPiece(ys), false));

            _options = new Options {
                Comparator = _comparator
            };

            _levelDb = new LevelDbUtils.LevelDb(_options, directory);
        }
Exemplo n.º 3
0
        static public void TestCompare()
        {
            var path = CleanTestDB();

            var options = new Options {
                CreateIfMissing = true
            };

            options.Comparator = Comparator.Create(
                "integers mod 2",
                (xs, ys) => LexicographicalCompare(((NativeArray <int>)xs).Select(x => fun(x)),
                                                   ((NativeArray <int>)ys).Select(y => fun(y))));

            object[] o   = { 1, "1", "2" };
            string   s0  = o.ToString();
            string   s01 = string.Join(",", o);

            object[] o1  = { "1,1", "2", "2" };
            object[] o2  = { "1", "1,2", "2" };
            string   s1  = o1.ToString();
            string   s2  = o2.ToString();
            string   s11 = string.Join(",", o1);
            string   s21 = string.Join(",", o2);

            using (var db = new DB(options, path))
            {
                byte[] tt = new byte[10];
                byte[] t  = BitConverter.GetBytes(1234);

                db.Put(BitConverter.GetBytes(1234), System.Text.Encoding.Default.GetBytes("this is a test string."));

                db.Put(BitConverter.GetBytes(123), BitConverter.GetBytes(1234));

                byte[] ret  = db.Get(BitConverter.GetBytes(123));
                byte[] ret2 = db.Get(BitConverter.GetBytes(1234));
                int    i1   = BitConverter.ToInt32(ret, 0);
                string str1 = System.Text.Encoding.ASCII.GetString(ret2);
                db.Put(1, new[] { 1, 2, 3 }, new WriteOptions());
                db.Put(3, new[] { 10, 20, 30 }, new WriteOptions());
                Console.WriteLine("put 1, [1,2,3]");
                Console.WriteLine("get 1:" + db.Get(1));
                Console.WriteLine("get 3:" + db.Get(3));
                Console.WriteLine("get 5:" + db.Get(5));

                var key = NativeArray.FromArray(new int[] { 3 });
                using (var xs = db.GetRaw <int>(key))
                {
                    int[]  arr = xs.ToArray();
                    string s   = string.Format("get {0} => [{1}]", key[0], string.Join(",", xs));
                    Console.WriteLine("get {0} => [{1}]", key[0], string.Join(",", xs));
                }
            }
        }