Brunet.Services.Dht.TableServerData.AddEntry C# (CSharp) Метод

AddEntry() публичный Метод

This adds an entry and should only be called if no such entry exists, as it does not look to see if a duplicate entry already exists. This creates a new LinkedList if this is the first entry for the specific key and stores it in the _data hashtable. This increments count.
Because data is stored by non-decreasing end time, we must place this at the correct position, which by starting at the last entry is right after the first entry that has a shorter end time.
public AddEntry ( Entry entry ) : void
entry Entry The data to store.
Результат void
    public void AddEntry(Entry entry) {
      CheckEntries();
      LinkedList<Entry> data = (LinkedList<Entry>) _data[entry.Key];
      if(data == null) {
        list_of_keys.AddLast(entry.Key);
        data = new LinkedList<Entry>();
        _data[entry.Key] = data;
      }
      LinkedListNode<Entry> ent = data.Last;
      while(ent != null) {
        if(entry.EndTime > ent.Value.EndTime) {
          data.AddAfter(ent, entry);
          break;
        }
        ent = ent.Previous;
      }
      if(ent == null) {
        data.AddFirst(entry);
      }
      count++;
    }

Usage Example

Пример #1
0
        public void Test0()
        {
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
            TableServerData          tsd = new TableServerData("0");

            byte[] key = new byte[20];
            rng.GetBytes(key);
            DateTime now = DateTime.UtcNow;
            Entry    ent = new Entry(key, key, now, now.AddSeconds(100));

            tsd.AddEntry(ent);
            LinkedList <Entry> entries = tsd.GetEntries(key);

            Assert.AreEqual(1, entries.Count, "Count after add");
            Assert.AreEqual(ent, entries.First.Value, "Entries are equal");
            tsd.UpdateEntry(ent.Key, ent.Value, now.AddSeconds(200));
            entries = tsd.GetEntries(key);
            Assert.AreEqual(1, entries.Count, "Count after update");
            Assert.AreEqual(ent, entries.First.Value, "Entries are equal");
            tsd.RemoveEntry(ent.Key, ent.Value);
            entries = tsd.GetEntries(key);
            Assert.AreEqual(tsd.Count, 0, "Count after remove");
            Assert.AreEqual(null, entries, "Entry after remove");
        }
All Usage Examples Of Brunet.Services.Dht.TableServerData::AddEntry