-
Notifications
You must be signed in to change notification settings - Fork 0
/
signer.go
103 lines (90 loc) · 2.25 KB
/
signer.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"sort"
"strconv"
"strings"
"sync"
)
// сюда писать код
const (
hashNum = 6
)
//main step
var ExecutePipeline = func(jobs ...job) {
wg := &sync.WaitGroup{}
in := make(chan interface{})
for _, job := range jobs {
wg.Add(1)
out := make(chan interface{})
go startWorker(wg, in, out, job)
in = out
}
wg.Wait()
}
//можно добавить и в ExecutePipeline
func startWorker(wg *sync.WaitGroup, in, out chan interface{}, j job) {
defer wg.Done()
j(in, out)
close(out)
}
var SingleHash = func(in, out chan interface{}) {
wg := &sync.WaitGroup{}
mutex := &sync.Mutex{}
for data := range in {
wg.Add(1)
go SHWorker(data, out, wg, mutex)
}
wg.Wait()
}
func SHWorker(data interface{}, out chan interface{}, wg *sync.WaitGroup, mutex *sync.Mutex) {
crc32datachan := make(chan string)
mutex.Lock()
//calculating value of md5(data)
md5data := DataSignerMd5(strconv.Itoa(data.(int)))
mutex.Unlock()
go func(out chan string, data interface{}) {
//calculating value of crc32(data)
crc32data := DataSignerCrc32(strconv.Itoa(data.(int)))
out <- crc32data
}(crc32datachan, data)
crc32data := <-crc32datachan
//calculating value of crc32(md5(data))
crc32md5data := DataSignerCrc32(md5data)
out <- crc32data + "~" + crc32md5data
wg.Done()
}
var MultiHash = func(in, out chan interface{}) {
wg := &sync.WaitGroup{}
for data := range in {
wg.Add(1)
go MHWorker(data, out, wg)
}
wg.Wait()
}
func MHWorker(data interface{}, out chan interface{}, wg *sync.WaitGroup) {
mhwg := &sync.WaitGroup{}
defer wg.Done()
var mhdataresult = make([]string, hashNum, hashNum)
for th := 0; th < hashNum; th++ {
mhwg.Add(1)
//calculating value of crc32(th+step1))
crc32thstep1 := strconv.Itoa(th) + data.(string)
go func(i int, wg *sync.WaitGroup, data string) {
defer wg.Done()
mhdataresult[i] = DataSignerCrc32(data)
}(th, mhwg, crc32thstep1)
}
mhwg.Wait()
result := strings.Join(mhdataresult, "")
out <- result
}
//this was the easiest function, so I wrote it first
var CombineResults = func(in, out chan interface{}) {
var allresults []string
for data := range in {
allresults = append(allresults, data.(string))
}
sort.Strings(allresults)
result := strings.Join(allresults, "_")
out <- result
}