Created
December 14, 2011 14:21
-
-
Save hideo55/1476764 to your computer and use it in GitHub Desktop.
sample code of ux::Map
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
#include <map> | |
#include <string> | |
#include <cstdlib> | |
#include <iostream> | |
#include <fstream> | |
#include <ux/ux.hpp> | |
using namespace std; | |
int main(int argc, char** argv){ | |
map<string, int> hashmap; | |
hashmap[string("foo")] = 1; | |
hashmap[string("bar")] = 10; | |
hashmap[string("baz")] = 100; | |
ux::Map<int> umap; | |
umap.build(hashmap); | |
ofstream os("index", ios::binary ); | |
if( umap.save(os) < 0 ){ | |
cerr << "Failed to save index" << endl; | |
exit(-1); | |
} | |
os.close(); | |
ifstream is("index", ios::binary); | |
ux::Map<int> other; | |
other.load(is); | |
int val; | |
string key = "bar"; | |
other.get(key.c_str(), key.size(), val); | |
assert( val == 10 ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment