public void TestCachedFind_Empty() { var snapshot = Blockchain.Singleton.GetSnapshot(); var storages = snapshot.Storages.CreateSnapshot(); var cache = new CloneCache <StorageKey, StorageItem>(storages); cache.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x02 }, Id = 0 }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x02 }, Id = 0 }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); CollectionAssert.AreEqual( cache.Find(new byte[5]).Select(u => u.Key.Key[1]).ToArray(), new byte[] { 0x02 } ); }
public void TestCachedFind_Last() { var snapshot = Blockchain.Singleton.GetSnapshot(); var storages = snapshot.Storages; var cache = new CloneCache <StorageKey, StorageItem>(storages); storages.DeleteWhere((k, v) => k.ScriptHash == UInt160.Zero); storages.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x01 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); storages.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x01 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x02 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x02 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); CollectionAssert.AreEqual( cache.Find(new byte[21]).Select(u => u.Key.Key[1]).ToArray(), new byte[] { 0x01, 0x02 } ); storages.DeleteWhere((k, v) => k.ScriptHash == UInt160.Zero); }
public override void Crack(Cracker.DataCracker context, IO.BitStream data, long?size) { try { cache = null; cracking = true; base.Crack(context, data, size); } finally { cracking = false; } }
public override DataElement Clone() { if (cracking) { return(new CloneCache(this, this.name).Get()); } if (cache == null) { cache = new CloneCache(this, this.name); } var ret = cache.Get() as DataModel; ret.cache = this.cache; return(ret); }
/// <summary> /// Creates a deep copy of the DataElement, and updates the appropriate Relations. /// </summary> /// <param name="newName">What name to set on the cloned DataElement</param> /// <param name="size">The size in bytes used when performing the copy. Useful for debugging statistics.</param> /// <returns>Returns a copy of the DataElement.</returns> public virtual DataElement Clone(string newName, ref long size) { if (DataElement.DebugClone) { logger.Debug("Clone {0} as {1}", fullName, newName); } var cache = new CloneCache(this, newName); var copy = cache.Get(); size = cache.Size; if (DataElement.DebugClone) { logger.Debug("Clone {0} took {1} bytes", copy.fullName, size); } return(copy); }
public void Init() { myDataCache = new MyDataCache <MyKey, MyValue>(); cloneCache = new CloneCache <MyKey, MyValue>(myDataCache); }
void DataModel_Invalidated(object sender, EventArgs e) { cache = null; }
public void TestCachedFind_Between() { var snapshot = TestBlockchain.GetStore().GetSnapshot(); var storages = snapshot.Storages; var cache = new CloneCache <StorageKey, StorageItem>(storages); storages.DeleteWhere((k, v) => k.ScriptHash == UInt160.Zero); storages.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x01 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); storages.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x01 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); storages.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x03 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x02 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x02 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); CollectionAssert.AreEqual( Enumerable.Select <KeyValuePair <StorageKey, StorageItem>, byte>(cache.Find(new byte[21]), u => u.Key.Key[1]).ToArray(), new byte[] { 0x01, 0x02, 0x03 } ); storages.DeleteWhere((k, v) => k.ScriptHash == UInt160.Zero); }