MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / Get

Method Get

time_based_key_value_store_981/solution.go:45–61  ·  view source on GitHub ↗
(key string, timestamp int)

Source from the content-addressed store, hash-verified

43}
44
45func (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}

Callers 1

TestKVFunction · 0.45

Calls 1

SearchMethod · 0.80

Tested by 1

TestKVFunction · 0.36