protected override bool RegisterGetPeersMessage(byte[] infoHash, DhtNode node, out TransactionId msgId) { var nodeId = (ulong)node.CompactEndPoint().ToInt64(); lock (this) { _index++; if (_index >= _bucketArray.Length) { _index = 0; } } var nowTick = DateTime.Now.Ticks; if (nowTick - _lastClearTime >= _clearDuration) { lock (this) { if (nowTick - _lastClearTime >= _clearDuration) { _treeStore.Clear(); _lastClearTime = nowTick; } } } msgId = _bucketArray[_index]; var path = nodeId << 16 | (uint)(msgId[0] << 8) | msgId[1]; return(_treeStore.TryAdd(path, infoHash)); }
/// <summary> ///A test for Clear ///</summary> public void ClearTestHelper <T>() { int degree = 2; BPlusTree <double> target = new BPlusTree <double>(degree); double data = 6; target.Add(1); target.Add(2); target.Add(3); target.Add(4); target.Add(5); target.Add(data); target.Clear(); Assert.IsNull(target.Root); }
public void TestEnumeration() { var options = Options; options.BTreeOrder = 4; using (BPlusTree <int, string> data = new BPlusTree <int, string>(options)) { data.EnableCount(); data.DebugSetOutput(new StringWriter()); data.DebugSetValidateOnCheckpoint(true); for (int id = 0; id < 10; id++) { data.Add(id, id.ToString()); } using (IEnumerator <KeyValuePair <int, string> > enu = data.GetEnumerator()) { Assert.IsTrue(enu.MoveNext()); Assert.AreEqual(0, enu.Current.Key); for (int id = 2; id < 10; id++) { Assert.IsTrue(data.Remove(id)); } for (int id = 6; id < 11; id++) { data.Add(id, id.ToString()); } Assert.IsTrue(enu.MoveNext()); Assert.AreEqual(1, enu.Current.Key); Assert.IsTrue(enu.MoveNext()); Assert.AreEqual(6, enu.Current.Key); Assert.IsTrue(enu.MoveNext()); Assert.AreEqual(7, enu.Current.Key); Assert.IsTrue(data.Remove(8)); Assert.IsTrue(data.Remove(9)); Assert.IsTrue(data.Remove(10)); data.Add(11, 11.ToString()); Assert.IsTrue(enu.MoveNext()); Assert.AreEqual(11, enu.Current.Key); Assert.IsTrue(false == enu.MoveNext()); } data.Clear(); } }
private bool LoadMediaFromDatabaseLocked(bool onStartup) { // locks & notes: see content var mediaTypes = _serviceContext.MediaTypeService.GetAll() .Select(x => _publishedContentTypeFactory.CreateContentType(x)); _mediaStore.SetAllContentTypesLocked(mediaTypes); using (_profilingLogger.TraceDuration <PublishedSnapshotService>("Loading media from database")) { // beware! at that point the cache is inconsistent, // assuming we are going to SetAll content items! _localMediaDb?.Clear(); _logger.LogDebug("Loading media from database..."); // IMPORTANT GetAllMediaSources sorts kits by level + parentId + sortOrder var kits = _publishedContentService.GetAllMediaSources(); return(onStartup ? _mediaStore.SetAllFastSortedLocked(kits, true) : _mediaStore.SetAllLocked(kits)); } }
public void TestInserts() { using (BPlusTree <int, string> data = Create(Options)) { data.EnableCount(); int[][] TestArrays = new int[][] { new int[] { 10, 18, 81, 121, 76, 31, 250, 174, 24, 38, 246, 79 }, new int[] { 110, 191, 84, 218, 170, 217, 199, 232, 184, 254, 32, 90, 241, 136, 181, 28, 226, 69, 52 }, }; foreach (int[] arry in TestArrays) { data.Clear(); Assert.AreEqual(0, data.Count); int count = 0; foreach (int id in arry) { data.Add(id, id.ToString()); Assert.AreEqual(++count, data.Count); } Assert.AreEqual(arry.Length, data.Count); data.UnloadCache(); foreach (int id in arry) { Assert.AreEqual(id.ToString(), data[id]); data[id] = String.Empty; Assert.AreEqual(String.Empty, data[id]); Assert.IsTrue(data.Remove(id)); Assert.AreEqual(--count, data.Count); } Assert.AreEqual(0, data.Count); } } }
private bool LoadContentFromDatabaseLocked(bool onStartup) { // locks: // contentStore is wlocked (1 thread) // content (and types) are read-locked var contentTypes = _serviceContext.ContentTypeService.GetAll().ToList(); _contentStore.SetAllContentTypesLocked(contentTypes.Select(x => _publishedContentTypeFactory.CreateContentType(x))); using (_profilingLogger.TraceDuration <PublishedSnapshotService>("Loading content from database")) { // beware! at that point the cache is inconsistent, // assuming we are going to SetAll content items! _localContentDb?.Clear(); // IMPORTANT GetAllContentSources sorts kits by level + parentId + sortOrder var kits = _publishedContentService.GetAllContentSources(); return(onStartup ? _contentStore.SetAllFastSortedLocked(kits, true) : _contentStore.SetAllLocked(kits)); } }
public void RandomSequenceTest() { int iterations = 5; int limit = 255; using (BPlusTree <int, string> data = Create(Options)) { data.EnableCount(); List <int> numbers = new List <int>(); while (iterations-- > 0) { data.Clear(); numbers.Clear(); data.DebugSetValidateOnCheckpoint(true); for (int i = 0; i < limit; i++) { int id = Random.Next(limit); if (!numbers.Contains(id)) { numbers.Add(id); data.Add(id, "V" + id); } } Assert.AreEqual(numbers.Count, data.Count); foreach (int number in numbers) { Assert.IsTrue(data.Remove(number)); } Assert.AreEqual(0, data.Count); } } }
public void Clear() { _tree.Clear(); }
public void Clear() { AssertModify(); _index.Clear(); }