From: Mukund Sivaraman Date: Mon, 26 Aug 2013 02:40:16 +0000 (+0530) Subject: [2750] Add non-const variant of find() X-Git-Tag: bind10-1.2.0beta1-release~193^2~4^2~70 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=79c66d327a479ff5d6dca45c17e438a404bc9dec;p=thirdparty%2Fkea.git [2750] Add non-const variant of find() --- diff --git a/src/lib/datasrc/memory/domaintree.h b/src/lib/datasrc/memory/domaintree.h index ffba88cf7f..47755f5d34 100644 --- a/src/lib/datasrc/memory/domaintree.h +++ b/src/lib/datasrc/memory/domaintree.h @@ -1279,6 +1279,19 @@ public: return (ret); } +private: + /// \brief Static helper function used by const and non-const + /// variants of find() below + template + static Result findImpl(TT* tree, + const isc::dns::LabelSequence& target_labels_orig, + TTN** target, + TTN* node, + DomainTreeNodeChain& node_path, + bool (*callback)(const DomainTreeNode&, CBARG), + CBARG callback_arg); + +public: /// \brief Find with callback and node chain /// \anchor callback /// @@ -1354,6 +1367,14 @@ public: /// \return As in the description, but in case of callback returning /// \c true, it returns immediately with the current node. template + Result find(const isc::dns::LabelSequence& target_labels_orig, + DomainTreeNode** node, + DomainTreeNodeChain& node_path, + bool (*callback)(const DomainTreeNode&, CBARG), + CBARG callback_arg); + + /// \brief Find with callback and node chain (const variant) + template Result find(const isc::dns::LabelSequence& target_labels_orig, const DomainTreeNode** node, DomainTreeNodeChain& node_path, @@ -1639,13 +1660,15 @@ DomainTree::deleteHelper(util::MemorySegment& mem_sgmt, } template -template +template typename DomainTree::Result -DomainTree::find(const isc::dns::LabelSequence& target_labels_orig, - const DomainTreeNode** target, - DomainTreeNodeChain& node_path, - bool (*callback)(const DomainTreeNode&, CBARG), - CBARG callback_arg) const +DomainTree::findImpl(TT* tree, + const isc::dns::LabelSequence& target_labels_orig, + TTN** target, + TTN* node, + DomainTreeNodeChain& node_path, + bool (*callback)(const DomainTreeNode&, CBARG), + CBARG callback_arg) { if (node_path.isEmpty() ^ target_labels_orig.isAbsolute()) { isc_throw(isc::BadValue, @@ -1653,17 +1676,6 @@ DomainTree::find(const isc::dns::LabelSequence& target_labels_orig, " and label sequence"); } - const DomainTreeNode* node; - - if (!node_path.isEmpty()) { - // Get the top node in the node chain - node = node_path.top(); - // Start searching from its down pointer - node = node->getDown(); - } else { - node = root_.get(); - } - Result ret = NOTFOUND; dns::LabelSequence target_labels(target_labels_orig); @@ -1674,7 +1686,7 @@ DomainTree::find(const isc::dns::LabelSequence& target_labels_orig, node_path.last_comparison_.getRelation(); if (relation == isc::dns::NameComparisonResult::EQUAL) { - if (needsReturnEmptyNode_ || !node->isEmpty()) { + if (tree->needsReturnEmptyNode_ || !node->isEmpty()) { node_path.push(node); *target = node; ret = EXACTMATCH; @@ -1687,7 +1699,7 @@ DomainTree::find(const isc::dns::LabelSequence& target_labels_orig, node->getLeft() : node->getRight(); } else { if (relation == isc::dns::NameComparisonResult::SUBDOMAIN) { - if (needsReturnEmptyNode_ || !node->isEmpty()) { + if (tree->needsReturnEmptyNode_ || !node->isEmpty()) { ret = PARTIALMATCH; *target = node; if (callback != NULL && @@ -1710,6 +1722,53 @@ DomainTree::find(const isc::dns::LabelSequence& target_labels_orig, return (ret); } +template +template +typename DomainTree::Result +DomainTree::find(const isc::dns::LabelSequence& target_labels_orig, + DomainTreeNode** target, + DomainTreeNodeChain& node_path, + bool (*callback)(const DomainTreeNode&, CBARG), + CBARG callback_arg) +{ + if (!node_path.isEmpty()) { + isc_throw(isc::BadValue, + "DomainTree::find() non-const method is given " + "non-empty node chain"); + } + + DomainTreeNode* node = root_.get(); + + return (findImpl, DomainTreeNode, CBARG > + (this, target_labels_orig, target, node, node_path, + callback, callback_arg)); +} + +template +template +typename DomainTree::Result +DomainTree::find(const isc::dns::LabelSequence& target_labels_orig, + const DomainTreeNode** target, + DomainTreeNodeChain& node_path, + bool (*callback)(const DomainTreeNode&, CBARG), + CBARG callback_arg) const +{ + const DomainTreeNode* node; + + if (!node_path.isEmpty()) { + // Get the top node in the node chain + node = node_path.top(); + // Start searching from its down pointer + node = node->getDown(); + } else { + node = root_.get(); + } + + return (findImpl, const DomainTreeNode, CBARG > + (this, target_labels_orig, target, node, node_path, + callback, callback_arg)); +} + template const DomainTreeNode* DomainTree::nextNode(DomainTreeNodeChain& node_path) const {