-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2313560
commit 53e0eb7
Showing
4 changed files
with
155 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rmi* | ||
test | ||
stdout | ||
result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
result: test | ||
$(shell ./test > stdout) | ||
echo $(.SHELLSTATUS) > result | ||
cat stdout >> result | ||
|
||
rmi.cpp: ../rmi | ||
../rmi ../wiki_ts_200M_uint64 rmi radix,linear 1024 | ||
|
||
test: main.cpp rmi.cpp | ||
# -lstdc++fs is required for ancient G++s | ||
g++ -std=c++17 -Wall -O3 -ffast-math -march=native main.cpp rmi.cpp -o test -lstdc++fs | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf test result rmi* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <vector> | ||
#include <iostream> | ||
#include <fstream> | ||
#include "rmi.h" | ||
|
||
int main() { | ||
// load the data | ||
std::vector<uint64_t> data; | ||
std::ifstream in("../wiki_ts_200M_uint64", | ||
std::ios::binary); | ||
|
||
// Read size. | ||
uint64_t size; | ||
in.read(reinterpret_cast<char*>(&size), sizeof(uint64_t)); | ||
data.resize(size); | ||
// Read values. | ||
in.read(reinterpret_cast<char*>(data.data()), size*sizeof(uint64_t)); | ||
in.close(); | ||
|
||
std::cout << "Data loaded." << std::endl; | ||
|
||
std::cout << "RMI status: " << rmi::load("rmi_data") << std::endl; | ||
|
||
size_t err; | ||
|
||
for (uint64_t key_index = 0; key_index < size; key_index++) { | ||
uint64_t lookup = data[key_index]; | ||
uint64_t true_index = (uint64_t) | ||
std::distance(data.begin(), std::lower_bound(data.begin(), | ||
data.end(), | ||
lookup)); | ||
uint64_t rmi_guess = rmi::lookup(lookup, &err); | ||
|
||
uint64_t diff = (rmi_guess > true_index ? rmi_guess - true_index : true_index - rmi_guess); | ||
if (diff > err) { | ||
std::cout << "Search key: " << lookup | ||
<< " Key at " << true_index << ": " << data[true_index] | ||
<< " RMI guess: " << rmi_guess << " +/- " << err | ||
<< " diff: " << diff << std::endl; | ||
exit(-1); | ||
} | ||
} | ||
|
||
rmi::cleanup(); | ||
exit(0); | ||
} |