Repository navigation
Expand file tree
/
Copy pathnode.h
More file actions
83 lines (75 loc) · 2.47 KB
/
Copy pathnode.h
File metadata and controls
83 lines (75 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef NODE_H
#define NODE_H
#include <array>
#include <memory>
#include <cstdint>
#include <string>
#include "matrixprocessor.h"
#include "bitmult.h"
//forward declaration of the Quadtree class because we're
// using statics now
const int NUM_CHILDREN = 4;
const int MIN_SIZE = 8;
const int BLOCK_DIM = 2;
const int ROW_LENGTH = 8;
/**
* So the Link constructor and destructor got implicitly
* deleted because they weren't happy that the
* Node class has a non-trivial default constructor.
* I get that it's not trivial because it involves initialising that array
*
* but I am not sure how or if it's possible to get the variant
* field 'node' to still have a non-trivial default constructor and have this still work
*
*
* I remember them mentioning something about having to implement all the stuff for yourself
* and then it will be fine
*
* If a union contains a non-static data member with a non-trivial
* special member function (copy/move constructor, copy/move assignment,
* or destructor), that function is deleted by default in the union and needs
* to be defined explicitly by the programmer.
* If a union contains a non-static data member with a non-trivial default constructor,
* the default constructor of the union is deleted by default unless a variant member
* of the union has a default member initializer .
*
*
*/
class Node;
typedef union Link {
Link();
~Link();
uint64_t leafMatrix;
std::unique_ptr<Node> node;
} Link;
class Node {
public:
Node();
void* operator new(size_t size) noexcept {
// the user made a new node so pls record it
Node::currentUsage++;
// do a max check
if (Node::currentUsage > Node::maxUsage)
Node::maxUsage = Node::currentUsage;
void* p = std::malloc(size);
return p;
}
bool at(size_t i, size_t j, size_t distanceFromLeaf);
// this method fetches a node child, NOT a boolean value
Node *get(size_t i, size_t j);
static std::unique_ptr<Node> Construct(std::string s);
std::unique_ptr<Node> Clone(size_t distanceFromLeaf);
// methods of traversal! make it now
static std::unique_ptr<Node> Union(Node* const A, Node* const B, size_t distanceFromLeaf);
static std::unique_ptr<Node> Product(Node* const A, Node* const B, size_t distanceFromLeaf);
void operator delete(void* p) noexcept {
Node::currentUsage--;
std::free(p);
}
//members
public:
std::array<Link, NUM_CHILDREN> children;
static int maxUsage;
static int currentUsage;
};
#endif // NODE_H