traversal_node.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024-2025, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 #include <cstddef>
18 #include <exception>
19 #include <string>
20 
21 namespace ML {
22 namespace forest {
23 
25 struct parentless_node_exception : std::exception {
26  parentless_node_exception() : msg_{"Node does not track its parent"} {}
27  parentless_node_exception(std::string msg) : msg_{msg} {}
28  parentless_node_exception(char const* msg) : msg_{msg} {}
29  virtual char const* what() const noexcept { return msg_.c_str(); }
30 
31  private:
32  std::string msg_;
33 };
34 
35 template <typename id_t = std::size_t>
37  public:
38  using id_type = id_t;
39  virtual bool is_leaf() const = 0;
40  virtual id_type hot_child() const = 0;
41  virtual id_type distant_child() const = 0;
42  virtual id_type parent() const
43  {
45  return id_type{};
46  }
47 };
48 
49 } // namespace forest
50 } // namespace ML
Definition: dbscan.hpp:29
Definition: traversal_node.hpp:25
virtual char const * what() const noexcept
Definition: traversal_node.hpp:29
parentless_node_exception(std::string msg)
Definition: traversal_node.hpp:27
parentless_node_exception(char const *msg)
Definition: traversal_node.hpp:28
parentless_node_exception()
Definition: traversal_node.hpp:26
Definition: traversal_node.hpp:36
virtual bool is_leaf() const =0
virtual id_type parent() const
Definition: traversal_node.hpp:42
virtual id_type distant_child() const =0
id_t id_type
Definition: traversal_node.hpp:38
virtual id_type hot_child() const =0