HPCToolkit
cskiplist.h
Go to the documentation of this file.
1 // * BeginRiceCopyright *****************************************************
2 //
3 // $HeadURL$
4 // $Id$
5 //
6 // --------------------------------------------------------------------------
7 // Part of HPCToolkit (hpctoolkit.org)
8 //
9 // Information about sources of support for research and development of
10 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
11 // --------------------------------------------------------------------------
12 //
13 // Copyright ((c)) 2002-2019, Rice University
14 // All rights reserved.
15 //
16 // Redistribution and use in source and binary forms, with or without
17 // modification, are permitted provided that the following conditions are
18 // met:
19 //
20 // * Redistributions of source code must retain the above copyright
21 // notice, this list of conditions and the following disclaimer.
22 //
23 // * Redistributions in binary form must reproduce the above copyright
24 // notice, this list of conditions and the following disclaimer in the
25 // documentation and/or other materials provided with the distribution.
26 //
27 // * Neither the name of Rice University (RICE) nor the names of its
28 // contributors may be used to endorse or promote products derived from
29 // this software without specific prior written permission.
30 //
31 // This software is provided by RICE and contributors "as is" and any
32 // express or implied warranties, including, but not limited to, the
33 // implied warranties of merchantability and fitness for a particular
34 // purpose are disclaimed. In no event shall RICE or contributors be
35 // liable for any direct, indirect, incidental, special, exemplary, or
36 // consequential damages (including, but not limited to, procurement of
37 // substitute goods or services; loss of use, data, or profits; or
38 // business interruption) however caused and on any theory of liability,
39 // whether in contract, strict liability, or tort (including negligence
40 // or otherwise) arising in any way out of the use of this software, even
41 // if advised of the possibility of such damage.
42 //
43 // ******************************************************* EndRiceCopyright *
44 
45 
46 
47 //******************************************************************************
48 //
49 // File: cskiplist.h
50 // $HeadURL$
51 //
52 // Purpose:
53 // Define an API for a concurrent skip list.
54 //
55 //******************************************************************************
56 
57 
58 #ifndef __CSKIPLIST_H__
59 #define __CSKIPLIST_H__
60 
61 //******************************************************************************
62 // global include files
63 //******************************************************************************
64 
65 #include <stdbool.h>
66 
67 //******************************************************************************
68 // local include files
69 //******************************************************************************
70 
71 #include "generic_val.h"
72 #include "mem_manager.h"
73 
74 //******************************************************************************
75 // macro
76 //******************************************************************************
77 
78 #define MAX_CSKIPLIST_STR 65536
79 #define OPAQUE_TYPE 0
80 //******************************************************************************
81 // abstract data type
82 //******************************************************************************
83 
84 #if OPAQUE_TYPE
85 
86 // opaque type not supported by gcc 4.4.*
87 typedef struct cskiplist_s cskiplist_t;
88 
89 #else
90 #include "cskiplist_defs.h"
91 #endif
92 
93 /*
94  * string representation of a node in the skip list.
95  */
96 typedef void (*cskl_node_tostr)(void* node_val, int node_height, int max_height,
97  char str[], int max_cskl_str_len);
98 
99 
100 //******************************************************************************
101 // interface operations
102 //******************************************************************************
103 
104 /*
105  * Inititalize mcs lock on global free csklnode list.
106  */
107 void
108 cskl_init();
109 
111 cskl_new(
112  void *lsentinel,
113  void *rsentinel,
114  int maxheight,
117  mem_alloc m_alloc);
118 
119 void
120 cskl_free(void* node);
121 
122 /*
123  * If cskl has a node that matches val then return that node's value,
124  * otherwise return NULL.
125  */
126 void*
127 cskl_cmp_find(cskiplist_t *cskl, void *val);
128 
129 
130 /*
131  * If cskl has a node that contains val then return that node's value,
132  * otherwise return NULL.
133  */
134 void*
135 cskl_inrange_find(cskiplist_t *cskl, void *val);
136 
137 csklnode_t *
138 cskl_insert(cskiplist_t *cskl, void *value,
139  mem_alloc m_alloc);
140 
141 bool
142 cskl_delete(cskiplist_t *cskl, void *value);
143 
144 bool
145 cskl_cmp_del_bulk_unsynch(cskiplist_t *cskl, void *low, void *high, mem_free m_free);
146 
147 bool
148 cskl_inrange_del_bulk_unsynch(cskiplist_t *cskl, void *low, void *high, mem_free m_free);
149 
150 
151 //******************************************************************************
152 // interface operations
153 //******************************************************************************
154 
155 /*
156  * print the levels for each node
157  */
158 void
159 cskl_levels_tostr (int height, int max_height, char str[],
160  int max_cskl_str_len);
161 
162 /*
163  * append the node string to the current cskiplist string
164  */
165 void
166 cskl_append_node_str(char nodestr[], char csklstr[], int max_cskl_str_len);
167 
168 /*
169  * compute a string representation of a cskiplist
170  * and return the result in the csklstr parameter.
171  */
172 void
173 cskl_tostr(cskiplist_t *cskl, cskl_node_tostr node_tostr,
174  char csklstr[], int max_cskl_str_len);
175 
176 void
177 cskl_dump(cskiplist_t *cskl, cskl_node_tostr node_tostr);
178 
179 void
180 cskl_print(cskiplist_t *cskl, cskl_node_tostr node_tostr);
181 
182 void
184 (
185  cskiplist_t *cskl, // cskiplist instance
186  cskl_node_tostr node_tostr // print node value
187 );
188 
189 #endif /* __CSKIPLIST_H__ */
void *(* mem_alloc)(size_t size)
Definition: mem_manager.h:17
void cskl_print(cskiplist_t *cskl, cskl_node_tostr node_tostr)
Definition: cskiplist.c:804
void(* cskl_node_tostr)(void *node_val, int node_height, int max_height, char str[], int max_cskl_str_len)
Definition: cskiplist.h:96
bool cskl_delete(cskiplist_t *cskl, void *value)
Definition: cskiplist.c:569
void cskl_append_node_str(char nodestr[], char csklstr[], int max_cskl_str_len)
Definition: cskiplist.c:697
void cskl_check_dump(cskiplist_t *cskl, cskl_node_tostr node_tostr)
Definition: cskiplist.c:861
cct_node_t * node
Definition: cct.c:128
int compare(SrcFile::ln x, SrcFile::ln y)
Definition: SrcFile.hpp:80
void cskl_free(void *node)
Definition: cskiplist.c:422
csklnode_t * cskl_insert(cskiplist_t *cskl, void *value, mem_alloc m_alloc)
Definition: cskiplist.c:483
void * cskl_cmp_find(cskiplist_t *cskl, void *val)
Definition: cskiplist.c:468
val_cmp inrange
void cskl_levels_tostr(int height, int max_height, char str[], int max_cskl_str_len)
Definition: cskiplist.c:678
cskiplist_t * cskl_new(void *lsentinel, void *rsentinel, int maxheight, val_cmp compare, val_cmp inrange, mem_alloc m_alloc)
Definition: cskiplist.c:441
int(* val_cmp)(void *lhs, void *rhs)
Definition: generic_val.h:32
void * cskl_inrange_find(cskiplist_t *cskl, void *val)
Definition: cskiplist.c:475
void cskl_init()
Definition: cskiplist.c:409
bool cskl_cmp_del_bulk_unsynch(cskiplist_t *cskl, void *low, void *high, mem_free m_free)
Definition: cskiplist.c:666
bool cskl_inrange_del_bulk_unsynch(cskiplist_t *cskl, void *low, void *high, mem_free m_free)
Definition: cskiplist.c:672
void cskl_tostr(cskiplist_t *cskl, cskl_node_tostr node_tostr, char csklstr[], int max_cskl_str_len)
Definition: cskiplist.c:706
void(* mem_free)(void *ptr)
Definition: mem_manager.h:18
void cskl_dump(cskiplist_t *cskl, cskl_node_tostr node_tostr)
Definition: cskiplist.c:760