public void TestExceptWith() { var a = new UInt256(new byte[32] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }); var b = new UInt256(new byte[32] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02 }); var c = new UInt256(new byte[32] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03 }); var set = new FIFOSet <UInt256>(10) { a, b, c }; set.ExceptWith(new UInt256[] { b, c }); CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { a }); }
internal static void Remove <T>(this HashSet <T> set, FIFOSet <T> other) where T : IEquatable <T> { if (set.Count > other.Count) { set.ExceptWith(other); } else { set.RemoveWhere(u => other.Contains(u)); } }
public ProtocolHandler(ZoroSystem system, LocalNode localNode, Blockchain blockchain, RemoteNode remoteNode) { this.system = system; this.localNode = localNode; this.blockchain = blockchain; this.remoteNode = remoteNode; InitMessageHandlers(); this.knownHashes = new FIFOSet <UInt256>(blockchain.MemPool.Capacity * 2); this.sentHashes = new FIFOSet <UInt256>(blockchain.MemPool.Capacity * 2); }
public void FIFOSetTest() { var a = UInt256.Zero; var b = new UInt256(); var c = new UInt256(new byte[32] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }); var set = new FIFOSet <UInt256>(3); Assert.IsTrue(set.Add(a)); Assert.IsFalse(set.Add(a)); Assert.IsFalse(set.Add(b)); Assert.IsTrue(set.Add(c)); CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { a, c }); var d = new UInt256(new byte[32] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02 }); // Testing Fifo max size Assert.IsTrue(set.Add(d)); CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { a, c, d }); var e = new UInt256(new byte[32] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03 }); Assert.IsTrue(set.Add(e)); Assert.IsFalse(set.Add(e)); CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { c, d, e }); }
public void TestAdd() { var a = new UInt256(new byte[32] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }); var b = new UInt256(new byte[32] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02 }); var set = new FIFOSet <UInt256>(1, 1); set.Add(a); set.Add(b); CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { b }); }
public void FifoSetTest() { var a = UInt256.Zero; var b = new UInt256(); var c = new UInt256(new byte[32] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }); var set = new FIFOSet <UInt256>(3); Assert.IsTrue(set.Add(a)); Assert.IsFalse(set.Add(a)); Assert.IsFalse(set.Add(b)); Assert.IsTrue(set.Add(c)); CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { a, c }); }
public void TestAdd() { var a = new UInt256(new byte[32] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }); var b = new UInt256(new byte[32] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02 }); var set = new FIFOSet <UInt256>(1, 1) { a, b }; CollectionAssert.AreEqual(Enumerable.ToArray <UInt256>(set), new UInt256[] { b }); }
public void TestGetEnumerator() { var a = new UInt256(new byte[32] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }); var b = new UInt256(new byte[32] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02 }); var set = new FIFOSet <UInt256>(1, 1) { a, b }; IEnumerable ie = set; ie.GetEnumerator().Should().NotBeNull(); }
public TaskManager(TrustlinkSystem system) { this.system = system; this.knownHashes = new FIFOSet <UInt256>(Blockchain.Singleton.MemPool.Capacity * 2); }
public ProtocolHandler(NeoSystem system) { this.system = system; this.knownHashes = new FIFOSet <UInt256>(Blockchain.Singleton.MemPool.Capacity * 2); this.sentHashes = new FIFOSet <UInt256>(Blockchain.Singleton.MemPool.Capacity * 2); }