-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.hpp
61 lines (49 loc) · 1.46 KB
/
node.hpp
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
//
// Created by juandiego on 4/14/23.
//
#ifndef AVL_FILE_NODE_HPP
#define AVL_FILE_NODE_HPP
#include <sstream>
#include "utils.hpp"
/// nullptr file representation
#define DISK_NULL (-1)
#define INITIAL_RECORD (0)
// for remove method purposes
#define DETACH (-2)
#define NOT_DETACH (-3)
template<typename KeyType>
struct Node {
KeyType key{};
long data_pointer = DISK_NULL;
long left = DISK_NULL;
long right = DISK_NULL;
long height = 0;
long next = DISK_NULL;
explicit Node() = default;
explicit Node(KeyType key_, long physical_position) : data_pointer(physical_position) {
func::copy(key, key_);
}
Node<KeyType> &operator=(const Node<KeyType> &other) {
func::copy(key, other.key);
next = other.next;
data_pointer = other.data_pointer;
return *this;
}
std::string to_string() {
std::stringstream ss;
ss << "<key: " << key << ", pointer: " << data_pointer << ", height: " << height << ", left: " << left
<< ", right: " << right << ", next: " << next << ">";
return ss.str();
}
};
template<typename RecordType>
std::ostream &operator<<(std::ostream &os, Node<RecordType> &node) {
os.write((char *) &node, sizeof(Node<RecordType>));
return os;
}
template<typename RecordType>
std::istream &operator>>(std::istream &is, Node<RecordType> &node) {
is.read((char *) &node, sizeof(Node<RecordType>));
return is;
}
#endif //AVL_FILE_NODE_HPP