[#316] locode/airports: Scan csv table into memory

Scanning csv-table entries one-by-one takes significant time and system
resources. To speed up random access to table records, on the first call,
the table is pumped into memory (map). On subsequent calls, I/O operations
are not performed.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-02-10 19:52:02 +03:00 committed by Alex Vanin
parent 687c7d3b4a
commit 307355f165
2 changed files with 76 additions and 62 deletions

View file

@ -3,6 +3,7 @@ package airportsdb
import (
"fmt"
"os"
"sync"
)
// Prm groups the required parameters of the DB's constructor.
@ -30,6 +31,12 @@ type Prm struct {
// The DB is immediately ready to work through API.
type DB struct {
airports, countries pathMode
airportsOnce, countriesOnce sync.Once
mCountries map[string]string
mAirports map[string][]record
}
type pathMode struct {