The SwappyItems Key-Values Store
Classes | Macros | Typedefs | Functions | Variables
SearchOnHibernateData.cpp File Reference
#include <cstdio>
#include <utility>
#include <chrono>
#include <inttypes.h>
#include <vector>
#include "SwappyItems.hpp"

Classes

struct  NodeData
 
struct  WayData
 
struct  PlaceData
 

Macros

#define FILE_ITEMS   ( 7*1024)
 
#define FILE_MULTI   6
 
#define RAM_MULTI   9
 
#define BBITS   5
 
#define BMASK   ((BBITS+4)* FILE_ITEMS)
 

Typedefs

typedef uint64_t Key
 
typedef SwappyItems< Key, WayData, FILE_ITEMS, FILE_MULTI, RAM_MULTI, BBITS, BMASKSwappyItemsWAYS
 
typedef SwappyItems< Key, NodeData, FILE_ITEMS, FILE_MULTI, RAM_MULTI, BBITS, BMASKSwappyItemsNODES
 
typedef SwappyItems< Key, PlaceData, FILE_ITEMS, FILE_MULTI, RAM_MULTI, BBITS, BMASKSwappyItemsPLACES
 

Functions

int main (int argc, char **argv)
 

Variables

SwappyItemsWAYSways
 
SwappyItemsNODESnodes
 
SwappyItemsPLACESplaces
 
std::chrono::time_point< std::chrono::system_clock > start
 
double mseconds
 

Macro Definition Documentation

◆ BBITS

#define BBITS   5

◆ BMASK

#define BMASK   ((BBITS+4)* FILE_ITEMS)

◆ FILE_ITEMS

#define FILE_ITEMS   ( 7*1024)

◆ FILE_MULTI

#define FILE_MULTI   6

◆ RAM_MULTI

#define RAM_MULTI   9

Typedef Documentation

◆ Key

typedef uint64_t Key

◆ SwappyItemsNODES

◆ SwappyItemsPLACES

◆ SwappyItemsWAYS

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
Examples
SearchOnHibernateData.cpp.
54  {
55  Key query = 103535041; // 185769837 // node 280319902
56  if (argc == 2) query = stol(argv[1]);
57  start = std::chrono::high_resolution_clock::now();
58 
59  ways = new SwappyItemsWAYS(23);
60  nodes = new SwappyItemsNODES(42);
61  places = new SwappyItemsPLACES(815);
62 
63  // get a way by key -------------------------------------------
64 
65  // std::pair<WayData, vector<Key> > * val = ways->get(query);
66  std::pair<NodeData, vector<Key> > * val = nodes->get(query);
67 
68  if (val == nullptr) {
69  printf("The '%lu' does not exist.\n", query);
70  } else {
71  //printf("Name of '%lu': %s\n", query, val->first._name);
72  //printf("Name of '%lu': %d\n", query, val->first._used);
73 
75  nodes->apply(nn, query, [](SwappyItemsNODES::Data * dat) {
76  // we can do anything to "dat", which is the data to key "r/2".
77  // the data is also written as copy via reference to "nn"
78  dat->first._used = 255;
79  });
80  printf("Name of '%lu': %d\n", query, nn.first._used);
81 
82  }
83  // ---------------------------------------------------------
84 
86  Key k2;
87  bool here = places->each(p, [&k2](Key key, SwappyItemsPLACES::Data & val) {
88  printf("each %d gets '%lu' %s\n", val.first._type, key, val.first._name);
89  k2 = key; // an other kind of "returning" a value
90  //val.first._type++; // change data works!!
91  // stop on true
92  return val.first._name[1] == 'o'; // the second letter must be a "o"
93  });
94  if (here) printf("found: '%lu' %s\n", k2, p.first._name);
95 
97  ways->each(w, [](Key key, SwappyItemsWAYS::Data & val) {
98  if (val.first._name[0] == 'A') {
99  printf("'%lu' with type %d has name %s\n", key, val.first._type, val.first._name);
100  for (auto k : val.second) {
101  printf(" ref '%lu'\n", k);
102  }
103  }
104  // all items, no stop
105  return false;
106  });
107 
109  nodes->each(n, [&w](Key nkey, SwappyItemsNODES::Data & val) {
110  if (val.first._used > 2) {
111  printf("%lu\n", nkey);
112  // Test node-each in a way-each
113  ways->each(w, [nkey](Key eKey, SwappyItemsWAYS::Data & eVal) {
114  // search the node-key in refs of all ways
115  for(Key r : eVal.second) {
116  // stop if found
117  if (r == nkey) {
118  printf(" in way %s\n", eVal.first._name);
119  return true;
120  }
121 
122  SwappyItemsNODES::Data nn;
123  // test a "special get", that does not confuse prio-queue and ram!
124  // we try to get a "random" key = r/2
125  bool rHalfExist = nodes->apply(nn, r/2, [](SwappyItemsNODES::Data * dat) {
126  // we can do anything to "dat", which is the data to key "r/2".
127  // the data is also written as copy via reference to "nn"
128  dat->first._lon = 99999;
129  });
130  if(rHalfExist) {
131  // we print a dot, if the half value of a ref key from a way exists in the nodes!
132  printf("'%lu' nn %lf\n", r, nn.first._lon);
133  }
134  }
135 
136  return false;
137  });
138  }
139 
140  // all items, no stop
141  return false;
142  });
143 
144  delete places;
145  delete ways;
146  delete nodes;
147 
148  auto now = std::chrono::high_resolution_clock::now();
149  mseconds = std::chrono::duration<double, std::milli>(now-start).count();
150  printf("# end: %.f ms\n", mseconds);
151  return 0;
152 }
SwappyItemsPLACES * places
Definition: SearchOnHibernateData.cpp:42
double mseconds
Definition: SearchOnHibernateData.cpp:47
SwappyItemsNODES * nodes
Definition: SearchOnHibernateData.cpp:41
SwappyItems< Key, WayData, FILE_ITEMS, FILE_MULTI, RAM_MULTI, BBITS, BMASK > SwappyItemsWAYS
Definition: SearchOnHibernateData.cpp:37
SwappyItems< Key, NodeData, FILE_ITEMS, FILE_MULTI, RAM_MULTI, BBITS, BMASK > SwappyItemsNODES
Definition: SearchOnHibernateData.cpp:38
SwappyItems< Key, PlaceData, FILE_ITEMS, FILE_MULTI, RAM_MULTI, BBITS, BMASK > SwappyItemsPLACES
Definition: SearchOnHibernateData.cpp:39
std::chrono::time_point< std::chrono::system_clock > start
Definition: SearchOnHibernateData.cpp:46
SwappyItemsWAYS * ways
Definition: SearchOnHibernateData.cpp:40
std::pair< TVALUE, std::vector< TKEY > > Data
Definition: SwappyItems.hpp:52
bool apply(Data &back, const TKEY &key, std::function< void(Data *)> foo)
Definition: SwappyItems.hpp:879
Data * get(const TKEY &key)
Definition: SwappyItems.hpp:188
bool each(Data &back, std::function< bool(TKEY, Data &)> foo)
Definition: SwappyItems.hpp:790
uint64_t Key
Definition: osm2graph.cpp:48

Variable Documentation

◆ mseconds

double mseconds

◆ nodes

◆ places

◆ start

std::chrono::time_point<std::chrono::system_clock> start

◆ ways