Types definition, and generic function for tree-search algorithms