From 914d13c41db04caf6cfebcb5dbaedb1eda469971 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Thu, 2 Apr 2020 11:46:57 +0800 Subject: [PATCH] refactor: discard unnecessary packages --- integration/cmd/osrm-ranking/main.go | 4 ++-- .../cmd/trafficcache-parallel-test/main.go | 7 +++--- .../trafficcache/{trafficcache => }/cache.go | 0 .../cache.go => cache_indexed_by_edge.go} | 24 +++++++++---------- 4 files changed, 17 insertions(+), 18 deletions(-) rename integration/traffic/livetraffic/trafficcache/{trafficcache => }/cache.go (100%) rename integration/traffic/livetraffic/trafficcache/{trafficcacheindexedbyedge/cache.go => cache_indexed_by_edge.go} (66%) diff --git a/integration/cmd/osrm-ranking/main.go b/integration/cmd/osrm-ranking/main.go index 7415db26701..4972e11ea87 100644 --- a/integration/cmd/osrm-ranking/main.go +++ b/integration/cmd/osrm-ranking/main.go @@ -11,7 +11,7 @@ import ( "github.com/Telenav/osrm-backend/integration/service/ranking" "github.com/Telenav/osrm-backend/integration/traffic/historicalspeed" - "github.com/Telenav/osrm-backend/integration/traffic/livetraffic/trafficcache/trafficcacheindexedbyedge" + "github.com/Telenav/osrm-backend/integration/traffic/livetraffic/trafficcache" "github.com/Telenav/osrm-backend/integration/traffic/livetraffic/trafficproxyclient" "github.com/Telenav/osrm-backend/integration/wayid2nodeids" @@ -49,7 +49,7 @@ func main() { } // prepare traffic cache - trafficCache := trafficcacheindexedbyedge.New(wayID2NodeIDsMapping) + trafficCache := trafficcache.NewCacheIndexedByEdge(wayID2NodeIDsMapping) feeder := trafficproxyclient.NewFeeder() feeder.RegisterEaters(trafficCache) go func() { diff --git a/integration/cmd/trafficcache-parallel-test/main.go b/integration/cmd/trafficcache-parallel-test/main.go index eee51a28e0f..6c1a9f83884 100644 --- a/integration/cmd/trafficcache-parallel-test/main.go +++ b/integration/cmd/trafficcache-parallel-test/main.go @@ -4,8 +4,7 @@ import ( "flag" "time" - "github.com/Telenav/osrm-backend/integration/traffic/livetraffic/trafficcache/trafficcache" - "github.com/Telenav/osrm-backend/integration/traffic/livetraffic/trafficcache/trafficcacheindexedbyedge" + "github.com/Telenav/osrm-backend/integration/traffic/livetraffic/trafficcache" "github.com/Telenav/osrm-backend/integration/traffic/livetraffic/trafficproxyclient" "github.com/Telenav/osrm-backend/integration/wayid2nodeids" @@ -17,14 +16,14 @@ func main() { defer glog.Flush() var cacheByWay *trafficcache.Cache - var cacheByEdge *trafficcacheindexedbyedge.Cache + var cacheByEdge *trafficcache.CacheIndexedByEdge if flags.indexedByEdge { wayID2NodeIDsMapping := wayid2nodeids.NewMappingFrom(flags.wayID2NodeIDsMappingFile) if err := wayID2NodeIDsMapping.Load(); err != nil { glog.Error(err) return } - cacheByEdge = trafficcacheindexedbyedge.New(wayID2NodeIDsMapping) + cacheByEdge = trafficcache.NewCacheIndexedByEdge(wayID2NodeIDsMapping) } if flags.indexedByWayID { cacheByWay = trafficcache.New() diff --git a/integration/traffic/livetraffic/trafficcache/trafficcache/cache.go b/integration/traffic/livetraffic/trafficcache/cache.go similarity index 100% rename from integration/traffic/livetraffic/trafficcache/trafficcache/cache.go rename to integration/traffic/livetraffic/trafficcache/cache.go diff --git a/integration/traffic/livetraffic/trafficcache/trafficcacheindexedbyedge/cache.go b/integration/traffic/livetraffic/trafficcache/cache_indexed_by_edge.go similarity index 66% rename from integration/traffic/livetraffic/trafficcache/trafficcacheindexedbyedge/cache.go rename to integration/traffic/livetraffic/trafficcache/cache_indexed_by_edge.go index 5977471b5a3..aa7bd707cb8 100644 --- a/integration/traffic/livetraffic/trafficcache/trafficcacheindexedbyedge/cache.go +++ b/integration/traffic/livetraffic/trafficcache/cache_indexed_by_edge.go @@ -1,4 +1,4 @@ -package trafficcacheindexedbyedge +package trafficcache import ( "github.com/Telenav/osrm-backend/integration/graph" @@ -9,15 +9,15 @@ import ( "github.com/golang/glog" ) -// Cache is used to cache live traffic and provide query interfaces. -type Cache struct { +// CacheIndexedByEdge is used to cache live traffic and provide query interfaces. +type CacheIndexedByEdge struct { Flows *flowscacheindexedbyedge.Cache Incidents *incidentscache.Cache } -// New creates a new Cache instance. -func New(wayID2Edges wayidsmap.Way2Edges) *Cache { - c := Cache{ +// NewCacheIndexedByEdge creates a new CacheIndexedByEdge instance. +func NewCacheIndexedByEdge(wayID2Edges wayidsmap.Way2Edges) *CacheIndexedByEdge { + c := CacheIndexedByEdge{ flowscacheindexedbyedge.New(wayID2Edges), incidentscache.NewWithEdgeIndexing(wayID2Edges), } @@ -25,35 +25,35 @@ func New(wayID2Edges wayidsmap.Way2Edges) *Cache { } // Clear all cached traffic flows and incidents. -func (c *Cache) Clear() { +func (c *CacheIndexedByEdge) Clear() { c.Flows.Clear() c.Incidents.Clear() } // Eat implements livetraffic.Eater inteface. -func (c *Cache) Eat(r trafficproxy.TrafficResponse) { +func (c *CacheIndexedByEdge) Eat(r trafficproxy.TrafficResponse) { glog.V(1).Infof("new traffic for cache, flows: %d, incidents: %d", len(r.FlowResponses), len(r.IncidentResponses)) c.Flows.Update(r.FlowResponses) c.Incidents.Update(r.IncidentResponses) } // QueryFlow returns Live Traffic Flow if exist. -func (c *Cache) QueryFlow(e graph.Edge) *trafficproxy.Flow { +func (c *CacheIndexedByEdge) QueryFlow(e graph.Edge) *trafficproxy.Flow { return c.Flows.QueryByEdge(e) } // QueryFlows returns Live Traffic Flows if exist. -func (c *Cache) QueryFlows(e []graph.Edge) []*trafficproxy.Flow { +func (c *CacheIndexedByEdge) QueryFlows(e []graph.Edge) []*trafficproxy.Flow { return c.Flows.QueryByEdges(e) } // EdgeBlockedByIncident check whether this Edge is on blocking incident. -func (c *Cache) EdgeBlockedByIncident(e graph.Edge) bool { +func (c *CacheIndexedByEdge) EdgeBlockedByIncident(e graph.Edge) bool { return c.Incidents.EdgeBlockedByIncident(e) } // EdgesBlockedByIncidents check whether this Edge is on blocking incidents. // the second return indicates the blocked edge index of input array if exist. -func (c *Cache) EdgesBlockedByIncidents(e []graph.Edge) (bool, int) { +func (c *CacheIndexedByEdge) EdgesBlockedByIncidents(e []graph.Edge) (bool, int) { return c.Incidents.EdgesBlockedByIncidents(e) }