Olá,
Não ficou claro para mim exatamente como deve ser o API dessa classe, por exemplo:
O correto seria public void put(Point2D p, Value val) ou public void put(Node p, Value val) (onde Node p contém um objeto p)? O enunciado diz "implement the same API (but renaming PointST to KdTreeST)", mas não tenho certeza se podemos (ou devemos) fazer esse tipo de alteração.
Oi Gabriel,
Legal que você perguntou!
O enunciado diz "implement the same API (but renaming PointST to KdTreeST)",
Isso significa que a API deve ser:
public class KdTreeST<Value> { public KdTreeST() // construct an empty symbol table of points public boolean isEmpty() // is the symbol table empty? public int size() // number of points public void put(Point2D p, Value val) // associate the value val with point p public Value get(Point2D p) // value associated with point p public boolean contains(Point2D p) // does the symbol table contain point p? public Iterable<Point2D> points() // all points in the symbol table public Iterable<Point2D> range(RectHV rect) // all points that are inside the rectangle (or on the boundary) public Point2D nearest(Point2D p) // a nearest neighbor of point p; null if the symbol table is empty public static void main(String[] args) // unit testing (required) }
Olhe a seguir como PointST e KdTreeST são usadas por RangeSearchVisualizer
public static void main(String[] args) { // initialize the data structures with n points from file String filename = args[0]; In in = new In(filename); PointST<Integer> brute = new PointST<Integer>(); KdTreeST<Integer> kdtree = new KdTreeST<Integer>(); for (int i = 0; !in.isEmpty(); i++) { double x = in.readDouble(); double y = in.readDouble(); Point2D p = new Point2D(x, y); kdtree.put(p, i); brute.put(p, i); } [...]
Entendi Professor! muito obrigado!
Em um assunto relacionado ao post, gostaria de saber se estamos usando KdTreeST<Value> e não KdTreeST<Key extends Comparable<Key>, Value> pelo fato da nossa árvore só funcionar com Point2D como key, ou se isso se deve a outro fato.
Ois,
gostaria de saber se estamos usando KdTreeST<Value> e não KdTreeST<Key extends Comparable<Key>, Value>pelo fato da nossa árvore só funcionar com Point2D como key,
É isso mesmo. Usamos KdTreeST<Value> pois as chaves são Ponto2D e não genéricas.
Gabriel,
Para fazer essa API estou me baseando em BST.java. Por exemplo, a função put() de BST é:
public void put(Key key, Value val)
private Node put(Node x, Key key, Value val)
Então, estou fazendo a função put() de KdTreeST.java trocando Key key por Point2D p.
Ainda estou testando, mas me parece correto.
O que você acha?
Oi,
eu acabei pensando a mesma coisa algum tempo depois que fiz o post, acho que é o que faz mais sentido mesmo, já que, de certa forma, tem que haver alguma função que aceita Node como um argumento.