Skip to content

Commit da223d0

Browse files
authored
Minor code cleanup, tweak explanation
1 parent e584a02 commit da223d0

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

veboas.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/*
22
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
58
69
Thanks to Jeff Erickson for suggesting the problem, and to John
710
Fischer and Yasutaka Furukawa for pointing out how to encode an
@@ -19,7 +22,7 @@ Leslie Wu
1922
using namespace std;
2023

2124
// Data
22-
char* veb_str = "HDLBACFEGJIKNMO";
25+
const char* veb_str = "HDLBACFEGJIKNMO";
2326

2427
inline int power_of_two(int exponent) { return 1 << exponent; }
2528

@@ -38,7 +41,7 @@ void hyper_compute(int n, int& d, int& D, int& subtree_size, int& subtree_leaf_c
3841
}
3942

4043
// 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)
4245
{
4346
int d, D, subtree_size, subtree_leaf_count;
4447
hyper_compute(length, d, D, subtree_size, subtree_leaf_count);
@@ -107,7 +110,7 @@ int main()
107110

108111
// To create implicit VEB structure, generate VEB addresses as satellite data,
109112
// tag, then sort
110-
char* alpha = "ABCDEFGHIJKLMNO";
113+
const char* alpha = "ABCDEFGHIJKLMNO";
111114

112115
int len = strlen(alpha);
113116
vector<pair<int,char> > indices(len);
@@ -117,7 +120,7 @@ int main()
117120
int idx = veb_index(i+1, power);
118121
indices[i] = make_pair(idx, alpha[i]);
119122
}
120-
sort(indices.begin(), indices.end());
123+
sort(begin(indices), end(indices));
121124

122125
for (i=0; i < len; i++) {
123126
std::cout << indices[i].second;
@@ -128,7 +131,7 @@ int main()
128131
// Search array
129132
int length = (int)strlen(veb_str);
130133

131-
char* search = "HDLBACFEGJIKNMOabc";
134+
const char* search = "HDLBACFEGJIKNMOabc";
132135
int search_len = (int)strlen(search);
133136

134137
for (int i=0; i < search_len; i++) {

0 commit comments

Comments
 (0)