1
1
/*
2
2
3
- An implementation of the cache-oblivious implicit van Emde Boas binary
4
- tree data structure.
3
+ A cache-oblivious [0] version of a van Emde Boas search tree [1],
4
+ stored implicitly as an array.
5
+
6
+ 0: http://erikdemaine.org/papers/BRICS2002/paper.pdf
7
+ 1: https://en.wikipedia.org/wiki/Van_Emde_Boas_tree
5
8
6
9
Thanks to Jeff Erickson for suggesting the problem, and to John
7
10
Fischer and Yasutaka Furukawa for pointing out how to encode an
@@ -19,7 +22,7 @@ Leslie Wu
19
22
using namespace std ;
20
23
21
24
// Data
22
- char * veb_str = " HDLBACFEGJIKNMO" ;
25
+ const char * veb_str = " HDLBACFEGJIKNMO" ;
23
26
24
27
inline int power_of_two (int exponent) { return 1 << exponent; }
25
28
@@ -38,7 +41,7 @@ void hyper_compute(int n, int& d, int& D, int& subtree_size, int& subtree_leaf_c
38
41
}
39
42
40
43
// Implicit van Emde Boas binary search
41
- int veb_search (char * veb_array, int length, char elt)
44
+ int veb_search (const char * veb_array, int length, char elt)
42
45
{
43
46
int d, D, subtree_size, subtree_leaf_count;
44
47
hyper_compute (length, d, D, subtree_size, subtree_leaf_count);
@@ -107,7 +110,7 @@ int main()
107
110
108
111
// To create implicit VEB structure, generate VEB addresses as satellite data,
109
112
// tag, then sort
110
- char * alpha = " ABCDEFGHIJKLMNO" ;
113
+ const char * alpha = " ABCDEFGHIJKLMNO" ;
111
114
112
115
int len = strlen (alpha);
113
116
vector<pair<int ,char > > indices (len);
@@ -117,7 +120,7 @@ int main()
117
120
int idx = veb_index (i+1 , power);
118
121
indices[i] = make_pair (idx, alpha[i]);
119
122
}
120
- sort (indices. begin (), indices. end ());
123
+ sort (begin (indices ), end (indices ));
121
124
122
125
for (i=0 ; i < len; i++) {
123
126
std::cout << indices[i].second ;
@@ -128,7 +131,7 @@ int main()
128
131
// Search array
129
132
int length = (int )strlen (veb_str);
130
133
131
- char * search = " HDLBACFEGJIKNMOabc" ;
134
+ const char * search = " HDLBACFEGJIKNMOabc" ;
132
135
int search_len = (int )strlen (search);
133
136
134
137
for (int i=0 ; i < search_len; i++) {
0 commit comments