diff --git a/cache/binary/deltacoords_test.go b/cache/binary/deltacoords_test.go index 33869e9..6873bc7 100644 --- a/cache/binary/deltacoords_test.go +++ b/cache/binary/deltacoords_test.go @@ -6,7 +6,6 @@ import ( "runtime" "testing" - "github.com/golang/protobuf/proto" "github.com/omniscale/imposm3/element" ) @@ -73,103 +72,3 @@ func BenchmarkUnmarshalDeltaCoords(b *testing.B) { runtime.GC() } - -func BenchmarkMarshalDeltaCoordsProto(b *testing.B) { - var buf []byte - var err error - - for n := 0; n < b.N; n++ { - deltaCoords := packNodes(nodes) - buf, err = proto.Marshal(deltaCoords) - if err != nil { - panic(err) - } - } - - deltaCoords := &DeltaCoords{} - err = proto.Unmarshal(buf, deltaCoords) - if err != nil { - panic(err) - } - - nodes2 := unpackNodes(deltaCoords, nodes) - - compareNodes(b, nodes, nodes2) - runtime.GC() - -} - -func BenchmarkUnmarshalDeltaCoordsProto(b *testing.B) { - var buf []byte - var err error - - deltaCoords := packNodes(nodes) - buf, err = proto.Marshal(deltaCoords) - if err != nil { - panic(err) - } - var nodes2 []element.Node - for n := 0; n < b.N; n++ { - deltaCoords := &DeltaCoords{} - err = proto.Unmarshal(buf, deltaCoords) - if err != nil { - panic(err) - } - nodes2 = unpackNodes(deltaCoords, nodes) - } - compareNodes(b, nodes, nodes2) - runtime.GC() - -} - -func packNodes(nodes []element.Node) *DeltaCoords { - var lastLon, lastLat int64 - var lon, lat int64 - var lastId int64 - ids := make([]int64, len(nodes)) - lons := make([]int64, len(nodes)) - lats := make([]int64, len(nodes)) - - i := 0 - for _, nd := range nodes { - lon = int64(CoordToInt(nd.Long)) - lat = int64(CoordToInt(nd.Lat)) - ids[i] = nd.Id - lastId - lons[i] = lon - lastLon - lats[i] = lat - lastLat - - lastId = nd.Id - lastLon = lon - lastLat = lat - i++ - } - return &DeltaCoords{Ids: ids, Lats: lats, Lons: lons} -} - -func unpackNodes(deltaCoords *DeltaCoords, nodes []element.Node) []element.Node { - if len(deltaCoords.Ids) > cap(nodes) { - nodes = make([]element.Node, len(deltaCoords.Ids)) - } else { - nodes = nodes[:len(deltaCoords.Ids)] - } - - var lastLon, lastLat int64 - var lon, lat int64 - var lastId, id int64 - - for i := 0; i < len(deltaCoords.Ids); i++ { - id = lastId + deltaCoords.Ids[i] - lon = lastLon + deltaCoords.Lons[i] - lat = lastLat + deltaCoords.Lats[i] - nodes[i] = element.Node{ - OSMElem: element.OSMElem{Id: int64(id)}, - Long: IntToCoord(uint32(lon)), - Lat: IntToCoord(uint32(lat)), - } - - lastId = id - lastLon = lon - lastLat = lat - } - return nodes -} diff --git a/cache/delta.go b/cache/delta.go index 39c0684..569e3de 100644 --- a/cache/delta.go +++ b/cache/delta.go @@ -15,58 +15,6 @@ func (s byId) Len() int { return len(s) } func (s byId) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s byId) Less(i, j int) bool { return s[i].Id < s[j].Id } -func packNodes(nodes []element.Node) *binary.DeltaCoords { - var lastLon, lastLat int64 - var lon, lat int64 - var lastId int64 - ids := make([]int64, len(nodes)) - lons := make([]int64, len(nodes)) - lats := make([]int64, len(nodes)) - - i := 0 - for _, nd := range nodes { - lon = int64(binary.CoordToInt(nd.Long)) - lat = int64(binary.CoordToInt(nd.Lat)) - ids[i] = nd.Id - lastId - lons[i] = lon - lastLon - lats[i] = lat - lastLat - - lastId = nd.Id - lastLon = lon - lastLat = lat - i++ - } - return &binary.DeltaCoords{Ids: ids, Lats: lats, Lons: lons} -} - -func unpackNodes(deltaCoords *binary.DeltaCoords, nodes []element.Node) []element.Node { - if len(deltaCoords.Ids) > cap(nodes) { - nodes = make([]element.Node, len(deltaCoords.Ids)) - } else { - nodes = nodes[:len(deltaCoords.Ids)] - } - - var lastLon, lastLat int64 - var lon, lat int64 - var lastId, id int64 - - for i := 0; i < len(deltaCoords.Ids); i++ { - id = lastId + deltaCoords.Ids[i] - lon = lastLon + deltaCoords.Lons[i] - lat = lastLat + deltaCoords.Lats[i] - nodes[i] = element.Node{ - OSMElem: element.OSMElem{Id: int64(id)}, - Long: binary.IntToCoord(uint32(lon)), - Lat: binary.IntToCoord(uint32(lat)), - } - - lastId = id - lastLon = lon - lastLat = lat - } - return nodes -} - type coordsBunch struct { sync.Mutex id int64