cheshirekow  v0.1.0
example_traits.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_BTPS_EXAMPLETRAITS_H_
28 #define MPBLOCKS_BTPS_EXAMPLETRAITS_H_
29 
30 #include <mpblocks/btps/node.h>
31 #include <cstdint>
32 
33 namespace mpblocks {
34 namespace btps {
35 
38 struct ExampleTraits {
39  struct Node;
40 
43  typedef Node* NodeRef;
44 
47  struct Node : BasicNode<ExampleTraits> {
48  Node(double weight = 0) : BasicNode<ExampleTraits>(weight), freq(0) {}
49 
50  uint32_t freq;
51  };
52 
55  struct NodeOps {
57  NodeRef& Parent(NodeRef N) { return N->parent; }
58 
60  NodeRef& LeftChild(NodeRef N) { return N->left; }
61 
63  NodeRef& RightChild(NodeRef N) { return N->right; }
64 
66  double Weight(NodeRef N) { return N->weight; }
67 
71  double& CumulativeWeight(NodeRef N) { return N->cumweight; }
72 
74  uint32_t& Count(NodeRef N) { return N->count; }
75  };
76 };
77 
78 } //< namespace btps
79 } //< namespace mpblocks
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 #endif // EXAMPLETRAITS_H_
NodeRef left
left child
Definition: node.h:44
double cumweight
cumulative weight of children
Definition: node.h:42
A node in a btps tree.
Definition: node.h:37
double & CumulativeWeight(NodeRef N)
return the cumulative weight of the subtree, the return type is deduced by the tree template and can ...
uint32_t & Count(NodeRef N)
return the subtree node count
a callable type which implements the primitives required to access fields of a node ...
uint32_t freq
number of times sampled
uint32_t count
count of subtree descendants
Definition: node.h:40
this type is not required by the interface, but if you just need a simple node type then this one wil...
NodeRef & LeftChild(NodeRef N)
return the left child of N
Node * NodeRef
some type which stores uniquely identifies nodes, for instance a node pointer or an index into an arr...
NodeRef & Parent(NodeRef N)
you can leave this one off you if you dont need removal
NodeRef right
right child
Definition: node.h:45
double weight
the weight of this node
Definition: node.h:41
NodeRef parent
only needed if we want removal
Definition: node.h:43
an example traits structure from which a balanced tree of partial sums may be instantiated ...
double Weight(NodeRef N)
return the weight of this node in particular
NodeRef & RightChild(NodeRef N)
return the right child of N