(key string, timestamp int)
| 43 | } |
| 44 | |
| 45 | func (m *TimeMap) Get(key string, timestamp int) string { |
| 46 | entries, ok := m.m[key] |
| 47 | if !ok { |
| 48 | return "" |
| 49 | } |
| 50 | |
| 51 | // Find the first entry where the timestamp is greater. This means |
| 52 | // the one right behind it is our entry to return. |
| 53 | index := sort.Search(len(entries), func(i int) bool { |
| 54 | return entries[i].timestamp > timestamp |
| 55 | }) |
| 56 | if index == 0 { |
| 57 | return "" |
| 58 | } |
| 59 | |
| 60 | return entries[index-1].value |
| 61 | } |