aboutsummaryrefslogtreecommitdiffstats
path: root/extra/mag/memkey.go
blob: b2e4b422b4b007fc612df80c9a479c72359da975 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	var (
		cache = make(map[int]string)
		br    = bufio.NewReader(os.Stdin)
		i     int
	)
	for {
		line, err := br.ReadString('\n')
		if err == io.EOF {
			break
		}
		if err != nil {
			log.Fatal(err)
		}
		fields := strings.Split(line, "\t")
		if len(fields) < 2 {
			continue
		}
		a, b := strings.TrimSpace(fields[0]), strings.TrimSpace(fields[1])
		id, err := strconv.Atoi(a)
		if err != nil {
			log.Println("skipping invalid id: %s", line)
			continue
		}
		cache[id] = b
		i++
		if i%1000000 == 0 {
			log.Printf("%d", i)
		}
	}
	log.Println("press enter to quit")
	fmt.Scanln()
}