-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbasic_node.h
More file actions
64 lines (51 loc) · 1.41 KB
/
basic_node.h
File metadata and controls
64 lines (51 loc) · 1.41 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
#pragma once
#include "parlay/alloc.h"
using node_size_t = unsigned int;
//using node_size_t = size_t;
// *******************************************
// BASIC NODE
// *******************************************
template<class balance, class _ET>
struct basic_node {
using ET = _ET;
struct node : balance {
node* lc; node* rc;
ET entry;
node_size_t s;
node_size_t ref_cnt;
};
using allocator = parlay::type_allocator<node>;
static node_size_t size(node* a) {
return (a == NULL) ? 0 : a->s;
}
static void update(node* a) {
a->s = size(a->lc) + size(a->rc) + 1;
}
static node_size_t ref_cnt(node* a) {
return (a) ? a->ref_cnt : 0;
}
static node* make_node(ET e) {
node *o = allocator::alloc();
o->ref_cnt = 1;
//o->entry = e;
parlay::assign_uninitialized(o->entry,e);
return o;
}
static node* single(ET e) {
node* r = make_node(e);
r->lc = r->rc = NULL; r->s = 1;
return r;
}
static void free_node(node* a) {
(a->entry).~ET();
allocator::free(a);
}
static node* empty() {return NULL;}
inline static ET& get_entry(node *a) {return a->entry;}
inline static ET* get_entry_p(node *a) {return &(a->entry);}
static void set_entry(node *a, ET e) {a->entry = e;}
static node* left(node a) {return a.lc;}
static node* right(node a) {return a.rc;}
};
//template <class E>
//using node_type = basic_node<weight_balanced_tree, E>;