Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support merklebtree #16

Closed
wants to merge 4 commits into from
Closed

Conversation

bradyjoestar
Copy link
Contributor

@bradyjoestar bradyjoestar commented Sep 24, 2019

#8

Why not use google/btree

The structure of node in google/btree doesn't have parent pointer

https://github.com/google/btree/blob/be84af90a1f71c9eeac820a4cdacb863122396d6/btree.go#L244-L248

type node struct { 
 	items    items 
 	children children 
 	cow      *copyOnWriteContext 
 } 

google/btree use copyOnWriteContext whick will make it difficlut.

emirpasic/gods/btree

So I use emirpasic/gods/btree and modify the

// Node is a single element within the tree
type Node struct {
	Parent   *Node
	Entries  []*Entry // Contained keys in node
	Children []*Node  // Children nodes
}

// Entry represents the key-value pair contained within nodes
type Entry struct {
	Key   interface{}
	Value interface{}
}

to

// Node is a single element within the tree
type Node struct {
	Parent   *Node
	Contents []*Content // Contained keys in node
	Children []*Node    // Children nodes
}

type Content interface {
	// Less tests whether the current item is less than the given argument.

	// If a.Comparator(b) return
	// negative , if a < b
	// zero     , if a == b
	// positive , if a > b
	Comparator(than Content) int
}

testcase

=== RUN   TestBTreeGet1
--- PASS: TestBTreeGet1 (0.00s)
=== RUN   TestBTreeGet2
--- PASS: TestBTreeGet2 (0.00s)
=== RUN   TestBTreePut1
--- PASS: TestBTreePut1 (0.00s)
=== RUN   TestBTreePut2
--- PASS: TestBTreePut2 (0.00s)
=== RUN   TestBTreePut3
--- PASS: TestBTreePut3 (0.00s)
=== RUN   TestBTreePut4
--- PASS: TestBTreePut4 (0.00s)
=== RUN   TestBTreeRemove1
--- PASS: TestBTreeRemove1 (0.00s)
=== RUN   TestBTreeRemove2
--- PASS: TestBTreeRemove2 (0.00s)
=== RUN   TestBTreeRemove3
--- PASS: TestBTreeRemove3 (0.00s)
=== RUN   TestBTreeRemove4
--- PASS: TestBTreeRemove4 (0.00s)
=== RUN   TestBTreeRemove5
--- PASS: TestBTreeRemove5 (0.00s)
=== RUN   TestBTreeRemove6
--- PASS: TestBTreeRemove6 (0.00s)
=== RUN   TestBTreeRemove7
--- PASS: TestBTreeRemove7 (0.00s)
=== RUN   TestBTreeRemove8
--- PASS: TestBTreeRemove8 (0.00s)
=== RUN   TestBTreeRemove9
--- PASS: TestBTreeRemove9 (0.05s)
=== RUN   TestBTreeHeight
--- PASS: TestBTreeHeight (0.00s)
=== RUN   TestBTreeLeftAndRight
--- PASS: TestBTreeLeftAndRight (0.00s)
=== RUN   TestBTreeIteratorValuesAndKeys
--- PASS: TestBTreeIteratorValuesAndKeys (0.00s)
=== RUN   TestBTreeIteratorNextOnEmpty
--- PASS: TestBTreeIteratorNextOnEmpty (0.00s)
=== RUN   TestBTreeIteratorPrevOnEmpty
--- PASS: TestBTreeIteratorPrevOnEmpty (0.00s)
=== RUN   TestBTreeIterator1Next
--- PASS: TestBTreeIterator1Next (0.00s)
=== RUN   TestBTreeIterator1Prev
--- PASS: TestBTreeIterator1Prev (0.00s)
=== RUN   TestBTreeIterator2Next
--- PASS: TestBTreeIterator2Next (0.00s)
=== RUN   TestBTreeIterator2Prev
--- PASS: TestBTreeIterator2Prev (0.00s)
=== RUN   TestBTreeIterator3Next
--- PASS: TestBTreeIterator3Next (0.00s)
=== RUN   TestBTreeIterator3Prev
--- PASS: TestBTreeIterator3Prev (0.00s)
=== RUN   TestBTreeIterator4Next
--- PASS: TestBTreeIterator4Next (0.00s)
=== RUN   TestBTreeIterator4Prev
--- PASS: TestBTreeIterator4Prev (0.00s)
=== RUN   TestBTreeIteratorBegin
--- PASS: TestBTreeIteratorBegin (0.00s)
=== RUN   TestBTreeIteratorEnd
--- PASS: TestBTreeIteratorEnd (0.00s)
=== RUN   TestBTreeIteratorFirst
--- PASS: TestBTreeIteratorFirst (0.00s)
=== RUN   TestBTreeIteratorLast
--- PASS: TestBTreeIteratorLast (0.00s)
=== RUN   TestBTree_search
--- PASS: TestBTree_search (0.00s)
PASS
coverage: 94.2% of statements in ../../merkletree/...

@bradyjoestar bradyjoestar changed the title borrow btree from `emirpasic/gods/btree' [support merklebtree] borrow btree from `emirpasic/gods/btree' Sep 24, 2019
@bradyjoestar
Copy link
Contributor Author

Completed! Thanks for your review!
@cbergoon

Testcase coverage

=== RUN   TestBTreeGet1
--- PASS: TestBTreeGet1 (0.00s)
=== RUN   TestBTreeGet2
--- PASS: TestBTreeGet2 (0.00s)
=== RUN   TestBTreePut1
--- PASS: TestBTreePut1 (0.00s)
=== RUN   TestBTreePut2
--- PASS: TestBTreePut2 (0.00s)
=== RUN   TestBTreePut3
--- PASS: TestBTreePut3 (0.00s)
=== RUN   TestBTreePut4
--- PASS: TestBTreePut4 (0.00s)
=== RUN   TestBTreeRemove1
--- PASS: TestBTreeRemove1 (0.00s)
=== RUN   TestBTreeRemove2
--- PASS: TestBTreeRemove2 (0.00s)
=== RUN   TestBTreeRemove3
--- PASS: TestBTreeRemove3 (0.00s)
=== RUN   TestBTreeRemove4
--- PASS: TestBTreeRemove4 (0.00s)
=== RUN   TestBTreeRemove5
--- PASS: TestBTreeRemove5 (0.00s)
=== RUN   TestBTreeRemove6
--- PASS: TestBTreeRemove6 (0.00s)
=== RUN   TestBTreeRemove7
--- PASS: TestBTreeRemove7 (0.00s)
=== RUN   TestBTreeRemove8
--- PASS: TestBTreeRemove8 (0.00s)
=== RUN   TestBTreeRemove9
--- PASS: TestBTreeRemove9 (5.01s)
=== RUN   TestBTreeHeight
--- PASS: TestBTreeHeight (0.00s)
=== RUN   TestBTreeLeftAndRight
--- PASS: TestBTreeLeftAndRight (0.00s)
=== RUN   TestBTreeIteratorValuesAndKeys
--- PASS: TestBTreeIteratorValuesAndKeys (0.00s)
=== RUN   TestBTreeIteratorNextOnEmpty
--- PASS: TestBTreeIteratorNextOnEmpty (0.00s)
=== RUN   TestBTreeIteratorPrevOnEmpty
--- PASS: TestBTreeIteratorPrevOnEmpty (0.00s)
=== RUN   TestBTreeIterator1Next
--- PASS: TestBTreeIterator1Next (0.00s)
=== RUN   TestBTreeIterator1Prev
--- PASS: TestBTreeIterator1Prev (0.00s)
=== RUN   TestBTreeIterator2Next
--- PASS: TestBTreeIterator2Next (0.00s)
=== RUN   TestBTreeIterator2Prev
--- PASS: TestBTreeIterator2Prev (0.00s)
=== RUN   TestBTreeIterator3Next
--- PASS: TestBTreeIterator3Next (0.00s)
=== RUN   TestBTreeIterator3Prev
--- PASS: TestBTreeIterator3Prev (0.00s)
=== RUN   TestBTreeIterator4Next
--- PASS: TestBTreeIterator4Next (0.00s)
=== RUN   TestBTreeIterator4Prev
--- PASS: TestBTreeIterator4Prev (0.00s)
=== RUN   TestBTreeIteratorBegin
--- PASS: TestBTreeIteratorBegin (0.00s)
=== RUN   TestBTreeIteratorEnd
--- PASS: TestBTreeIteratorEnd (0.00s)
=== RUN   TestBTreeIteratorFirst
--- PASS: TestBTreeIteratorFirst (0.00s)
=== RUN   TestBTreeIteratorLast
--- PASS: TestBTreeIteratorLast (0.00s)
=== RUN   TestBTree_search
--- PASS: TestBTree_search (0.00s)
=== RUN   TestMBTreePut1
--- PASS: TestMBTreePut1 (0.00s)
=== RUN   TestMBTreePut2
--- PASS: TestMBTreePut2 (11.60s)
=== RUN   TestMBTreeRemove1
--- PASS: TestMBTreeRemove1 (0.00s)
PASS
coverage: 94.5% of statements in ../../merkletree/...
ok  	github.com/bradyjoestar/merkletree/merklebtree	16.605s	coverage: 94.5% of statements in ../../merkletree/...

webb.shi

@bradyjoestar bradyjoestar changed the title [support merklebtree] borrow btree from `emirpasic/gods/btree' support merklebtree Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant