예제 #1
0
        //~ func TestDelete(t *testing.T) {
        public void TestDelete()
        {
            //~ r := New()
            var r = new RadixTree <int>();

            //~ s := []string{"", "A", "AB"}
            var s = new string[] { "", "A", "AB" };

            //~ for _, ss := range s {
            //~     r.Insert(ss, true)
            //~ }
            foreach (var ss in s)
            {
                r.GoInsert(ss, 1);
            }

            //~ for _, ss := range s {
            //~     _, ok := r.Delete(ss)
            //~     if !ok {
            //~         t.Fatalf("bad %q", ss)
            //~     }
            //~ }
            foreach (var ss in s)
            {
                var(_, ok) = r.GoDelete(ss);
                Assert.IsTrue(ok, "Removed key");
            }
        }
예제 #2
0
        //~ 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");
        }
예제 #3
0
        // Delete is used to permanently delete an entry
        //~ func (i *InmemBackend) Delete(key string) error {
        public async Task DeleteAsync(string key)
        {
            //~ i.permitPool.Acquire()
            //~ defer i.permitPool.Release()
            //~
            //~ i.l.Lock()
            //~ defer i.l.Unlock()
            //~
            //~ i.root.Delete(key)
            //~ return nil
            using (var defer = new Util.Defer())
            {
                await _permitPool.Acquire();

                defer.Add(async() => await _permitPool.Release());

                _l.EnterWriteLock();
                defer.Add(() => _l.ExitWriteLock());

                _root.GoDelete(key);
            }
        }