Skip to content

Commit

Permalink
refactor: discard unnecessary packages
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyoucao577 committed Apr 7, 2020
1 parent 1d66069 commit 914d13c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions integration/cmd/osrm-ranking/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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() {
Expand Down
7 changes: 3 additions & 4 deletions integration/cmd/trafficcache-parallel-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package trafficcacheindexedbyedge
package trafficcache

import (
"github.com/Telenav/osrm-backend/integration/graph"
Expand All @@ -9,51 +9,51 @@ 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),
}
return &c
}

// 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)
}

0 comments on commit 914d13c

Please sign in to comment.