Author: Adam <git@apiote.xyz>
delete variables when no longer needed
traffic/convert.go | 68 ++++++++++++++++++++++++++++++++++++++++++-----
diff --git a/traffic/convert.go b/traffic/convert.go index 1ec2f650a7204c99247d54e8a77b7508d1a5899f..41ff7c3fa2f1e22f581f4a7e585da64cdd34278d 100644 --- a/traffic/convert.go +++ b/traffic/convert.go @@ -35,8 +35,8 @@ ) type _LineGraph struct { StopCodesArray []string - StopCodes map[string]int - NextNodes map[int]map[int]struct{} + StopCodes map[string]int + NextNodes map[int]map[int]struct{} } type ErrEmpty struct{} @@ -292,7 +292,7 @@ } return c, e } -func convertCalendar(c feedConverter) (feedConverter, error) { // ( feedInfo -- >> calendar) +func convertCalendar(c feedConverter) (feedConverter, error) { // ( feedInfo -- schedules >> ) c.schedules = map[string]Schedule{} path := c.TmpFeedPath calendarFile, err := os.Open(filepath.Join(path, "calendar.txt")) @@ -374,7 +374,7 @@ } return c, nil } -func convertCalendarDates(c feedConverter) (feedConverter, error) { +func convertCalendarDates(c feedConverter) (feedConverter, error) { // ( feedInfo -- schedules >> ) path := c.TmpFeedPath datesFile, err := os.Open(filepath.Join(path, "calendar_dates.txt")) if err != nil { @@ -546,6 +546,8 @@ if err != nil { return fmt.Errorf("while writing: %w", err) } + c.feedInfo = FeedInfo{} + return nil } @@ -554,6 +556,11 @@ if c.TrafficCalendarFile != nil { c.TrafficCalendarFile.Close() } return c, e +} + +func clearDepartures(c feedConverter) feedConverter { + c.Departures = map[string][]Departure{} + return c } func convertDepartures(c feedConverter) (feedConverter, error) { // O(n:stop_times) ; ( -- departures:map[tripID][]departure, tripsThroughStop:map[stopID][]{tripID,order}, tripHeadsigns:map[tripID]stopID >> ) @@ -621,6 +628,11 @@ c.TripsThroughStop = tripsThroughStop return c, nil } +func clearLineNames(c feedConverter) feedConverter { + c.LineNames = map[string]string{} + return c +} + func getLineNames(c feedConverter) (feedConverter, error) { // O(n:routes) ; ( -- lineNames:map[routeID]lineName >> ) path := c.TmpFeedPath @@ -662,6 +674,11 @@ c.LineNames = names return c, nil } +func clearStopNames(c feedConverter) feedConverter { + c.stopNames = map[string]string{} + return c +} + func getStopNames(c feedConverter) (feedConverter, error) { // O(n:stops) ; ( -- stopNames[stopID]stopName >> ) if c.Feed.Flags().Headsign != HeadsignTripLastStop { return c, nil @@ -706,6 +723,16 @@ return c, nil } +func clearTripsChangeOptions(c feedConverter) feedConverter { + c.TripChangeOpts = map[string]ChangeOption{} + return c +} + +func clearTripsThroughStops(c feedConverter) feedConverter { + c.TripsThroughStop = map[string]map[string]StopOrder{} + return c +} + func convertTrips(c feedConverter) (feedConverter, error) { // O(n:trips) ; (departures, lineNames, stopNames -- tripsOffsets:map[tripID]offset, tripsChangeOpts:map[tripID]{lineID,headsign} >> trips) path := c.TmpFeedPath departures := c.Departures @@ -783,7 +810,12 @@ c.TripChangeOpts = tripChangeOpts return c, nil } -func convertStops(c feedConverter) (feedConverter, error) { // O(n:stops) ; (tripsThroughStop, lineNames, tripChangeOpts, tripOffsets -- stopsOffsetsByCode:CodeIndex, stopsOffsetsByName:map[name][]offsets >> stops) +func clearStops(c feedConverter) feedConverter { + c.Stops = map[string]string{} + return c +} + +func convertStops(c feedConverter) (feedConverter, error) { // O(n:stops) ; (translations, tripsThroughStop, lineNames, tripChangeOpts, tripOffsets -- stopsOffsetsByCode:CodeIndex, stopsOffsetsByName:map[name][]offsets >> stops) path := c.TmpFeedPath tripsThroughStop := c.TripsThroughStop tripChangeOpts := c.TripChangeOpts @@ -922,6 +954,16 @@ c.StopsCodeIndex = stopsOffsetsByCode c.StopsNameIndex = stopsOffsetsByName c.Stops = stops return c, nil +} + +func clearLineGraphs(c feedConverter) feedConverter { + c.LineGraphs = map[string]map[uint]LineGraph{} + return c +} + +func clearLineHeadsigns(c feedConverter) feedConverter { + c.lineHeadsigns = map[string]map[uint][]string{} + return c } func convertLineGraphs(c feedConverter) (feedConverter, error) { // O(n:stop_times) ; (tripsOffsets, stops -- lineGrapsh:map[lineName]map[direction]graph, lineHeadsigns:map[lineName]map[direction][]headsigns >> ) @@ -1363,7 +1405,9 @@ tripIndex := map[string][]uint{} for trip, offset := range c.TripsOffsets { tripIndex[trip] = []uint{offset} } - return writeNameIndex(c, tripIndex, "ix_trips.bare", true) + err := writeNameIndex(c, tripIndex, "ix_trips.bare", true) + c.TripsOffsets = map[string]uint{} + return err } func writeStopCodeIndex(c feedConverter) error { @@ -1423,6 +1467,7 @@ r = r. Tee(unzipGtfs). Tee(prepareFeedGtfs). Tee(convertVehicles). + Tee(convertAgencies). Bind(convertFeedInfo). Bind(createTrafficCalendarFile). Bind(convertCalendar). @@ -1437,14 +1482,21 @@ Bind(convertDepartures). Bind(getLineNames). Bind(getStopNames). Bind(convertTrips). + Map(clearDepartures). + Map(clearStopNames). Bind(convertStops). Tee(writeStopNameIndex). Tee(writeStopCodeIndex). + Map(clearTripsChangeOptions). + Map(clearTripsThroughStops). + Map(clearLineNames). Bind(convertLineGraphs). + Tee(writeTripIndex). + Map(clearStops). Bind(convertLines). Tee(writeLineIndex). - Tee(convertAgencies). - Tee(writeTripIndex). + Map(clearLineGraphs). + Map(clearLineHeadsigns). Tee(deleteTxtFiles). Tee(compressTraffic). Tee(deleteBareFiles).