Commit 196beb7d authored by Han Feng's avatar Han Feng
Browse files

modify the typedef name, remove invalid comments caused by implementation modification

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac397focused@3875 e5f2f494-b856-4b98-b285-d166d9295462
parent 9d98002c
......@@ -12,6 +12,10 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
/// \note Although the purpose of the RBTree is to provide a generic map with
/// domain name as key. Because of some unresolved design issue, the design and
/// interface is not fixed, RBTree isn't ready to be used as a base data sturct
/// by other modules.
#ifndef _RBTREE_H
#define _RBTREE_H 1
......@@ -59,20 +63,12 @@ class RBTree;
///
/// \note \c RBNode basically used internally by RBTree, it is meaningless to
/// inherited from it or create it without \c RBTree.
/// For data stored in \c RBNode, RBNode will hold the ownership, therefore RBNode
/// will release it(call the deconstructor)finally, so it will be has problem if two
/// RBNode store the same data, or the data RBNode managed is delete outside RBNode
/// both will cause double delete.
///
/// \todo It's really bad practce split the memory allocate and delete into seperate
/// classes, it's planed to add deleter functor as one template paremeter and
/// use it to release the data. but now let's just use this simple design
template <typename T>
class RBNode : public boost::noncopyable {
public:
/// only \c RBTree can create and destroy \c RBNode
friend class RBTree<T>;
typedef boost::shared_ptr<T> NodeDataType;
typedef boost::shared_ptr<T> NodeDataPtr;
/// \name Deonstructor
/// \note it's seems a little strange that constructor is private
......@@ -85,8 +81,7 @@ public:
/// \name Test functions
//@{
/// \brief return the name of current node, it's relative to its top node
///
/// \brief return the name of current node, it's relative to its top node ///
/// To get the absolute name of one node, the node path from the top node
/// to current node has to be recorded
const isc::dns::Name& getName() const { return (name_); }
......@@ -94,9 +89,9 @@ public:
/// \brief return the data store in this node
/// \note, since the data is managed by RBNode, developer should not
/// free the pointer
NodeDataType& getData() { return (data_); }
NodeDataPtr& getData() { return (data_); }
/// \brief return the data stored in this node, read-only version
const NodeDataType& getData() const { return (data_); }
const NodeDataPtr& getData() const { return (data_); }
/// \brief return whether the node has related data
/// \note it's meaningless has empty \c RBNode in one RBTree, the only
......@@ -108,7 +103,7 @@ public:
/// \name Modify functions
//@{
/// \breif set the data stored in the node
void setData(const NodeDataType& data) { data_ = data;}
void setData(const NodeDataPtr& data) { data_ = data;}
//@}
......@@ -116,7 +111,6 @@ private:
/// \brief Define rbnode color
enum RBNodeColor {BLACK, RED};
/// \name Constructors
/// \note \c Single RBNode is meaningless without living inside one \c RBTree
/// the creation and destroy of one \c RBNode is handle by host \c RBTree, so
......@@ -134,23 +128,20 @@ private:
RBNode(const isc::dns::Name& name);
//@}
/// This is a factory class method of a special singleton null node.
static RBNode<T>* NULL_NODE() {
static RBNode<T> null_node;
return (&null_node);
}
/// data to maintain the rbtree balance
RBNode<T>* parent_;
RBNode<T>* left_;
RBNode<T>* right_;
RBNodeColor color_;
isc::dns::Name name_;
NodeDataType data_;
NodeDataPtr data_;
/// the down pointer points to the root node of sub domains of current
/// domain
/// \par Adding down pointer to \c RBNode is for two purpose:
......@@ -615,7 +606,6 @@ RBTree<T>::leftRotate(RBNode<T>** root, RBNode<T>* node) {
return (node);
}
template <typename T>
RBNode<T>*
RBTree<T>::rightRotate(RBNode<T>** root, RBNode<T>* node) {
......
......@@ -52,27 +52,27 @@ class RBTreeTest : public::testing::Test {
protected:
RBTreeTest() : rbtree() {
rbtree.insert(Name("c"), &rbtnode);
rbtnode->setData(RBNode<int>::NodeDataType(new int(1)));
rbtnode->setData(RBNode<int>::NodeDataPtr(new int(1)));
rbtree.insert(Name("b"), &rbtnode);
rbtnode->setData(RBNode<int>::NodeDataType(new int(2)));
rbtnode->setData(RBNode<int>::NodeDataPtr(new int(2)));
rbtree.insert(Name("a"), &rbtnode);
rbtnode->setData(RBNode<int>::NodeDataType(new int(3)));
rbtnode->setData(RBNode<int>::NodeDataPtr(new int(3)));
rbtree.insert(Name("x.d.e.f"), &rbtnode);
rbtnode->setData(RBNode<int>::NodeDataType(new int(4)));
rbtnode->setData(RBNode<int>::NodeDataPtr(new int(4)));
rbtree.insert(Name("z.d.e.f"), &rbtnode);
rbtnode->setData(RBNode<int>::NodeDataType(new int(5)));
rbtnode->setData(RBNode<int>::NodeDataPtr(new int(5)));
rbtree.insert(Name("g.h"), &rbtnode);
rbtnode->setData(RBNode<int>::NodeDataType(new int(6)));
rbtnode->setData(RBNode<int>::NodeDataPtr(new int(6)));
rbtree.insert(Name("i.g.h"), &rbtnode);
rbtnode->setData(RBNode<int>::NodeDataType(new int(7)));
rbtnode->setData(RBNode<int>::NodeDataPtr(new int(7)));
rbtree.insert(Name("o.w.y.d.e.f"), &rbtnode);
rbtnode->setData(RBNode<int>::NodeDataType(new int(8)));
rbtnode->setData(RBNode<int>::NodeDataPtr(new int(8)));
rbtree.insert(Name("j.z.d.e.f"), &rbtnode);
rbtnode->setData(RBNode<int>::NodeDataType(new int(9)));
rbtnode->setData(RBNode<int>::NodeDataPtr(new int(9)));
rbtree.insert(Name("p.w.y.d.e.f"), &rbtnode);
rbtnode->setData(RBNode<int>::NodeDataType(new int(10)));
rbtnode->setData(RBNode<int>::NodeDataPtr(new int(10)));
rbtree.insert(Name("q.w.y.d.e.f"), &rbtnode);
rbtnode->setData(RBNode<int>::NodeDataType(new int(11)));
rbtnode->setData(RBNode<int>::NodeDataPtr(new int(11)));
}
RBTree<int> rbtree;
RBNode<int>* rbtnode;
......@@ -85,7 +85,7 @@ TEST_F(RBTreeTest, getNodeCount) {
}
TEST_F(RBTreeTest, setGetData) {
rbtnode->setData(RBNode<int>::NodeDataType(new int(11)));
rbtnode->setData(RBNode<int>::NodeDataPtr(new int(11)));
EXPECT_EQ(11, *(rbtnode->getData()));
}
......@@ -100,7 +100,7 @@ TEST_F(RBTreeTest, insertNames) {
EXPECT_EQ(RBTree<int>::SUCCEED, rbtree.insert(Name("example.com"), &rbtnode));
EXPECT_EQ(15, rbtree.getNodeCount());
rbtnode->setData(RBNode<int>::NodeDataType(new int(12)));
rbtnode->setData(RBNode<int>::NodeDataPtr(new int(12)));
// return ALREADYEXIST, since node "example.com" already has been explicitly inserted
EXPECT_EQ(RBTree<int>::ALREADYEXIST, rbtree.insert(Name("example.com"), &rbtnode));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment