forked from LPD-EPFL/ASCYLIB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashtable-lock.h
71 lines (62 loc) · 2.33 KB
/
hashtable-lock.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
/*
* File: hashtable-lock.h
* Author: Vincent Gramoli <[email protected]>,
* Vasileios Trigonakis <[email protected]>
* Description: one hand-over-hand locking list per bucket
* (Details: Maurice Herlihy and Nir Shavit. The Art of
* Multiprocessor Programming, Revised First Edition. 2012.)
* hashtable-lock.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.
*
*/
#include "./lists/intset.h"
#define DEFAULT_MOVE 0
#define DEFAULT_SNAPSHOT 0
#define DEFAULT_LOAD 1
#define DEFAULT_ELASTICITY 1
#define DEFAULT_ALTERNATE 0
#define DEFAULT_EFFECTIVE 1
#define MAXHTLENGTH 65536
/* Hashtable length (# of buckets) */
extern unsigned int maxhtlength;
/* ################################################################### *
* HASH TABLE
* ################################################################### */
typedef struct ht_intset
{
size_t hash;
intset_l_t* buckets;
ptlock_t* locks;
uint8_t padding[CACHE_LINE_SIZE - 24];
} ht_intset_t;
void ht_delete(ht_intset_t *set);
int ht_size(ht_intset_t *set);
int floor_log_2(unsigned int n);
ht_intset_t *ht_new();
sval_t ht_contains(ht_intset_t* set, skey_t key);
int ht_add(ht_intset_t* set, skey_t key, sval_t val);
sval_t ht_remove(ht_intset_t* set, skey_t key);
/*
* Move an element in the hashtable (from one linked-list to another)
*/
int ht_move(ht_intset_t *set, int val1, int val2);
/*
* Read all elements of the hashtable (parses all linked-lists)
* This cannot be consistent when used with move operation.
* TODO: make a coarse-grain version of the snapshot.
*/
int ht_snapshot(ht_intset_t *set);
#define IO_FLUSH fflush(stdout)