diff options
| -rw-r--r-- | merkle_test.go | 1 | ||||
| -rw-r--r-- | utils.go | 13 | ||||
| -rw-r--r-- | utils_test.go | 12 |
3 files changed, 25 insertions, 1 deletions
diff --git a/merkle_test.go b/merkle_test.go index b2dc9be..b6d9224 100644 --- a/merkle_test.go +++ b/merkle_test.go @@ -67,6 +67,7 @@ func TestProofsPostMerkle(t *testing.T) { func TestBatchProofsBFSMerkle(t *testing.T) { m := NewBFSMerkle(25, "/mnt/data/bfs.db") root := make([]byte, hashSize) + sort.Sort(Int64Slice(ids)) m.Read(root, 0) start := time.Now() proofs = m.BatchProofs(ids) @@ -1,5 +1,10 @@ package main +import ( + "math/rand" + "sort" +) + // floor of log(x) (i.e MSB for positive integers) func Log(x int64) int64 { var r int64 = 0 @@ -34,3 +39,11 @@ func Post(size int64, height int64, id int64) int64 { } return r } + +func Shuffle(data sort.Interface) { + var j int + for i := data.Len() - 1; i > 0; i-- { + j = rand.Intn(i + 1) + data.Swap(i, j) + } +} diff --git a/utils_test.go b/utils_test.go index c42ecef..7b912a0 100644 --- a/utils_test.go +++ b/utils_test.go @@ -1,6 +1,10 @@ package main -import "testing" +import ( + "fmt" + "sort" + "testing" +) func TestLog(t *testing.T) { tests := []struct { @@ -72,3 +76,9 @@ func TestPost(t *testing.T) { } } + +func TestShuffle(t *testing.T) { + a := sort.IntSlice([]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) + Shuffle(a) + fmt.Println(a) +} |
