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


C# MemBlock.Equals方法代码示例

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


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

示例1: Verify

    public static void Verify(MemBlock p, ISender from, object state) {
      lock(_class_lock) {
	//
	// Make sure that the packet equals my state.
	//
	if (!p.Equals(state)) {
	  _wrongly_routed++;
	}
	_received++;
      }
    }
开发者ID:twchoi,项目名称:tmp-brunet-deetoo,代码行数:11,代码来源:RoutingTester-1.cs

示例2: Test

  public void Test() {
    System.Random r = new System.Random();

    byte[] data;
    for(int i = 0; i < 100; i++) {
      data = new byte[ r.Next(1024) ];
      r.NextBytes(data);
      int offset = r.Next(data.Length);
      MemBlock mb1 = new MemBlock(data, 0, data.Length);
      MemBlock mb1a = MemBlock.Copy(data, 0, data.Length);
      Assert.AreEqual(mb1, mb1a, "MemBlock.Copy");
      Assert.AreEqual(mb1, data, "MemBlock == byte[]");
      MemBlock mb2 = new MemBlock(data, offset, data.Length - offset);
      MemBlock mb2a = mb1.Slice(offset);
      MemBlock mb3 = new MemBlock(data, 0, offset);
      MemBlock mb3a = mb1.Slice(0, offset);
      Assert.IsTrue(mb3.Equals( mb3a ), "mb3.Equals(mb3a)");
      Assert.IsTrue(mb3a.Equals( mb3 ), "mb3a.Equals(mb3)");
      Assert.AreEqual(mb3.CompareTo(mb2) + mb2.CompareTo(mb3), 0, "CompareTo");
      Assert.IsTrue(mb2.Equals( mb2a ), "mb2.Equals(mb2a)");
      Assert.IsTrue(mb2a.Equals( mb2 ), "mb2a.Equals(mb2)");

      MemBlock cat = MemBlock.Concat(mb3, mb2);
      MemBlock cata = MemBlock.Concat(mb3a, mb2a);
      Assert.IsTrue(cat.Equals(cata), "Concat Equals");
      Assert.IsTrue(cata.Equals(cat), "Concat a Equals");
      Assert.IsTrue(mb1.Equals(cat), "Concat Equals Original");
      if( offset != 0 ) {
        //These should not be equal
        Assert.IsFalse(mb2.Equals(mb1), "mb2 != mb1");
      }
      int mb2a_l = mb2a.Length;
      byte[] tmp_data = new byte[mb2a_l];
      mb2a.CopyTo(tmp_data, 0);
      MemBlock mb2b = new MemBlock(tmp_data, 0, tmp_data.Length);
      Assert.IsTrue(mb2a.Equals(mb2b), "mb2a.Equals(mb2b)");
      Assert.IsTrue(mb2b.Equals(mb2a), "mb2b.Equals(mb2a)");

      //Check the Hash:
      Assert.AreEqual(mb2b.GetHashCode(), mb2a.GetHashCode(), "GetHashCode");

      //Here are some manual equality testing using the indexer
      bool all_equals = true;
      int j = 0;
      while( all_equals && (j < mb1.Length) ) {
        all_equals = (mb1[ j ] == cat[ j ]);
        j++;
      }
      Assert.IsTrue(all_equals, "Manual equality test mb1");
      all_equals = true;
      j = 0;
      while( all_equals && (j < mb2.Length) ) {
        all_equals = (mb2[ j ] == mb2a[ j ]);
        j++;
      }
      Assert.IsTrue(all_equals, "Manual equality test mb2");
      all_equals = true;
      j = 0;
      while( all_equals && (j < mb2.Length) ) {
        all_equals = (mb2[ j ] == mb2b[ j ]);
        j++;
      }
      Assert.IsTrue(all_equals, "Manual equality test mb2b");
    }
  }
开发者ID:xujyan,项目名称:brunet,代码行数:65,代码来源:MemBlock.cs

示例3: HandleData

 // The the packet is an eos, set _all_done otherwise ignore it...
 // This could have a counter on it to match a counter on send to ensure
 // all packets arrive prior to calling _all_done...
 public void HandleData(MemBlock b, ISender return_path, object state) {
   if(b.Equals(eos_data)) {
     _all_done.Set();
   }
 }
开发者ID:xujyan,项目名称:brunet,代码行数:8,代码来源:SystemTest.cs

示例4: VerifyRequest

 ///<summary>Verifies the hash with the DHEWithCertificateHash.</summary>
 public bool VerifyRequest(MemBlock hash) {
   if(DHEWithCertificateHash.Value == null) {
     throw new Exception("Hash not set!");
   } else if(!DHEWithCertificateHash.Value.Equals(hash)) {
     throw new Exception("Hash does not match!");
   }
   _hash_verified = true;
   return hash.Equals(DHEWithCertificateHash.Value);
 }
开发者ID:kyungyonglee,项目名称:BrunetTutorial,代码行数:10,代码来源:SecurityAssociation.cs


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