Skip to content

Instantly share code, notes, and snippets.

@hideo55
Created December 14, 2011 14:21
Show Gist options
  • Save hideo55/1476764 to your computer and use it in GitHub Desktop.
Save hideo55/1476764 to your computer and use it in GitHub Desktop.
sample code of ux::Map
#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