FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tilemaker/src/node_stores.cpp at master · cyclemap/tilemaker · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
cyclemap
/
tilemaker
Public
forked from
systemed/tilemaker
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
tilemaker
/
src
/
node_stores.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
116 lines (92 loc) · 3.06 KB
Breadcrumbs
tilemaker
/
src
/
node_stores.cpp
Copy path
File metadata and controls
116 lines (92 loc) · 3.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#
include
<
algorithm
>
#
include
<
boost/sort/sort.hpp
>
#
include
"
node_stores.h
"
void
BinarySearchNodeStore::reopen
()
{
std::lock_guard<std::mutex>
lock
(mutex);
for
(
auto
i =
0
; i <
mLatpLons
.
size
(); i++)
mLatpLons
[i]->
clear
();
mLatpLons
.
clear
();
for
(
auto
i =
0
; i <
NODE_SHARDS
; i++) {
mLatpLons
.
push_back
(std::make_unique<
map_t
>());
}
}
bool
BinarySearchNodeStore::contains
(
size_t
shard, NodeID i)
const
{
auto
internalShard =
mLatpLons
[
shardPart
(i)];
auto
id =
idPart
(i);
auto
iter =
std::lower_bound
(internalShard->
begin
(), internalShard->
end
(), id, [](
auto
const
&e,
auto
i) {
return
e.
first
< i;
});
return
!(iter == internalShard->
end
() || iter->
first
!= id);
}
LatpLon
BinarySearchNodeStore::at
(NodeID i)
const
{
auto
shard =
mLatpLons
[
shardPart
(i)];
auto
id =
idPart
(i);
auto
iter =
std::lower_bound
(shard->
begin
(), shard->
end
(), id, [](
auto
const
&e,
auto
i) {
return
e.
first
< i;
});
if
(iter == shard->
end
() || iter->
first
!= id)
throw
std::out_of_range
(
"
Could not find node with id
"
+
std::to_string
(i));
return
iter->
second
;
}
size_t
BinarySearchNodeStore::size
()
const
{
std::lock_guard<std::mutex>
lock
(mutex);
uint64_t
size =
0
;
for
(
auto
i =
0
; i <
mLatpLons
.
size
(); i++)
size +=
mLatpLons
[i]->
size
();
return
size;
}
void
BinarySearchNodeStore::insert
(
const
std::vector<
element_t
>& elements) {
uint32_t
newEntries[
NODE_SHARDS
] = {};
std::vector<
map_t
::iterator> iterators;
//
Before taking the lock, do a pass to find out how much
//
to grow each backing collection
for
(
auto
it = elements.
begin
(); it != elements.
end
(); it++) {
newEntries[
shardPart
(it->
first
)]++;
}
std::lock_guard<std::mutex>
lock
(mutex);
for
(
auto
i =
0
; i <
NODE_SHARDS
; i++) {
auto
size =
mLatpLons
[i]->
size
();
mLatpLons
[i]->
resize
(size + newEntries[i]);
iterators.
push_back
(
mLatpLons
[i]->
begin
() + size);
}
for
(
auto
it = elements.
begin
(); it != elements.
end
(); it++) {
uint32_t
shard =
shardPart
(it->
first
);
uint32_t
id =
idPart
(it->
first
);
*iterators[shard] =
std::make_pair
(id, it->
second
);
iterators[shard]++;
}
}
void
BinarySearchNodeStore::finalize
(
size_t
threadNum) {
std::lock_guard<std::mutex>
lock
(mutex);
for
(
auto
i =
0
; i <
NODE_SHARDS
; i++) {
boost::sort::block_indirect_sort
(
mLatpLons
[i]->
begin
(),
mLatpLons
[i]->
end
(),
[](
auto
const
&a,
auto
const
&b) {
return
a.
first
< b.
first
; },
threadNum);
}
}
void
CompactNodeStore::reopen
()
{
std::lock_guard<std::mutex>
lock
(mutex);
mLatpLons
= std::make_unique<
map_t
>();
}
LatpLon
CompactNodeStore::at
(NodeID i)
const
{
if
(i >=
mLatpLons
->
size
())
throw
std::out_of_range
(
"
Could not find node with id
"
+
std::to_string
(i));
return
mLatpLons
->
at
(i);
}
size_t
CompactNodeStore::size
()
const
{
std::lock_guard<std::mutex>
lock
(mutex);
return
mLatpLons
->
size
();
}
void
CompactNodeStore::insert
(
const
std::vector<
element_t
>& elements) {
std::lock_guard<std::mutex>
lock
(mutex);
for
(
auto
const
&i: elements)
insert_back
(i.
first
, i.
second
);
}
//
@brief Make the store empty
void
CompactNodeStore::clear
() {
std::lock_guard<std::mutex>
lock
(mutex);
mLatpLons
->
clear
();
}
Back
|
FazBrowse Home
|
New Git URL