File: node_stores.h

package info (click to toggle)
tilemaker 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 78,284 kB
  • sloc: cpp: 28,715; ansic: 4,052; makefile: 180; ruby: 77; sh: 6
file content (86 lines) | stat: -rw-r--r-- 2,431 bytes parent folder | download
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
#ifndef _NODE_STORES_H
#define _NODE_STORES_H

#include <mutex>
#include <memory>
#include "node_store.h"
#include "sorted_node_store.h"
#include "sharded_node_store.h"
#include "mmap_allocator.h"

class BinarySearchNodeStore : public NodeStore
{

public:
	using internal_element_t = std::pair<ShardedNodeID, LatpLon>;
	using map_t = std::deque<internal_element_t, mmap_allocator<internal_element_t>>;

	void reopen() override;
	void finalize(size_t threadNum) override;
	LatpLon at(NodeID i) const override;
	size_t size() const override;
	void insert(const std::vector<element_t>& elements) override;
	void clear() override {
		reopen();
	}
	void batchStart() override {}

	bool contains(size_t shard, NodeID id) const override;
	NodeStore& shard(size_t shard) override { return *this; }
	const NodeStore& shard(size_t shard) const override { return *this; }
	size_t shards() const override { return 1; }
	

private: 
	mutable std::mutex mutex;
	std::vector<std::shared_ptr<map_t>> mLatpLons;

	uint32_t shardPart(NodeID id) const {
		uint32_t rv = id >> 32;
		return rv;
	}

	uint32_t idPart(NodeID id) const { return id; }
};

class CompactNodeStore : public NodeStore
{

public:
	using element_t = std::pair<NodeID, LatpLon>;
	using map_t = std::deque<LatpLon, mmap_allocator<LatpLon>>;

	void reopen() override;
	LatpLon at(NodeID i) const override;
	size_t size() const override;
	void insert(const std::vector<element_t>& elements) override;
	void clear() override;
	void finalize(size_t numThreads) override {}
	void batchStart() override {}

	// CompactNodeStore has no metadata to know whether or not it contains
	// a node, so it's not suitable for used in sharded scenarios.
	bool contains(size_t shard, NodeID id) const override { return true; }
	NodeStore& shard(size_t shard) override { return *this; }
	const NodeStore& shard(size_t shard) const override { return *this; }
	size_t shards() const override { return 1; }

private: 
	// @brief Insert a latp/lon pair.
	// @param i OSM ID of a node
	// @param coord a latp/lon pair to be inserted
	// @invariant The OSM ID i must be larger than previously inserted OSM IDs of nodes
	//			  (though unnecessarily for current impl, future impl may impose that)
	void insert_back(NodeID i, LatpLon coord) {
		if(i >= mLatpLons->size())
			mLatpLons->resize(i + 1);
		(*mLatpLons)[i] = coord;
	}


	mutable std::mutex mutex;
	std::shared_ptr<map_t> mLatpLons;
};


#endif