Skip to content

Instantly share code, notes, and snippets.

@quiye
Last active March 16, 2018 15:52
Show Gist options
  • Save quiye/c11fc81a0832420abc112c2952b73711 to your computer and use it in GitHub Desktop.
Save quiye/c11fc81a0832420abc112c2952b73711 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<fstream>
#include<sstream>
#include <k2hash/k2hash.h>
#include <k2hash/k2hshm.h>
using namespace std;
int main(){
K2HShm k;
cout << k.GetSystemPageSize() << endl;
bool isCppCreated = k.Create("/tmp/testcpp.k2h");
cout<<(isCppCreated ? "already ..." : "now created!")<<endl;
k.Attach("/tmp/testcpp.k2h",false);
k.Set("tako", "僕は磯に住むタコだよ🐙");
k.Set("ika", "僕は磯に住むイカだよくコ:彡");
cout << k.GetSystemPageSize() << endl;
cout << k.GetK2hashFilePath() << endl;
cout << k.Get("tako") << endl;
cout<<(k.Get("tako") ? "GET" : "NOT GET")<<endl;
ifstream ifs("yubin.csv");
string s,out;
while(getline(ifs,s)){
stringstream ss(s);
vector<string> vs;
while(getline(ss, out, ',')) vs.push_back(out);
const char* key = &vs[0][0];
const char* val = &vs[1][0];
k.Set(key,val);
}
cout << k.Get("\"4100004\"") << endl;
k.Detach();
cout<<(k.Get("tako") ? "GET" : "NOT GET")<<endl;
}
@quiye
Copy link
Author

quiye commented Mar 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment