do { cs = openCats.poll(); } while (hasMoreResults() && catDistances.contains(cs.getCatIndex())); visited.cats.put(cs.getCatIndex(), cs.getDistance()); catDistances.put(cs.getCatIndex(), cs.getDistance()); for (int i : graph.catPages[cs.getCatIndex()]) { if (validWpIds != null && !validWpIds.contains(i)) { continue; if (!pageDistances.containsKey(i) || pageDistances.get(i) > cs.getDistance()) { pageDistances.put(i, cs.getDistance()); visited.pages.put(i, cs.getDistance()); for (int i : graph.catChildren[cs.getCatIndex()]) { if (!catDistances.containsKey(i)) { double d = cs.getDistance() + graph.catCosts[i]; openCats.add(new CategoryDistance(i, graph.cats[i], d, (byte)-1)); if (cs.getDirection() == +1) { for (int i : graph.catParents[cs.getCatIndex()]) { if (!catDistances.containsKey(i)) { double d = cs.getDistance() + graph.catCosts[i]; openCats.add(new CategoryDistance(i, graph.cats[i], d, (byte)+1));
public CategoryBfs(CategoryGraph graph, int startId, NameSpace startNamespace, Language language, int maxResults, TIntSet validWpIds, LocalCategoryMemberDao categoryMemberDao, int direction) throws DaoException { this.startPage = startId; this.maxResults = maxResults; this.graph = graph; this.validWpIds = validWpIds; this.categoryMemberDao = categoryMemberDao; this.language = language; pageDistances.put(startPage, 0.000000); if (startNamespace == NameSpace.ARTICLE) { Collection<Integer> cats = categoryMemberDao.getCategoryIds(language, startId); if (cats!=null){ for (int catId : cats) { int ci = graph.catIdToIndex(catId); if (ci >= 0) { openCats.add(new CategoryDistance(ci, graph.cats[ci], graph.catCosts[ci], (byte)direction)); } } } } else if (startNamespace == NameSpace.CATEGORY) { int ci = graph.catIdToIndex(startId); if (ci >= 0) { openCats.add(new CategoryDistance(ci, graph.cats[ci], 0.000000001, (byte)direction)); } } else { throw new IllegalArgumentException(); } }