-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
45 lines (38 loc) · 917 Bytes
/
main.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
// just a main function
package main
import (
"fmt"
"os"
"strconv"
)
func toPositive(input uint32) (pos uint32) {
pos = input & 0x7fffffff
return
}
func partition(input uint32, noOfPartitions uint32) (part uint32) {
part = input % noOfPartitions
return
}
func keyAndPartitions(args []string) (key string, noOfPartitions uint32) {
noOfPartitions = 60
if (len(os.Args) == 4) {
if (os.Args[1] == "-n") {
noOfPartitions64, _ := strconv.ParseUint(os.Args[2], 0, 32)
noOfPartitions = uint32(noOfPartitions64)
key = os.Args[3]
} else {
fmt.Println("use -n to give number of partitions")
}
} else {
key = os.Args[1]
}
return
}
func main() {
if (len(os.Args) == 1) {
fmt.Println("no args given")
return
}
key, noOfPartitions := keyAndPartitions(os.Args)
fmt.Println(partition(toPositive(MurmurHash2([]byte(key))), noOfPartitions))
}