当前位置: 首页>>代码示例>>C#>>正文


C# Key.CompareTo方法代码示例

本文整理汇总了C#中Key.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Key.CompareTo方法的具体用法?C# Key.CompareTo怎么用?C# Key.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Key的用法示例。


在下文中一共展示了Key.CompareTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compare

        public void Compare()
        {
            var x = new Key();
            Assert.IsTrue(x.CompareTo(null) > 0);
            Assert.IsFalse(x.Equals(null));
            Assert.IsFalse(x.Equals(string.Empty));
            Assert.IsTrue(x != null);

            var y = new Key();
            Assert.AreEqual(x, y);
            Assert.IsTrue(x.CompareTo(y) == 0);
            Assert.IsTrue(x == y);

            x.Row = "A";
            y.Row = "B";
            Assert.AreNotEqual(x, y);
            Assert.IsTrue(x.CompareTo(y) < 0);
            Assert.IsTrue(y.CompareTo(x) > 0);
            Assert.IsTrue(x != y);
            Assert.IsTrue(x < y);
            Assert.IsFalse(x > y);

            x.Row = "AB";
            y.Row = "AB";
            Assert.AreEqual(x, y);
            Assert.IsTrue(x.CompareTo(y) == 0);
            Assert.IsTrue(y.CompareTo(x) == 0);
            Assert.IsTrue(x == y);

            x.ColumnFamily = "A";
            y.ColumnFamily = "B";
            Assert.AreNotEqual(x, y);
            Assert.IsTrue(x.CompareTo(y) < 0);
            Assert.IsTrue(y.CompareTo(x) > 0);
            Assert.IsTrue(x != y);
            Assert.IsTrue(x < y);
            Assert.IsFalse(x > y);

            x.ColumnFamily = null;
            y.ColumnFamily = string.Empty;
            Assert.AreNotEqual(x, y);
            Assert.IsTrue(x.CompareTo(y) < 0);
            Assert.IsTrue(y.CompareTo(x) > 0);

            x.ColumnFamily = "AB";
            y.ColumnFamily = "AB";
            Assert.AreEqual(x, y);
            Assert.IsTrue(x.CompareTo(y) == 0);
            Assert.IsTrue(y.CompareTo(x) == 0);
            Assert.IsTrue(x == y);

            x.ColumnQualifier = "A";
            y.ColumnQualifier = "B";
            Assert.AreNotEqual(x, y);
            Assert.IsTrue(x.CompareTo(y) < 0);
            Assert.IsTrue(y.CompareTo(x) > 0);
            Assert.IsTrue(x != y);
            Assert.IsTrue(x < y);
            Assert.IsFalse(x > y);

            x.ColumnQualifier = null;
            y.ColumnQualifier = string.Empty;
            Assert.AreNotEqual(x, y);
            Assert.IsTrue(x.CompareTo(y) < 0);
            Assert.IsTrue(y.CompareTo(x) > 0);
            Assert.IsTrue(x != y);
            Assert.IsTrue(x < y);
            Assert.IsFalse(x > y);

            x.ColumnQualifier = "AB";
            y.ColumnQualifier = "AB";
            Assert.AreEqual(x, y);
            Assert.IsTrue(x.CompareTo(y) == 0);
            Assert.IsTrue(y.CompareTo(x) == 0);
            Assert.IsTrue(x == y);

            x.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc);
            y.DateTime = new DateTime(2011, 1, 1, 1, 2, 4, DateTimeKind.Utc);
            Assert.AreNotEqual(x, y);
            Assert.IsTrue(x.CompareTo(y) < 0);
            Assert.IsTrue(y.CompareTo(x) > 0);
            Assert.IsTrue(x != y);
            Assert.IsTrue(x < y);
            Assert.IsFalse(x > y);

            x.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc);
            y.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc);
            Assert.AreEqual(x, y);
            Assert.IsTrue(x.CompareTo(y) == 0);
            Assert.IsTrue(y.CompareTo(x) == 0);
            Assert.AreEqual(x, y);
        }
开发者ID:andysoftdev,项目名称:ht4n,代码行数:92,代码来源:TestKey.cs

示例2: SearchBlockForKey

        static bool SearchBlockForKey(byte[] block, Key key, out Value value)
        {
            int offset = BitConverter.ToUInt16 (block, 0); // grab the tree root
            value = Value.Empty;

            while (offset >= 2 && offset < Config.SortedBlockSize && block[offset] == (byte)RecordHeaderFlag.Record) {
                int startingOffset = offset;
                offset += 1; // skip header
                offset += 4; // skip tree pointers
                int keySize = Helper.Decode7BitInt (block, ref offset);
                int cmp = key.CompareTo (block, offset, keySize);
                if (cmp == 0) {
                    // Found it
                    var pair = ReadPair (block, ref startingOffset);
                    value = pair.Value;
                    return true;
                } else if (cmp < 0)
                    offset = BitConverter.ToUInt16 (block, startingOffset + 1); // key < node => explore left side
                else if (cmp > 0)
                    offset = BitConverter.ToUInt16 (block, startingOffset + 3); // key > node => explore right side
            }
            return false;
        }
开发者ID:T145,项目名称:razordbx,代码行数:23,代码来源:SortedBlockTable.cs

示例3: LevelMergeReadTest2

        public void LevelMergeReadTest2()
        {
            string path = Path.GetFullPath ("TestData\\LevelMergeReadTest2");
            if (!Directory.Exists (path)) Directory.CreateDirectory (path);

            int num_tables_to_merge = 4;
            int items_per_table = 2500;
            int totalData = 0;
            for (int i = 0; i < num_tables_to_merge; i++) {
                var mt = new MemTable ();
                for (int j = 0; j < items_per_table; j++) {
                    var randKey = Key.Random (40);
                    var randVal = Value.Random (512);
                    mt.Add (randKey, randVal);
                }
                mt.WriteToSortedBlockTable ("TestData\\LevelMergeReadTest2", 0, i);
                totalData += mt.Size;
            }

            var cache = new RazorCache ();
            int ct = 0;
            Key key = new Key (new ByteArray (new byte[] { 0 }));
            var timer = new Stopwatch ();
            timer.Start ();
            foreach (var pair in SortedBlockTable.EnumerateMergedTablesPreCached(cache, "TestData\\LevelMergeReadTest2",
                new List<PageRef>{
                new PageRef { Level = 0, Version = 0},
                new PageRef { Level = 0, Version = 1},
                new PageRef { Level = 0, Version = 2},
                new PageRef { Level = 0, Version = 3}
                }, ExceptionHandling.ThrowAll, null)) {
                Assert.True (key.CompareTo (pair.Key) < 0);
                key = pair.Key;
                ct++;
            }
            timer.Stop ();

            Console.WriteLine ("Scanned through a multilevel merge at a throughput of {0} MB/s", (double)totalData / timer.Elapsed.TotalSeconds / (1024.0 * 1024.0));
        }
开发者ID:T145,项目名称:razordbx,代码行数:39,代码来源:LevelMergeTests.cs

示例4: ScanBlockForKey

        static bool ScanBlockForKey(byte[] block, Key key, out Value value)
        {
            int offset = 2; // skip over the tree root pointer
            value = Value.Empty;

            while (offset >= 2 && offset < Config.SortedBlockSize && block[offset] == (byte)RecordHeaderFlag.Record) {
                int startingOffset = offset;
                offset++; // skip past the header flag
                offset += 4; // skip past the tree pointers
                int keySize = Helper.Decode7BitInt (block, ref offset);
                int cmp = key.CompareTo (block, offset, keySize);
                if (cmp == 0) {
                    // Found it
                    var pair = ReadPair (block, ref startingOffset);
                    value = pair.Value;
                    return true;
                } else if (cmp < 0)
                    return false;
                offset += keySize;
                // Skip past the value
                int valueSize = Helper.Decode7BitInt (block, ref offset);
                offset += valueSize;
            }
            return false;
        }
开发者ID:T145,项目名称:razordbx,代码行数:25,代码来源:SortedBlockTable.cs


注:本文中的Key.CompareTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。