-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenge.go
68 lines (57 loc) · 1.45 KB
/
challenge.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
57
58
59
60
61
62
63
64
65
66
67
68
package challenge
import (
input "challenge/input"
task "challenge/task"
"context"
"math/big"
)
type AppCtx struct {
Ctx context.Context
TaskManager *task.TaskManager
InputHandler *input.InputHandler
Storage map[string][]byte
MaxStorageSize int64
}
/*
Pushes result to Storage
--> Drop the oldest value out of Storage if it's size reaches MaxStorageCap
*/
func (app *AppCtx) PushResult(sourceID string, result []byte) {
app.Storage[sourceID] = result
}
/*
Fetches Result from Storage
*/
func (app *AppCtx) FetchResult(sourceID string) []byte {
return app.Storage[sourceID]
}
/*
Check if value exist in Storage by SourceID
- If Exist Drops value from Storage by sourceID and Update StorageKeys
*/
func (app *AppCtx) DropResult(sourceID string) {
}
/*
Return all Storage Keys
*/
func (app *AppCtx) GetSourceIDs() (sourceIDs []string) {
return sourceIDs
}
func FilterA(in []byte) bool {
return big.NewInt(0).SetBytes(in).Cmp(big.NewInt(10)) >= 0
}
func FilterB(in []byte) bool {
return big.NewInt(0).SetBytes(in).Cmp(big.NewInt(50)) <= 0
}
func InitApp(maxPendingTasks int64, maxStorageSize int64) *AppCtx {
app := &AppCtx{
Ctx: context.Background(),
Storage: make(map[string][]byte),
MaxStorageSize: maxStorageSize,
}
return app
}
func (app *AppCtx) Run() {
go app.TaskManager.Executioner(app.Ctx) // run task executioner in the background
go app.InputHandler.ParseInput() // start listening to input
}