Skip to content
Snippets Groups Projects
Commit 9a0de678 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

make tree_base use array instead of tuple

parent 813c34b0
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
#define VISITOR_HPP_
 
#include <alib/utility>
#include <alib/tuple>
 
namespace core {
 
......
......@@ -8,7 +8,7 @@
#ifndef __TREE_BASE_HPP_
#define __TREE_BASE_HPP_
 
#include "tuple.hpp"
#include "array.hpp"
#include "vector.hpp"
 
namespace ext {
......@@ -73,8 +73,8 @@ public:
 
template < class Data, int arity, class ConstData = Data, class Cast = Data >
class AnyaryNode {
typedef typename ext::TupleBuilder < Data, arity >::type ChildrenType;
typedef typename ext::TupleBuilder < ConstData, arity >::type ConstChildrenType;
typedef ext::array < Data, arity > ChildrenType;
typedef ext::array < ConstData, arity > ConstChildrenType;
 
union ChildrenUnion {
ChildrenType children;
......@@ -96,7 +96,7 @@ class AnyaryNode {
}
 
public:
AnyaryNode ( typename ext::TupleBuilder < Data, arity >::type c ) : children_union ( std::move ( c ) ) {
AnyaryNode ( ext::array < Data, arity > c ) : children_union ( std::move ( c ) ) {
setParent ( std::make_index_sequence < arity > ( ) );
}
 
......@@ -123,11 +123,11 @@ public:
return * this;
}
 
const typename ext::TupleBuilder < Data, arity >::type & getElements ( ) {
const ext::array < Data, arity > & getElements ( ) {
return children_union.children;
}
 
const typename ext::TupleBuilder < ConstData, arity >::type & getElements ( ) const {
const ext::array < ConstData, arity > & getElements ( ) const {
return children_union.const_children;
}
 
......@@ -141,7 +141,7 @@ public:
return std::get < N > ( children_union.children );
}
 
void setElements ( typename ext::TupleBuilder < Data, arity >::type c ) {
void setElements ( ext::array < Data, arity > c ) {
children_union.children = std::move ( c );
setParent ( std::make_index_sequence < arity > ( ) );
}
......@@ -157,7 +157,7 @@ public:
template < class Data, class ConstData = Data, class Cast = Data >
class NullaryNode : public AnyaryNode < Data, 0, ConstData, Cast > {
public:
NullaryNode ( ) : AnyaryNode < Data, 0, ConstData, Cast > ( ext::tuple < > ( ) ) {
NullaryNode ( ) : AnyaryNode < Data, 0, ConstData, Cast > ( ext::make_array < Data > ( ) ) {
}
 
};
......@@ -165,7 +165,7 @@ public:
template < class Data, class ConstData = Data, class Cast = Data >
class UnaryNode : public AnyaryNode < Data, 1, ConstData, Cast > {
public:
UnaryNode ( Data c ) : AnyaryNode < Data, 1, ConstData, Cast > ( ext::make_tuple ( std::move ( c ) ) ) {
UnaryNode ( Data c ) : AnyaryNode < Data, 1, ConstData, Cast > ( ext::make_array ( std::move ( c ) ) ) {
}
 
Data & getChild ( ) {
......@@ -185,7 +185,7 @@ public:
template < class Data, class ConstData = Data, class Cast = Data >
class BinaryNode : public AnyaryNode < Data, 2, ConstData, Cast > {
public:
BinaryNode ( Data l, Data r ) : AnyaryNode < Data, 2, ConstData, Cast > ( ext::make_tuple ( std::move ( l ), std::move ( r ) ) ) {
BinaryNode ( Data l, Data r ) : AnyaryNode < Data, 2, ConstData, Cast > ( ext::make_array ( std::move ( l ), std::move ( r ) ) ) {
}
 
Data & getLeft ( ) {
......@@ -217,7 +217,7 @@ public:
template < class Data, class ConstData = Data, class Cast = Data >
class TernaryNode : public AnyaryNode < Data, 3, ConstData, Cast > {
public:
TernaryNode ( Data f, Data s, Data t ) : AnyaryNode < Data, 3, ConstData, Cast > ( ext::make_tuple ( std::move ( f ), std::move ( s ), std::move ( t ) ) ) {
TernaryNode ( Data f, Data s, Data t ) : AnyaryNode < Data, 3, ConstData, Cast > ( ext::make_array ( std::move ( f ), std::move ( s ), std::move ( t ) ) ) {
}
 
Data & getFirst ( ) {
......@@ -480,7 +480,7 @@ public:
}
 
template < int arity >
static void setChildren ( const AnyaryNode < Data, arity, ConstData, Cast > & node, typename ext::TupleBuilder < Data, arity >::type children ) {
static void setChildren ( const AnyaryNode < Data, arity, ConstData, Cast > & node, ext::array < Data, arity > children ) {
const_cast < AnyaryNode < Data, arity, ConstData, Cast > & > ( node ).setChildren ( std::move ( children ) );
}
 
......
#include "ForwardTreeTest.h"
#include <alib/vector>
#include <alib/deque>
#include <alib/tuple>
 
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( ForwardTreeTest, "bits" );
CPPUNIT_TEST_SUITE_REGISTRATION ( ForwardTreeTest );
......
#include "TreeTest.h"
 
#include <alib/tuple>
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( TreeTest, "bits" );
CPPUNIT_TEST_SUITE_REGISTRATION ( TreeTest );
 
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment