Add circular dependency integrity check.

This commit adds a check to prevent circular dependencies in branch nodes. If a circular dependency occurs then a panic will be called and the commit will be prevented. This only works for a single branch level and will not recursively search the tree.

/cc @snormore @mkobetic