40 lines
643 B
Go
40 lines
643 B
Go
|
package fileutils
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"io/ioutil"
|
||
|
"log"
|
||
|
"os"
|
||
|
"strconv"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func InputParserIntMap(filename string) map[int]bool {
|
||
|
file, err := os.Open(filename)
|
||
|
defer file.Close()
|
||
|
|
||
|
if err != nil {
|
||
|
log.Panicf(err.Error())
|
||
|
}
|
||
|
|
||
|
values := make(map[int]bool)
|
||
|
scanner := bufio.NewScanner(file)
|
||
|
for scanner.Scan() {
|
||
|
x, err := strconv.Atoi(scanner.Text())
|
||
|
if err != nil {
|
||
|
log.Panicf(err.Error())
|
||
|
}
|
||
|
values[x] = true
|
||
|
}
|
||
|
|
||
|
return values
|
||
|
}
|
||
|
|
||
|
func InputParserStrings(filename string) []string {
|
||
|
data, err := ioutil.ReadFile(filename)
|
||
|
if err != nil {
|
||
|
log.Panicf(err.Error())
|
||
|
}
|
||
|
return strings.Split(string(data), "\n")
|
||
|
}
|