2015-08-30 00:17:30 +00:00
|
|
|
// Copyright 2015 The go-python Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package maps
|
|
|
|
|
2017-08-09 09:16:55 +00:00
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
)
|
2015-08-30 00:17:30 +00:00
|
|
|
|
2017-08-09 09:16:55 +00:00
|
|
|
func Sum(t map[int]float64) float64 {
|
|
|
|
sum := 0.0
|
|
|
|
for _, v := range t {
|
|
|
|
sum += v
|
|
|
|
}
|
|
|
|
|
|
|
|
return sum
|
|
|
|
}
|
|
|
|
|
|
|
|
func New() map[int]float64 {
|
|
|
|
return map[int]float64{
|
|
|
|
1: 3.0,
|
|
|
|
2: 5.0,
|
|
|
|
}
|
2015-08-30 00:17:30 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 09:16:55 +00:00
|
|
|
func Keys(t map[int]float64) []int {
|
|
|
|
var keys []int
|
|
|
|
for k, _ := range t {
|
|
|
|
keys = append(keys, k)
|
2015-08-30 00:17:30 +00:00
|
|
|
}
|
2017-08-09 09:16:55 +00:00
|
|
|
|
|
|
|
sort.Ints(keys)
|
|
|
|
return keys
|
|
|
|
}
|
|
|
|
|
|
|
|
func Values(t map[int]float64) []float64 {
|
|
|
|
var values []float64
|
|
|
|
for _, v := range t {
|
|
|
|
values = append(values, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Float64s(values)
|
|
|
|
return values
|
2015-08-30 00:17:30 +00:00
|
|
|
}
|