Fleet  0.0.9
Inference in the LOT
Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
Node Class Reference

#include <Node.h>

Inheritance diagram for Node:
Inheritance graph
[legend]
Collaboration diagram for Node:
Collaboration graph
[legend]

Public Member Functions

 Node (const Rule *r=nullptr, double _lp=0.0, bool cr=true)
 
 Node (const Node &n)
 
 Node (Node &&n)
 
virtual ~Node ()
 
void assign (Node &n)
 Assign will set everything to n BUT it will not copy the parent points etc since we're assuming this node is staying in the same place. More...
 
void assign (Node &&n)
 
const std::string & format () const
 
nonterminal_t type (const size_t i) const
 
void set_child (const size_t i, Node &n)
 
void set_child (const size_t i, Node &&n)
 
void operator= (const Node &n)
 
void operator= (Node &&n)
 
bool operator< (const Node &n) const
 
nonterminal_t nt () const
 
bool is_null () const
 
virtual size_t count_nonnull () const
 
virtual bool is_complete () const
 
virtual std::string string (bool usedot=true) const override
 
virtual std::string parseable () const
 
template<typename VirtualMachineState_t , typename Grammar_t >
int linearize (Program< VirtualMachineState_t > &program) const
 
virtual bool operator== (const Node &n) const override
 
virtual size_t hash (size_t depth=0) const
 
virtual void fullprint (size_t tab=0)
 A function to print out everything, for debugging purposes. More...
 
- Public Member Functions inherited from BaseNode< Node >
 BaseNode (size_t n=0, Node *p=nullptr, size_t i=0)
 Constructor of basenode – sizes children to n. More...
 
 BaseNode (const Node &n)
 
 BaseNode (Node &&n)
 
void operator= (const Node &t)
 
void operator= (const Node &&t)
 
void make_root ()
 Make a node root – just nulls the parent. More...
 
virtual ~BaseNode ()
 
virtual std::string my_string () const
 
NodeIterator begin () const
 
NodeIterator end () const
 
virtual bool operator!= (const Node &n) const
 
void reserve_children (const size_t n)
 
decltype(children) & get_children ()
 
decltype(children) const & get_children () const
 
Nodechild (const size_t i)
 
const Nodechild (const size_t i) const
 
void fill (size_t n, Args... args)
 
size_t nchildren () const
 
Nodeleft_descend () const
 
size_t depth () const
 
void fix_child_info ()
 
void check_child_info () const
 
Nodeoperator[] (const size_t i)
 
const Nodeoperator[] (const size_t i) const
 
void set_child (const size_t i, Node &n)
 
void set_child (const size_t i, Node &&n)
 
void push_back (Node &n)
 
void push_back (Node &&n)
 
virtual bool is_root () const
 Am I a root node? I am if my parent is nullptr. More...
 
Noderoot ()
 Find the root of this node by walking up the tree. More...
 
Nodeget_via (std::function< bool(Node &)> &f)
 Return a pointer to the first node satisfying predicate f, in standard traversal; nullptr otherwise. More...
 
virtual size_t count () const
 How many nodes total are below me? More...
 
virtual size_t count (const Node &n) const
 How many nodes below me are equal to n? More...
 
virtual bool is_terminal () const
 Am I a terminal? I am if I have no children. More...
 
virtual size_t count_terminals () const
 
virtual Nodeget_nth (int n, std::function< int(const Node &)> &f)
 
virtual Nodeget_nth (int n)
 
sum (std::function< T(const Node &)> &f) const
 
sum (T(*f)(const Node &)) const
 
bool all (std::function< bool(const Node &)> &f) const
 
void map (const std::function< void(Node &)> &f)
 
void show (size_t t=0) const
 

Public Attributes

const Rulerule
 
double lp
 
bool can_resample
 
- Public Attributes inherited from BaseNode< Node >
Nodeparent
 
size_t pi
 

Static Public Attributes

static const char NTDelimiter = ':'
 
static const char RuleDelimiter = ';'
 
- Static Public Attributes inherited from BaseNode< Node >
static NodeIterator EndNodeIterator
 

Friends

class BaseNode< Node >
 

Additional Inherited Members

- Protected Attributes inherited from BaseNode< Node >
std::vector< Nodechildren
 

Detailed Description

Author
Steven Piantadosi
Date
22/10/21

Constructor & Destructor Documentation

◆ Node() [1/3]

Node::Node ( const Rule r = nullptr,
double  _lp = 0.0,
bool  cr = true 
)
inline

◆ Node() [2/3]

Node::Node ( const Node n)
inline

◆ Node() [3/3]

Node::Node ( Node &&  n)
inline

◆ ~Node()

virtual Node::~Node ( )
inlinevirtual

Member Function Documentation

◆ assign() [1/2]

void Node::assign ( Node n)
inline

Assign will set everything to n BUT it will not copy the parent points etc since we're assuming this node is staying in the same place.

Parameters
n

◆ assign() [2/2]

void Node::assign ( Node &&  n)
inline

◆ count_nonnull()

virtual size_t Node::count_nonnull ( ) const
inlinevirtual

How many nodes total are below me?

Parameters
n
Returns

◆ format()

const std::string& Node::format ( ) const
inline

◆ fullprint()

virtual void Node::fullprint ( size_t  tab = 0)
inlinevirtual

A function to print out everything, for debugging purposes.

Parameters
tab

◆ hash()

virtual size_t Node::hash ( size_t  depth = 0) const
inlinevirtual

Hash a tree by hashing the rule and everything below.

Parameters
depth
Returns

◆ is_complete()

virtual bool Node::is_complete ( ) const
inlinevirtual

A tree is complete if it contains no null nodes below it.

Returns

◆ is_null()

bool Node::is_null ( ) const
inline

Am I a null node?

Returns

◆ linearize()

template<typename VirtualMachineState_t , typename Grammar_t >
int Node::linearize ( Program< VirtualMachineState_t > &  program) const
inline

convert tree to a linear sequence of operations. To do this, we first linearize the kids, leaving their values as the top on the stack then we compute our value, remove our kids' values to clean up the stack, and push on our return the only fanciness is for if: here we will use the following layout <TOP of="" stack>=""> <bool> op_IF(xsize) X-branch JUMP(ysize) Y-branch

NOTE: Inline here lets gcc inline a few recursions of this function, which ends up speeding us up a bit (otherwise recursive inlining only happens at -O3) This optimization is why we do set max-inline-insns-recursive in Fleet.mk

Parameters
ops
Returns
This returns the size of the program that was pushed onto ops. This is useful for saving us lots of calls to program_size, which ends up being an important optimization.

◆ nt()

nonterminal_t Node::nt ( ) const
inline

What nonterminal type do I return?

Returns

◆ operator<()

bool Node::operator< ( const Node n) const
inline

◆ operator=() [1/2]

void Node::operator= ( const Node n)
inline

◆ operator=() [2/2]

void Node::operator= ( Node &&  n)
inline

◆ operator==()

virtual bool Node::operator== ( const Node n) const
inlineoverridevirtual

Check equality between notes. Note this compares rule objects.

Parameters
n
Returns

Reimplemented from BaseNode< Node >.

◆ parseable()

virtual std::string Node::parseable ( ) const
inlinevirtual

Create a string that can be parsed according to Grammar.from_parseable

Returns

◆ set_child() [1/2]

void Node::set_child ( const size_t  i,
Node n 
)
inline

Set my child to n. NOTE: This one needs to be used, rather than accessing children directly, because we have to set parent pointers and indices.

Parameters
i
n

◆ set_child() [2/2]

void Node::set_child ( const size_t  i,
Node &&  n 
)
inline

Set my child to n. NOTE: This one needs to be used, rather than accessing children directly, because we have to set parent pointers and indices.

Parameters
i
n

◆ string()

virtual std::string Node::string ( bool  usedot = true) const
inlineoverridevirtual

Convert a tree to a string, using each node's format.

Parameters
usedot- do we print a dot in front of pieces of nodes that cannot be resampled? Useful for mcts
Returns

Reimplemented from BaseNode< Node >.

◆ type()

nonterminal_t Node::type ( const size_t  i) const
inline

Return the type of the i'th child

Parameters
i
Returns

Friends And Related Function Documentation

◆ BaseNode< Node >

friend class BaseNode< Node >
friend

Member Data Documentation

◆ can_resample

bool Node::can_resample

◆ lp

double Node::lp

◆ NTDelimiter

const char Node::NTDelimiter = ':'
static

◆ rule

const Rule* Node::rule

◆ RuleDelimiter

const char Node::RuleDelimiter = ';'
static

The documentation for this class was generated from the following file: