-
Notifications
You must be signed in to change notification settings - Fork 0
/
intrusive_rb_tree.h
83 lines (73 loc) · 2.32 KB
/
intrusive_rb_tree.h
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
// Copyright © 2016 zendo (734181759@qq.com). All rights reserved.
#pragma once
#include "intrusive_hook.h"
namespace zendo
{
namespace detail
{
template<typename Hook>
class intrusive_rb_iterator : protected detail::rb_hook_access
{
using hook_ptr = Hook*;
hook_ptr nonius_;
void inc()
{
if( nonius_ )
{
hook_ptr r = right(nonius_);
if( r )
{
nonius_ = min(r);
}
else if( is_left_child(nonius_) )
{
nonius_ = parent(nonius_);
}
else
{
while( nonius_->is_right_child() )
{
nonius_ = parent(nonius_);
}
nonius_ = parent(nonius_);
}
}
}
void dec()
{
if( nonius_ )
{
hook_ptr l = left(nonius_);
if( l )
{
nonius_ = max(l);
}
else if( is_right_child(nonius_) )
{
nonius_ = parent(nonius_);
}
else
{
while( nonius_->is_left_child() )
nonius_ = nonius_->parent_;
nonius_ = nonius_->parent_;
}
}
}
};
template<typename Key, typename T, bool CacheSize, int Tag = 0>
class intrusive_rb_tree;
template<typename Key, typename T, int Tag>
class intrusive_rb_tree<Key, T, false, Tag> : protected detail::rb_hook_access
{
public:
using value_type = T;
using value_ptr = value_type*;
using key_type = Key;
using hook_type = rb_hook<Key, Tag>;
using hook_ptr = hook_type*;
static_assert(std::is_base_of<hook_type, T>::value, "");
private:
};
}
}