//~ 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"); } }
//~ func TestLongestPrefix(t *testing.T) { public void TestLongestPrefix() { //~ r := New() var r = new RadixTree <int>(); //~ keys := []string{ //~ "", //~ "foo", //~ "foobar", //~ "foobarbaz", //~ "foobarbazzip", //~ "foozip", //~ } var keys = new string[] { "", "foo", "foobar", "foobarbaz", "foobarbazzip", "foozip", }; //~ for _, k := range keys { //~ r.Insert(k, nil) //~ } //~ if r.Len() != len(keys) { //~ t.Fatalf("bad len: %v %v", r.Len(), len(keys)) //~ } foreach (var k in keys) { r.GoInsert(k, 1); } Assert.AreEqual(keys.Length, r.Count, "Tree count and key count match"); //~ type exp struct { //~ inp string //~ out string //~ } //~ cases := []exp{ //~ {"a", ""}, //~ {"abc", ""}, //~ {"fo", ""}, //~ {"foo", "foo"}, //~ {"foob", "foo"}, //~ {"foobar", "foobar"}, //~ {"foobarba", "foobar"}, //~ {"foobarbaz", "foobarbaz"}, //~ {"foobarbazzi", "foobarbaz"}, //~ {"foobarbazzip", "foobarbazzip"}, //~ {"foozi", "foo"}, //~ {"foozip", "foozip"}, //~ {"foozipzap", "foozip"}, //~ } var cases = new (string inp, string @out)[]
// Put is used to insert or update an entry //~ func (i *InmemBackend) Put(entry *Entry) error { public async Task PutAsync(Entry entry) { //~ i.permitPool.Acquire() //~ defer i.permitPool.Release() //~ //~ i.l.Lock() //~ defer i.l.Unlock() //~ //~ i.root.Insert(entry.Key, entry) //~ return nil using (var defer = new Util.Defer()) { await _permitPool.Acquire(); defer.Add(async() => await _permitPool.Release()); _l.EnterWriteLock(); defer.Add(() => _l.ExitWriteLock()); _root.GoInsert(entry.Key, entry); } }
//~ 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"); }