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

Last change on this file since 4071 was 4071, checked in by Peter, 20 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.3 KB
Line 
1#ifndef theplu_yat_utility_ranking_impl
2#define theplu_yat_utility_ranking_impl
3
4// $Id: Impl.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 "NodeBase.h"
28
29#include <cstddef>
30
31namespace theplu {
32namespace yat {
33namespace utility {
34
35  /// \cond IGNORE_DOXYGEN
36
37  // namespace for internal classes used in class Ranking
38  namespace ranking {
39
40    class Impl
41    {
42    public:
43      Impl(void);
44      Impl(const Impl& other) = delete;
45      Impl(Impl&& other);
46      Impl& operator=(const Impl& rhs) = delete;
47      Impl& operator=(Impl&& rhs);
48
49      // Head is the only node with no value. Its parent is the root
50      // node and the rest of the tree is in the left branch from the
51      // root. Also, it holds a link to the leftmost node, which
52      // corresponds to begin()
53      NodeBase head_;
54      // typically only called with assert, YAT_ASSERT or similar
55      bool validate(void) const;
56      // return number of nodes left of node, i.e., number of nodes
57      // with value less than node->value.
58      size_t ranking(const NodeBase* node) const;
59      void reset(void);
60      /*
61        \brief replace node with child
62
63       Function assumes that child can replace node without collision
64       or destrying the order in the tree, which means
65       if there is a node->left its value is <= child->value
66       if there is a node->right its value is <= child->value
67       if there is a node->left (ecl child) there is no child->left
68       if there is a node->right (excl child) there is no child->right
69      */
70      void relink(const NodeBase* node, NodeBase* child);
71    private:
72      void move_data(Impl&&);
73    };
74  } // end of namespace ranking
75
76  /// \endcond
77
78}}} // of namespace utility, yat, and theplu
79#endif
Note: See TracBrowser for help on using the repository browser.