Решение на ExpireMap от Йончо Йончев

Обратно към всички решения

Към профила на Йончо Йончев

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 25 неуспешни тест(а)

Код

package main
import (
//"fmt"
"time"
)
type Entry struct {
key string
value interface{}
expire time.Duration
}
//my structure
type ExpireMap map[string]Entry
//Връща указател към нов обект от тип ExpireMap, готов за използване.
func NewExpireMap() *ExpireMap {
em := make(ExpireMap)
return &em
}
// func (em *ExpireMap) Set(key string, value interface{}, expire time.Duration) {
// myMap := make(ExpireMap)
// myMap = em
// myMap[key] = Entry{key, value, expire}
// }
// //Връща стойността на ключ и true, когато ключа е намерен.
// func (em *ExpireMap) Get(key string) (interface{}, bool) {
// myMap := make(ExpireMap)
// myMap = em
// val, ok := myMap[key]
// return val.value, ok
// }
// func (em *ExpireMap) GetInt(key string) (int, bool) {
// val, ok := em[key]
// return val.value, ok
// }
// func (em *ExpireMap) GetFloat64(key string) (float64, bool) {
// val, ok := em[key]
// return val.value, ok
// }
// func (em *ExpireMap) GetString(key string) (string, bool) {
// val, ok := em[key]
// return val.value, ok
// }
// func (em *ExpireMap) GetBool(key string) (bool, bool) {
// val, ok := em[key]
// return val, ok
// }
// func (em *ExpireMap) Expires(key string) (time.Time, bool) {
// val, ok := em[key]
// return val.expire, ok
// }
// func (em *ExpireMap) Delete(key string) {
// em[key] = Entry{"", nil, time.Millisecond * 0}
// }
// func (em *ExpireMap) Contains(key string) bool {
// val, ok := em[key].value
// return ok
// }
// func (em *ExpireMap) Size() int {
// return em.Size()
// }
// func (em *ExpireMap) Increment(key string) error {
// val, ok := em[key]
// val.expire += time.Millisecond * 1
// return ok
// }
// func (em *ExpireMap) Decrement(key string) error {
// val, ok := em[key]
// val.expire -= time.Millisecond * 1
// return ok
// }
// func (em *ExpireMap) ToUpper(key string) error {
// val, ok := *em[key]
// Delete(key)
// em[ToUpper(key)] = val
// return ok
// }
// func (em *ExpireMap) ToLower(key string) error {
// val, ok := *em[key].value
// Delete(key)
// em[ToLower(key)] = val
// return ok
// }
// func (em *ExpireMap) ExpiredChan() <-chan string {
// out := make(chan string)
// go func() {
// for _, n := range em {
// out <- n.value
// }
// close(out)
// }()
// return out
// }
// func (em *ExpireMap) Cleanup() {
// for key, _ := range em {
// Delete(key)
// }
// }
// func (em *ExpireMap) Destroy() {
// Cleanup(em)
// }
func main() {
//cache := NewExpireMap()
//defer cache.Destroy()
// cache.Set("foo", "bar", 15*time.Second)
// cache.Set("spam", "4", 25*time.Minute)
// cache.Set("eggs", 9000.01, 3*time.Minute)
// err := cache.Increment("spam")
// if err != nil {
// fmt.Println("Sadly, incrementing the spam did not succeed")
// }
// if val, ok := cache.Get("spam"); ok {
// fmt.Printf("The value of spam should be the string 5: %s", val)
// } else {
// fmt.Println("No spam. Have some eggs instead?")
// }
// if eggs, ok := cache.GetFloat64("eggs"); !ok || eggs <= 9000 {
// fmt.Println("We did not have as many eggs as expected. Have you considered our spam offers?")
// }
}

Лог от изпълнението

# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]
# _/tmp/d20141204-6466-1dyrgnf
./solution_test.go:24: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:24: defer requires function call, not conversion
./solution_test.go:29: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:30: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:40: mp.Get undefined (type *ExpireMap has no field or method Get)
./solution_test.go:49: mp.Destroy undefined (type *ExpireMap has no field or method Destroy)
./solution_test.go:49: defer requires function call, not conversion
./solution_test.go:52: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:55: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: mp.Set undefined (type *ExpireMap has no field or method Set)
./solution_test.go:58: too many errors
FAIL	_/tmp/d20141204-6466-1dyrgnf [build failed]

История (2 версии и 0 коментара)

Йончо обнови решението на 18.11.2014 16:55 (преди над 3 години)

+package main
+
+import (
+ //"fmt"
+ "time"
+)
+
+type Entry struct {
+ key string
+ value interface{}
+ expire time.Duration
+}
+
+//my structure
+type ExpireMap map[string]Entry
+
+//Връща указател към нов обект от тип ExpireMap, готов за използване.
+func NewExpireMap() *ExpireMap {
+ em := make(ExpireMap)
+ return &em
+}
+
+// func (em *ExpireMap) Set(key string, value interface{}, expire time.Duration) {
+// entry = &Entry{em.key, em.value, em.expire}
+// em[key] = entry
+// }
+
+// //Връща стойността на ключ и true, когато ключа е намерен.
+// func (em *ExpireMap) Get(key string) (interface{}, bool) {
+// myMap := make(ExpireMap)
+// myMap = em
+// val, ok := myMap[key]
+// return val.value, ok
+// }
+
+// func (em *ExpireMap) GetInt(key string) (int, bool) {
+// val, ok := em[key]
+// return val.value, ok
+// }
+
+// func (em *ExpireMap) GetFloat64(key string) (float64, bool) {
+// val, ok := em[key]
+// return val.value, ok
+// }
+
+// func (em *ExpireMap) GetString(key string) (string, bool) {
+// val, ok := em[key]
+// return val.value, ok
+// }
+
+// func (em *ExpireMap) GetBool(key string) (bool, bool) {
+// val, ok := em[key]
+// return val, ok
+// }
+
+// func (em *ExpireMap) Expires(key string) (time.Time, bool) {
+// val, ok := em[key]
+// return val.expire, ok
+// }
+
+// func (em *ExpireMap) Delete(key string) {
+// em[key] = Entry{"", nil, time.Millisecond * 0}
+// }
+
+// func (em *ExpireMap) Contains(key string) bool {
+// val, ok := em[key].value
+// return ok
+// }
+
+// func (em *ExpireMap) Size() int {
+// return em.Size()
+// }
+
+// func (em *ExpireMap) Increment(key string) error {
+// val, ok := em[key]
+// val.expire += time.Millisecond * 1
+// return ok
+// }
+
+// func (em *ExpireMap) Decrement(key string) error {
+// val, ok := em[key]
+// val.expire -= time.Millisecond * 1
+// return ok
+// }
+
+// func (em *ExpireMap) ToUpper(key string) error {
+// val, ok := *em[key]
+// Delete(key)
+// em[ToUpper(key)] = val
+// return ok
+// }
+
+// func (em *ExpireMap) ToLower(key string) error {
+// val, ok := *em[key].value
+// Delete(key)
+// em[ToLower(key)] = val
+// return ok
+// }
+
+// func (em *ExpireMap) ExpiredChan() <-chan string {
+// out := make(chan string)
+// go func() {
+// for _, n := range em {
+// out <- n.value
+// }
+// close(out)
+// }()
+// return out
+// }
+
+// func (em *ExpireMap) Cleanup() {
+// for key, _ := range em {
+// Delete(key)
+// }
+// }
+
+// func (em *ExpireMap) Destroy() {
+// Cleanup(em)
+// }
+
+func main() {
+ // cache := NewExpireMap()
+ // defer cache.Destroy()
+
+ // cache.Set("foo", "bar", 15*time.Second)
+ // cache.Set("spam", "4", 25*time.Minute)
+ // cache.Set("eggs", 9000.01, 3*time.Minute)
+
+ // err := cache.Increment("spam")
+
+ // if err != nil {
+ // fmt.Println("Sadly, incrementing the spam did not succeed")
+ // }
+
+ // if val, ok := cache.Get("spam"); ok {
+ // fmt.Printf("The value of spam should be the string 5: %s", val)
+ // } else {
+ // fmt.Println("No spam. Have some eggs instead?")
+ // }
+
+ // if eggs, ok := cache.GetFloat64("eggs"); !ok || eggs <= 9000 {
+ // fmt.Println("We did not have as many eggs as expected. Have you considered our spam offers?")
+ // }
+}

Йончо обнови решението на 18.11.2014 16:59 (преди над 3 години)

package main
import (
//"fmt"
"time"
)
type Entry struct {
key string
value interface{}
expire time.Duration
}
//my structure
type ExpireMap map[string]Entry
//Връща указател към нов обект от тип ExpireMap, готов за използване.
func NewExpireMap() *ExpireMap {
em := make(ExpireMap)
return &em
}
// func (em *ExpireMap) Set(key string, value interface{}, expire time.Duration) {
-// entry = &Entry{em.key, em.value, em.expire}
-// em[key] = entry
+// myMap := make(ExpireMap)
+// myMap = em
+// myMap[key] = Entry{key, value, expire}
// }
// //Връща стойността на ключ и true, когато ключа е намерен.
// func (em *ExpireMap) Get(key string) (interface{}, bool) {
// myMap := make(ExpireMap)
// myMap = em
// val, ok := myMap[key]
// return val.value, ok
// }
// func (em *ExpireMap) GetInt(key string) (int, bool) {
// val, ok := em[key]
// return val.value, ok
// }
// func (em *ExpireMap) GetFloat64(key string) (float64, bool) {
// val, ok := em[key]
// return val.value, ok
// }
// func (em *ExpireMap) GetString(key string) (string, bool) {
// val, ok := em[key]
// return val.value, ok
// }
// func (em *ExpireMap) GetBool(key string) (bool, bool) {
// val, ok := em[key]
// return val, ok
// }
// func (em *ExpireMap) Expires(key string) (time.Time, bool) {
// val, ok := em[key]
// return val.expire, ok
// }
// func (em *ExpireMap) Delete(key string) {
// em[key] = Entry{"", nil, time.Millisecond * 0}
// }
// func (em *ExpireMap) Contains(key string) bool {
// val, ok := em[key].value
// return ok
// }
// func (em *ExpireMap) Size() int {
// return em.Size()
// }
// func (em *ExpireMap) Increment(key string) error {
// val, ok := em[key]
// val.expire += time.Millisecond * 1
// return ok
// }
// func (em *ExpireMap) Decrement(key string) error {
// val, ok := em[key]
// val.expire -= time.Millisecond * 1
// return ok
// }
// func (em *ExpireMap) ToUpper(key string) error {
// val, ok := *em[key]
// Delete(key)
// em[ToUpper(key)] = val
// return ok
// }
// func (em *ExpireMap) ToLower(key string) error {
// val, ok := *em[key].value
// Delete(key)
// em[ToLower(key)] = val
// return ok
// }
// func (em *ExpireMap) ExpiredChan() <-chan string {
// out := make(chan string)
// go func() {
// for _, n := range em {
// out <- n.value
// }
// close(out)
// }()
// return out
// }
// func (em *ExpireMap) Cleanup() {
// for key, _ := range em {
// Delete(key)
// }
// }
// func (em *ExpireMap) Destroy() {
// Cleanup(em)
// }
func main() {
- // cache := NewExpireMap()
- // defer cache.Destroy()
+ //cache := NewExpireMap()
+ //defer cache.Destroy()
// cache.Set("foo", "bar", 15*time.Second)
// cache.Set("spam", "4", 25*time.Minute)
// cache.Set("eggs", 9000.01, 3*time.Minute)
// err := cache.Increment("spam")
// if err != nil {
// fmt.Println("Sadly, incrementing the spam did not succeed")
// }
// if val, ok := cache.Get("spam"); ok {
// fmt.Printf("The value of spam should be the string 5: %s", val)
// } else {
// fmt.Println("No spam. Have some eggs instead?")
// }
// if eggs, ok := cache.GetFloat64("eggs"); !ok || eggs <= 9000 {
// fmt.Println("We did not have as many eggs as expected. Have you considered our spam offers?")
// }
}