Small refactorings and ceosmetic changes

This commit is contained in:
Florian Weingarten 2015-04-29 20:59:06 -04:00
parent a906b9febe
commit c9f1f08019
7 changed files with 97 additions and 111 deletions

View file

@ -60,9 +60,8 @@ func (t Tree) Equals(other *Tree) bool {
}
func (t *Tree) Insert(node *Node) error {
pos, _, err := t.find(node.Name)
pos, _, err := t.binarySearch(node.Name)
if err == nil {
// already present
return ErrNodeAlreadyInTree
}
@ -74,7 +73,7 @@ func (t *Tree) Insert(node *Node) error {
return nil
}
func (t Tree) find(name string) (int, *Node, error) {
func (t Tree) binarySearch(name string) (int, *Node, error) {
pos := sort.Search(len(t.Nodes), func(i int) bool {
return t.Nodes[i].Name >= name
})
@ -87,6 +86,6 @@ func (t Tree) find(name string) (int, *Node, error) {
}
func (t Tree) Find(name string) (*Node, error) {
_, node, err := t.find(name)
_, node, err := t.binarySearch(name)
return node, err
}