forked from CUIT-CBI/merkle-dag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delimit.go
97 lines (79 loc) · 1.44 KB
/
delimit.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
package merkledag
type TestFile struct {
name string
data []byte
}
func (file *TestFile) Size() uint64 {
return uint64(len(file.data))
}
func (file *TestFile) Name() string {
return file.name
}
func (file *TestFile) Type() int {
return FILE
}
func (file *TestFile) Bytes() []byte {
return file.data
}
type testDirIter struct {
list []Node
iter int
}
func (iter *testDirIter) Next() bool {
if iter.iter+1 < len(iter.list) {
iter.iter += 1
return true
}
return false
}
func (iter *testDirIter) Node() Node {
return iter.list[iter.iter]
}
type TestDir struct {
list []Node
name string
}
func (dir *TestDir) Size() uint64 {
var len uint64 = 0
for i := range dir.list {
len += dir.list[i].Size()
}
return len
}
func (dir *TestDir) Name() string {
return dir.name
}
func (dir *TestDir) Type() int {
return DIR
}
func (dir *TestDir) It() DirIterator {
it := &testDirIter{
list: dir.list,
iter: -1,
}
return it
}
type HashMap struct {
mp map[string]([]byte)
}
func (hmp *HashMap) Has(key []byte) (bool, error) {
return hmp.mp[string(key)] != nil, nil
}
func (hmp *HashMap) Put(key, value []byte) error {
flag, _ := hmp.Has(key)
if flag {
panic("Key is same")
}
hmp.mp[string(key)] = value
return nil
}
func (hmp *HashMap) Get(key []byte) ([]byte, error) {
flag, _ := hmp.Has(key)
if !flag {
panic("Don't have the key")
}
return hmp.mp[string(key)], nil
}
func (hmp *HashMap) Delete(key []byte) error {
return nil
}