Browse Source

ZoneTable::find

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac440@3896 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner 14 years ago
parent
commit
afa0f7eea0
1 changed files with 32 additions and 12 deletions
  1. 32 12
      src/lib/datasrc/zonetable.cc

+ 32 - 12
src/lib/datasrc/zonetable.cc

@@ -101,6 +101,36 @@ struct ZoneTable::ZoneTableImpl {
             return (result::EXIST);
         }
     }
+
+    ZoneTable::FindResult findZone(const Name& name) const {
+        ZoneNode *node(NULL);
+        result::Result my_result;
+
+        // Translate the return codes
+        switch (zones.find(name, &node)) {
+            case ZoneTree::EXACTMATCH:
+                my_result = result::SUCCESS;
+                break;
+            case ZoneTree::PARTIALMATCH:
+                my_result = result::PARTIALMATCH;
+                break;
+            // We have no data there, so translate the pointer to NULL as well
+            case ZoneTree::NOTFOUND:
+                return (FindResult(result::NOTFOUND, ConstZonePtr()));
+            // Can Not Happen
+            default:
+                isc_throw(AssertError,
+                    "RBTree<Zone>::find returned unexpected result");
+        }
+
+        // Can Not Happen (remember, NOTFOUND is handled)
+        if (!node) {
+            isc_throw(AssertError,
+                "RBTree<Zone>::find gave NULL pointer");
+        }
+
+        return (FindResult(my_result, node->getData()));
+    }
 };
 
 ZoneTable::ZoneTable() : impl_(new ZoneTableImpl)
@@ -123,18 +153,8 @@ ZoneTable::removeZone(const Name&) {
 
 ZoneTable::FindResult
 ZoneTable::findZone(const Name& name) const {
-    // Inefficient internal loop to find a longest match.
-    // This will be replaced with a single call to more intelligent backend.
-    for (int i = 0; i < name.getLabelCount(); ++i) {
-        Name matchname(name.split(i));
-        ZoneTableImpl::ZoneMap::const_iterator found =
-            impl_->zones.find(matchname);
-        if (found != impl_->zones.end()) {
-            return (FindResult(i == 0 ? result::SUCCESS :
-                               result::PARTIALMATCH, (*found).second));
-        }
-    }
-    return (FindResult(result::NOTFOUND, ConstZonePtr()));
+    return (impl_->findZone(name));
 }
+
 } // end of namespace datasrc
 } // end of namespace isc