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


C# AHAddress.IsRightOf方法代码示例

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


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

示例1: Test2

    public void Test2() {
      TableServerData tsd = new TableServerData("0");
      RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
      MemBlock[] addresses = new MemBlock[100];
      byte[] value = new byte[20];
      rng.GetBytes(value);
      DateTime now = DateTime.UtcNow;
      DateTime lease_end = now.AddMinutes(1);
      for(int i = 0; i < addresses.Length; i++) {
        addresses[i] = (new AHAddress(rng)).ToMemBlock();
        tsd.AddEntry(new Entry(addresses[i], value, now, lease_end));
      }

      AHAddress start = new AHAddress(rng);
      AHAddress end = new AHAddress(rng);
      LinkedList<MemBlock> keys_se = tsd.GetKeysBetween(start, end);
      LinkedList<MemBlock> keys_es = tsd.GetKeysBetween(end, start);
      String output = " - " +start + ":" + end;
      if(start.IsLeftOf(end)) {
        foreach(MemBlock address in addresses) {
          AHAddress addr = new AHAddress(address);
          if(addr.IsLeftOf(end) && addr.IsRightOf(start)) {
            Assert.IsTrue(keys_se.Contains(address), addr + " in lse" + output);
            Assert.IsTrue(keys_es.Contains(address), addr + " in les" + output);
          }
          else {
            Assert.IsFalse(keys_se.Contains(address), addr + " out lse" + output);
            Assert.IsFalse(keys_es.Contains(address), addr + " out les" + output);
          }
        }
      }
      else {
        foreach(MemBlock address in addresses) {
          AHAddress addr = new AHAddress(address);
          if(addr.IsLeftOf(start) && addr.IsRightOf(end)) {
            Assert.IsTrue(keys_se.Contains(address), addr + " in rse" + output);
            Assert.IsTrue(keys_es.Contains(address), addr + " in res" + output);
          }
          else {
            Assert.IsFalse(keys_se.Contains(address), addr + " out rse" + output);
            Assert.IsFalse(keys_es.Contains(address), addr + " out res" + output);
          }
        }
      }

      LinkedList<MemBlock> keys = tsd.GetKeys();
      foreach(MemBlock addr in addresses) {
        Assert.IsTrue(keys.Contains(addr), "keys does not contain: " + (new AHAddress(addr)));
      }
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:50,代码来源:TableServerData.cs

示例2: Test

    public void Test() {
      byte[]  buf1 = new byte[20];
      for (int i = 0; i <= 18; i++)
      {
        buf1[i] = 0x00;
      }
      buf1[19] = 0x0A;
      AHAddress test_address_1 = new AHAddress( MemBlock.Reference(buf1, 0, buf1.Length) );

      byte[] buf2 = new byte[20];
      for (int i = 0; i <= 18; i++) {
        buf2[i] = 0xFF;
      }
      buf2[19] = 0xFE;
      AHAddress test_address_2 = new AHAddress( MemBlock.Reference(buf2, 0, buf2.Length) );
      //test_address_1 is to the left of test_address_2
      //because it only a few steps in the clockwise direction:
      Assert.IsTrue( test_address_1.IsLeftOf( test_address_2 ), "IsLeftOf");
      Assert.IsTrue( test_address_2.IsRightOf( test_address_1 ), "IsRightOf");
      //This distance is twelve:
      Assert.AreEqual( test_address_2.DistanceTo( test_address_1),
                       new BigInteger(12), "DistanceTo");
      Assert.IsTrue( test_address_1.CompareTo(test_address_2) < 0, "CompareTo");
      Assert.IsTrue( test_address_2.CompareTo(test_address_1) > 0, "CompareTo");
      byte[] buf3 = new byte[Address.MemSize];
      test_address_2.CopyTo(buf3);
      AHAddress test3 = new AHAddress(MemBlock.Reference(buf3,0,buf3.Length)); 
      Assert.IsTrue( test3.CompareTo( test_address_2 ) == 0 , "CompareTo");
      Assert.IsTrue( test3.CompareTo( test3 ) == 0, "CompareTo");
      //As long as the address does not wrap around, adding should increase it:
      AHAddress a4 = new AHAddress( test_address_1.ToBigInteger() + 100 );
      Assert.IsTrue( a4.CompareTo( test_address_1 ) > 0, "adding increases");
      Assert.IsTrue( a4.CompareTo( test_address_2 ) < 0, "smaller than biggest");
      //Here are some consistency tests:
      for( int i = 0; i < 1000; i++) {
        System.Random r = new Random();
        byte[] b1 = new byte[Address.MemSize];
        r.NextBytes(b1);
        //Make sure it is class 0:
        Address.SetClass(b1, 0);
        byte[] b2 = new byte[Address.MemSize];
        r.NextBytes(b2);
        //Make sure it is class 0:
        Address.SetClass(b2, 0);
        byte[] b3 = new byte[Address.MemSize];
        r.NextBytes(b3);
        //Make sure it is class 0:
        Address.SetClass(b3, 0);
        AHAddress a5 = new AHAddress( MemBlock.Reference(b1,0,b1.Length) );
        AHAddress a6 = new AHAddress( MemBlock.Reference(b2,0,b2.Length) );
        AHAddress a7 = new AHAddress( MemBlock.Reference(b3,0,b3.Length) );
        Assert.IsTrue( a5.CompareTo(a6) == -1 * a6.CompareTo(a5), "consistency");
        //Nothing is between the same address:
        Assert.IsFalse( a5.IsBetweenFromLeft(a6, a6), "Empty Between Left");
        Assert.IsFalse( a5.IsBetweenFromRight(a7, a7), "Empty Between Right");
        //Endpoints are not between:
        Assert.IsFalse( a6.IsBetweenFromLeft(a6, a7), "End point Between Left");
        Assert.IsFalse( a6.IsBetweenFromRight(a6, a7), "End point Between Right");
        Assert.IsFalse( a7.IsBetweenFromLeft(a6, a7), "End point Between Left");
        Assert.IsFalse( a7.IsBetweenFromRight(a6, a7), "End point Between Right");

        if ( a5.IsBetweenFromLeft(a6, a7) ) {
          //Then the following must be true:
          Assert.IsTrue( a6.LeftDistanceTo(a5) < a6.LeftDistanceTo(a7),
                         "BetweenLeft true");
        }
        else {
          //Then the following must be false:
          Assert.IsFalse( a6.LeftDistanceTo(a5) < a6.LeftDistanceTo(a7),
                          "BetweenLeft false");
        }
        if ( a5.IsBetweenFromRight(a6, a7) ) {
          //Then the following must be true:
          Assert.IsTrue( a6.RightDistanceTo(a5) < a6.RightDistanceTo(a7),
                         "BetweenRight true");
        }
        else {
          //Then the following must be false:
          Assert.IsFalse( a6.RightDistanceTo(a5) < a6.RightDistanceTo(a7),
                          "BetweenRight false");
        }
        if( a5.IsCloserToFirst(a6, a7) ) {
          Assert.IsTrue( a5.DistanceTo(a6).abs() < a5.DistanceTo(a7).abs(), "IsCloser 1");
        }
        else {
          Assert.IsFalse( a5.DistanceTo(a6).abs() < a5.DistanceTo(a7).abs(), "IsCloser 2");
        }
        Assert.IsFalse(a5.IsCloserToFirst(a6, a7) && a5.IsCloserToFirst(a7,a6), "can only be closer to one!");
        if( false == a5.Equals(a6) ) {
          Assert.IsTrue(a5.IsCloserToFirst(a5, a6), "Always closer to self");
        }
        Assert.IsFalse(a5.IsBetweenFromLeft(a6, a7) ==
                            a5.IsBetweenFromRight(a6, a7),
                            "can't be between left and between right");
      }
    }
开发者ID:johnynek,项目名称:brunet,代码行数:96,代码来源:AHAddress.cs

示例3: GetKeysBetween

 /**
 <summary>Returns a list of keys stored at this node that exist between the
 two addresses.  Such keys returned are the storest path between the two
 addresses.</summary>
 <param name="add1">One of the address end points.</param>
 <param name="add2">Another of the address end points.</param>
 <returns>A LinkedList of key entries between add1 and add2</returns>
 */
 public LinkedList<MemBlock> GetKeysBetween(AHAddress add1, AHAddress add2) {
   LinkedList<MemBlock> keys = new LinkedList<MemBlock>();
   if(add1.IsRightOf(add2)) {
     foreach(MemBlock key in list_of_keys) {
       AHAddress key_addr = new AHAddress(key);
       if(key_addr.IsBetweenFromLeft(add1, add2)) {
         keys.AddLast(key);
       }
     }
   }
   else {
     foreach(MemBlock key in list_of_keys) {
       AHAddress key_addr = new AHAddress(key);
       if(key_addr.IsBetweenFromRight(add1, add2)) {
         keys.AddLast(key);
       }
     }
   }
   return keys;
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:28,代码来源:TableServerData.cs


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