forked from usnistgov/blockmatrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockMatrixBasics.go
More file actions
52 lines (38 loc) · 1.39 KB
/
BlockMatrixBasics.go
File metadata and controls
52 lines (38 loc) · 1.39 KB
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
package main
import(
"fmt"
"bytes"
"blockmatrix"
)
// This is an application to show basic usage of Block Matrix data structure
func main() {
var Dimension int = 5 // Dimension of block matrix
var Blocks []bytes.Buffer // data blocks
Blocks = make([]bytes.Buffer, Dimension * Dimension - Dimension)
for b := 0; b < len(Blocks); b++ {
s := fmt.Sprintf("This is Block No: %d", b + 1)
Blocks[b].Write([]byte(s))
}
// for developers to trace functions, set TraceEnabled to true
blockmatrix.TraceEnabled = true
// Create a block matrix of specified dimension
bm := blockmatrix.Create(Dimension, blockmatrix.Sha256)
fmt.Printf("Created a block matrix %v\n", &bm)
// Dump the block matrix and print only the first 8 characters of hashes
bm.Dump(8)
// Now insert all our blocks into the block matrix
bm.InsertBlocks(Blocks)
// Dump the block matrix and print only the first 8 characters of hashes
bm.Dump(8)
// Get block data of blocknumber = 12
bd := bm.GetBlockData(12)
fmt.Printf("GetBlockData 12: %s\n", bd.String())
fmt.Printf("GetBlockHash 12: %s\n", bm.GetBlockHash(12))
// now delete block number 12
bm.DeleteBlock(12)
bd = bm.GetBlockData(12)
fmt.Printf("GetBlockData 12: %s\n", bd.String())
fmt.Printf("GetBlockHash 12: %s\n", bm.GetBlockHash(12))
// Dump the block matrix and print only the first 8 characters of hashes
bm.Dump(8)
}