forked from systemed/tilemaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsharded_way_store.cpp
More file actions
81 lines (63 loc) · 2 KB
/
sharded_way_store.cpp
File metadata and controls
81 lines (63 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "sharded_way_store.h"
#include "node_store.h"
thread_local size_t lastWayShard = 0;
ShardedWayStore::ShardedWayStore(std::function<std::shared_ptr<WayStore>()> createWayStore, const NodeStore& nodeStore):
createWayStore(createWayStore),
nodeStore(nodeStore) {
for (int i = 0; i < shards(); i++)
stores.push_back(createWayStore());
}
ShardedWayStore::~ShardedWayStore() {
}
void ShardedWayStore::reopen() {
for (auto& store : stores)
store->reopen();
}
void ShardedWayStore::batchStart() {
for (auto& store : stores)
store->batchStart();
}
std::vector<LatpLon> ShardedWayStore::at(WayID wayid) const {
for (int i = 0; i < shards(); i++) {
size_t index = (lastWayShard + i) % shards();
if (stores[index]->contains(0, wayid)) {
lastWayShard = index;
return stores[index]->at(wayid);
}
}
// Superfluous return to silence a compiler warning
return stores[shards() - 1]->at(wayid);
}
bool ShardedWayStore::requiresNodes() const {
return stores[0]->requiresNodes();
}
void ShardedWayStore::insertLatpLons(std::vector<WayStore::ll_element_t> &newWays) {
throw std::runtime_error("ShardedWayStore::insertLatpLons: don't call this directly");
}
void ShardedWayStore::insertNodes(const std::vector<std::pair<WayID, std::vector<NodeID>>>& newWays) {
throw std::runtime_error("ShardedWayStore::insertNodes: don't call this directly");
}
void ShardedWayStore::clear() {
for (auto& store : stores)
store->clear();
}
std::size_t ShardedWayStore::size() const {
size_t rv = 0;
for (auto& store : stores)
rv += store->size();
return rv;
}
void ShardedWayStore::finalize(unsigned int threadNum) {
for (auto& store : stores)
store->finalize(threadNum);
}
bool ShardedWayStore::contains(size_t shard, WayID id) const {
return stores[shard]->contains(0, id);
}
WayStore& ShardedWayStore::shard(size_t shard) {
return *stores[shard].get();
}
const WayStore& ShardedWayStore::shard(size_t shard) const {
return *stores[shard].get();
}
size_t ShardedWayStore::shards() const { return nodeStore.shards(); }