source: branches/kendall-score/yat/utility/ranking/NodeBase.h @ 4071

Last change on this file since 4071 was 4071, checked in by Peter, 19 months ago

Add variables height_ and size_ in NodeBase?, which describes the longest distance to its leaves and the size of the subtree in which it is the root, respectively. Use these variables to calculate the ranking, which means the ranking now scales like the height rather than the number of nodes. refs #710

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1#ifndef theplu_yat_utility_detail_node_base
2#define theplu_yat_utility_detail_node_base
3
4// $Id: NodeBase.h 4071 2021-08-18 02:31:29Z peter $
5
6/*
7  Copyright (C) 2021 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25// This is a private file used by yat/utility/Ranking.h
26
27#include <cstddef>
28
29namespace theplu {
30namespace yat {
31namespace utility {
32
33  /// \cond IGNORE_DOXYGEN
34
35  // namespace for internal classes used in class Ranking
36  namespace ranking {
37
38    class NodeBase
39    {
40    public:
41      NodeBase(void);
42      virtual ~NodeBase(void);
43      NodeBase* parent_;
44      NodeBase* left_;
45      NodeBase* right_;
46      unsigned int height_; // max distance to leaf (plus 1)
47      // number of total offsprings including myself
48      size_t size_;
49
50      // return 0 for root, 1 for its children, etc
51      int generation(void) const;
52
53      // increase size of node and parent node, recursively.
54      void increment_size(void);
55      // decrease size of node and parent node, recursively.
56      void decrement_size(void);
57
58      void update_height(void);
59
60      // return true if head node
61      bool is_head_node(void) const;
62      // return true if having a parent and its left child is this
63      bool is_left_node(void) const;
64      // return true if having a parent and its right child is this
65      bool is_right_node(void) const;
66      // return true if having no parent
67      bool is_root_node(void) const;
68      // return traverse up in the tree following the left branch
69      // until a node has no left branch and we return that leaf node.
70      NodeBase* left_most(void);
71      const NodeBase* left_most(void) const;
72      // same as left_most but follow right branch
73      NodeBase* right_most(void);
74      const NodeBase* right_most(void) const;
75      // Only used to validate that the tree is valid, used in debug
76      // code and assertions.
77      bool validate(void) const;
78      bool recursive_validate(void) const;
79    };
80
81    size_t height(const NodeBase* node);
82    size_t size(const NodeBase* node);
83
84  } // end of namespace ranking
85
86  /// \endcond
87
88}}} // of namespace utility, yat, and theplu
89#endif
Note: See TracBrowser for help on using the repository browser.