-
Notifications
You must be signed in to change notification settings - Fork 534
difftree: merkletrie internal package with iterator #133
difftree: merkletrie internal package with iterator #133
Conversation
Great job! The Maybe you can you modify this to work directly with Tree and create a fixture generator form the current fixtures? I know you said that the main reason to do this |
Thank you very much @mcuadros . You raised a very good point. I have not yet decided how I'm going to implement this. As you have already introduced, there are two ways: A) Make Both ways are going to be equally efficient as both of them do the same amount of work. In all the cases the children creation is deferred until it is needed, so the tree will be built (and destroyed) at the same time as the iterator goes over it. The rest of fields needed by the Noder are already in the Tree so we will not waste any time, nor memory. So, in my opinion is a matter of taste and style. Solution A introduces some new functionality to Solution B helps to keep responsibilities separated, but also hides the relationship between Unrelated question: the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
package merkletrie | ||
|
||
// The Noder interface is implemented by the elements of a Merkle Trie. | ||
type Noder interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be in utils/iterators
, but maybe we can wait until we want to actually use it for other algorithms (e.g. commit walk, tree walk).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree.
I'll probably move it in the next patch, after having used it a little bit for some real work.
This patch is the first in a series of patches to make our current implementation of difftree more efficient. The current version is slow for repositories with lots of files, see https://github.com/alcortesm/git-diff-tree-benchmarks/blob/master/README.md for details.
The plan is to improve difftree performance by taking advantage of git trees being Merkle trees, and skip comparing whole directories by just checking that their hash has not change.
This patch is the first step towards that, it introduces a new merkletrie package with support for Radix-Merkle trees and its comparison.
Currently only the tree iterator is implemented, the comparison will come in a future patch. For the iterator to be useful for the future comparison implementation it has to be able to go into directories or skip them completely, depending on what the user wants in each moment.
How to review this PR:
doc.go
file, refresh merkle trees and radix trees on wikipedia if needed.noder.go
, this is, the node interface for the tree. It should be easy in the future to change git.Tree to implement this interface.node.go
andnode_test.go
for a simple implementation ofNoder
that helps me test the package.frame.go
andframe_test.go
to learn how to represent siblings in a nice way.iter.go
for the iterator. Warning: It does heavy use of nested stacks.iter_test.go
anditer_fixtures.go
for some combinatorial forest fun.Notes: please take special attention to: