-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.go
42 lines (34 loc) · 890 Bytes
/
index.go
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
package osm
//TODO move elsewhere
// Used for fast querying
type Index struct {
// these are for indexing
nodesById map[uint64]*Node
waysById map[uint64]*Way
relationById map[uint64]*Relation
}
func (osm *Osm) BuildIndex() Index {
index := Index{}
index.nodesById = map[uint64]*Node{}
index.waysById = map[uint64]*Way{}
index.relationById = map[uint64]*Relation{}
for i := range osm.Node {
index.nodesById[osm.Node[i].Id] = osm.Node[i]
}
for i := range osm.Way {
index.waysById[osm.Way[i].Id] = osm.Way[i]
}
for i := range osm.Relation {
index.relationById[osm.Relation[i].Id] = osm.Relation[i]
}
return index
}
func (index *Index) NodeById(id uint64) *Node {
return index.nodesById[id]
}
func (index *Index) WayById(id uint64) *Way {
return index.waysById[id]
}
func (index *Index) RelationById(id uint64) *Relation {
return index.relationById[id]
}