...
1
18
19
20 package req_timings
21
22 import (
23 "fmt"
24 "scheduler/hashtable"
25 "scheduler/log"
26 )
27
28 var ht hashtable.ValueHashtable
29
30 func init() {
31 ht = hashtable.ValueHashtable{}
32 }
33
34 func AddTiming(remoteAddress string, timing int64) error {
35
36 values := ht.Get(remoteAddress)
37 if values == nil {
38 ht.Put(remoteAddress, []int64{timing})
39 return nil
40 }
41
42 if valuesArr, ok := values.([]int64); ok {
43 valuesArr = append(valuesArr, timing)
44 if len(valuesArr) > 2 {
45 valuesArr = valuesArr[1:]
46 }
47 ht.Put(remoteAddress, valuesArr)
48 } else {
49 log.Log.Errorf("Existing value is not a float arr")
50 }
51
52 return nil
53 }
54
55 func GetTimings(remoteAddress string) ([]int64, error) {
56 values := ht.Get(remoteAddress)
57
58 if valuesArr, ok := values.([]int64); ok {
59 return valuesArr, nil
60 }
61
62 return []int64{}, fmt.Errorf("no timing for address %s", remoteAddress)
63 }
64
65 func Clear() {
66 ht = hashtable.ValueHashtable{}
67 }
68
View as plain text