About the Java version of Ranker.FindRank(Score_Tuple score)

62 views
Skip to first unread message

Rob

unread,
Jan 4, 2013, 9:52:03 AM1/4/13
to google-app-en...@googlegroups.com
It took me some time to understand why FindRank passing one score returned a list of ranks, I was thinking that it was possible to have more than one rank in that list. Then I found out that it's probably an issue caused by the conversion of a dynamically typed language to one that is not. So I changed the code for FindRank from this:

public ArrayList<Long> FindRank(Score_Tuple score) throws Exception
{
    ArrayList<Score_Tuple> scoreList = new ArrayList<Score_Tuple>();
    scoreList.add(score);
    return FindRanks(scoreList);
}


To this:

public Long FindRank(Score_Tuple score) throws Exception
{
    ArrayList<Long> node_ids = new ArrayList<Long>();
    Map<Long, Entity> nodes_dict;

    ArrayList<NodeID_Child_Tuple> node_ids_with_children = FindNodeIDs(score);

    for(NodeID_Child_Tuple child : node_ids_with_children)
    node_ids.add(child.getNode_id());

    // Query the needed nodes
    nodes_dict = GetMultipleNodes(node_ids);
    return FindRank(node_ids_with_children, nodes_dict);
}

This way you get only one result and don't mess with unnecessary lists. This is a striped version of FindRanks and I don't think it is the best implementation for this case: it seems that the best would be to make something that looks like FindRank(ArrayList<NodeID_Child_Tuple>, Map<Long, Entity>), but since I don't know the inner works of this algorithm I didn't try. Could someone refactor it?

By the way, line 682 should be:

    ArrayList<NodeID_Child_Tuple> node_ids_with_children;
Instead of:
    ArrayList<NodeID_Child_Tuple> node_ids_with_childern = new ArrayList<NodeID_Child_Tuple>();


Thanks
Reply all
Reply to author
Forward
0 new messages