-
Notifications
You must be signed in to change notification settings - Fork 0
/
a.go
73 lines (65 loc) · 1.1 KB
/
a.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
package main
import (
"fmt"
a "merkle/merkle"
)
func addnode(i string) {
t[0] = append(t[0], i)
t = append(t[:1])
build()
}
func deletenode(data string) {
str := t[0]
for i := 0; i < len(str); i++ {
if str[i] == data {
str = append(str[:i], str[i+1:]...)
t = [][]string{}
t[0] = append(t[0], str[:]...)
build()
}
}
}
func find(data string) bool {
str := t[0]
for i := 0; i < len(str); i++ {
if str[i] == data {
return true
}
}
return false
}
func build() {
//n := height(len(t[0]))
var hash []string
for i := 0; i < len(t[0]); i++ {
hash = append(hash, a.Sha(t[0][i]))
}
t = append(t, hash)
k := 1
// fmt.Println(n)
for len(t[k]) > 1 {
s := []string{}
for i := 0; i < len(t[k]); i = i + 2 {
var j string
if i+1 < len(t[k]) {
j = t[k][i]
} else {
j = t[k][i] + t[k][i+1]
}
// fmt.Println(len(t[k]))
// fmt.Println(j)
s = append(s, a.Sha(j))
fmt.Println(s)
}
k++
fmt.Println("sucess")
t = append(t, s)
}
//fmt.Println(len(t[2][0]))
}
var t [][]string
func main() {
t = [][]string{{"hi", "in"}}
build()
fmt.Println(find("hi"))
}