forked from LPD-EPFL/ASCYLIB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bst-drachsler.h
107 lines (79 loc) · 2.71 KB
/
bst-drachsler.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* File: bst-drachsler.h
* Author: Tudor David <[email protected]>
* Description: Dana Drachsler, Martin Vechev, and Eran Yahav.
* Practical Concurrent Binary Search Trees via Logical Ordering. PPoPP 2014.
* bst-drachsler.h is part of ASCYLIB
*
* Copyright (c) 2014 Vasileios Trigonakis <[email protected]>,
* Tudor David <[email protected]>
* Distributed Programming Lab (LPD), EPFL
*
* ASCYLIB is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, version 2
* of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _BST_DRACHLER_H_INCLUDED_
#define _BST_DRACHLER_H_INCLUDED_
#include <stdio.h>
#include <stdlib.h>
#include "utils.h"
#include "lock_if.h"
#include "common.h"
#include "atomic_ops_if.h"
#include "ssalloc.h"
#include "ssmem.h"
//#define DO_DRACHSLER_REBALANCE 1
#define DRACHSLER_RO_FAIL RO_FAIL
#define TRUE 1
#define FALSE 0
#define MAX_KEY KEY_MAX
#define MIN_KEY 0
#define max(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
typedef uint8_t bool_t;
extern __thread ssmem_allocator_t* alloc;
typedef ALIGNED(64) struct node_t node_t;
struct node_t {
volatile node_t* left;
volatile node_t* right;
volatile node_t* parent;
volatile node_t* succ;
volatile node_t* pred;
#ifdef DO_DRACHSLER_REBALANCE
int32_t left_height;
int32_t right_height;
#endif
ptlock_t tree_lock;
ptlock_t succ_lock;
skey_t key;
sval_t value;
bool_t mark;
char padding[96-5*sizeof(uintptr_t)-2*sizeof(ptlock_t)-sizeof(sval_t)-sizeof(skey_t)-sizeof(bool_t)];
};
node_t* initialize_tree();
node_t* bst_search(skey_t key, node_t* root);
sval_t bst_contains(skey_t k, node_t* root);
bool_t bst_insert(skey_t k, sval_t v, node_t* root);
node_t* choose_parent(node_t* pred, node_t* succ, node_t* first_cand);
void insert_to_tree(node_t* parent, node_t* new_node, node_t* root);
node_t* lock_parent(node_t* node);
sval_t bst_remove(skey_t key, node_t* root);
bool_t acquire_tree_locks(node_t* n);
void remove_from_tree(node_t* n, bool_t has_two_children, node_t* root);
void update_child(node_t *parent, node_t* old_ch, node_t* new_ch);
uint32_t bst_size(node_t* node);
#ifdef DO_DRACHSLER_REBALANCE
void bst_rebalance(node_t* node, node_t* child, node_t* root);
void bst_rotate(node_t* child, node_t* n, node_t* parent, bool_t left_rotation);
#endif
#endif