//~ func TestRoot(t *testing.T) { public void TestRoot() { //~ r := New() var r = new RadixTree <int>(); //~ _, ok := r.Delete("") //~ if ok { //~ t.Fatalf("bad") //~ } var(_, ok) = r.GoDelete(""); Assert.IsFalse(ok, "Remove should fail"); //~ _, ok = r.Insert("", true) //~ if ok { //~ t.Fatalf("bad") //~ } (_, ok) = r.GoInsert("", 0); Assert.IsFalse(ok, "Insert should not replace"); //~ val, ok := r.Get("") //~ if !ok || val != true { //~ t.Fatalf("bad: %v", val) //~ } int val; (val, ok) = r.GoGet(""); Assert.IsTrue(ok, "Get should not find key"); Assert.AreEqual(default(int), val, "Get should return default int"); //~ val, ok = r.Delete("") //~ if !ok || val != true { //~ t.Fatalf("bad: %v", val) //~ } (val, ok) = r.GoDelete(""); Assert.IsTrue(ok, "Remove was successful"); Assert.AreEqual(default(int), val, "Remove should return default int"); }
// Get is used to fetch an entry //~ func (i *InmemBackend) Get(key string) (*Entry, error) { public async Task <Entry> GetAsync(string key) { //~ i.permitPool.Acquire() //~ defer i.permitPool.Release() //~ //~ i.l.RLock() //~ defer i.l.RUnlock() //~ //~ if raw, ok := i.root.Get(key); ok { //~ return raw.(*Entry), nil //~ } //~ return nil, nil using (var defer = new Util.Defer()) { await _permitPool.Acquire(); defer.Add(async() => await _permitPool.Release()); _l.EnterReadLock(); defer.Add(() => _l.ExitReadLock()); return(_root.GoGet(key).value); } }