-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cache.go
56 lines (46 loc) · 1.21 KB
/
Cache.go
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
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"log"
)
type HourCache struct {
Minutes map[int]*MinuteCache
}
func NewHourCache() *HourCache {
minuteMap := map[int]*MinuteCache{}
for i:=0; i<60; i++ {
minuteMap[i] = NewMinuteCache()
}
return &HourCache{Minutes: minuteMap}
}
type MinuteCache struct {
Seconds map[int]float64
written bool
}
func NewMinuteCache() *MinuteCache {
secondMap := map[int]float64{}
return &MinuteCache{Seconds: secondMap, written: true}
}
type Cache struct {
Content map[string]*HourCache
}
func NewCache() *Cache {
cache := &Cache{Content: map[string]*HourCache{}}
return cache
}
func (self *Cache) Insert( Second int, Minute int, Id string, Data float64 ) {
if self.Content[Id] == nil {
self.Content[Id] = NewHourCache()
}
self.Content[Id].Minutes[Minute].Seconds[Second] = Data
self.Content[Id].Minutes[Minute].written = false
}
func (self *Cache) print( Id string ) {
for i:= 0; i<60; i++ {
for j:=0; j<60; j++ {
if self.Content[Id].Minutes[i].Seconds[j] != 0 {
log.Println( self.Content[Id].Minutes[i].Seconds[j] )
log.Printf( "%d, %d, %s \n", i, j, Id)
}
}
}
}