/** * adds request to the data structure: * if the request is new it will be added normally * if the request exists from before it will updated (rank) * if the request exists but has been used (poped) it will do nothing */ public void add(Url request) { if (request == null) { return; } bool match = _urlTrie.Matcher.NewMatch(request.getUrl().Trim()); if (match == false) { PointingNode pNode = new PointingNode(); LinkedListNode <RankNode> pLinkNode = _rankLevels[request.getRank()].addFirstNode(new RankNode(request)); pNode.setRankNode(pLinkNode); pNode.setRankTableEntry(_rankLevels[request.getRank()]); _urlTrie.Put(request.getUrl().Trim(), pNode); if (request.getRank() < _minRank) { _minRank = request.getRank(); } if (request.getRank() > _maxRank) { _maxRank = request.getRank(); } _count++; } else { PointingNode pNode = _urlTrie.Matcher.GetExactMatch(); updateRequest(pNode, request); } }
/** * updates the request ranking */ private void updateRequest(PointingNode pNode, Url newRequest) { if (pNode == null || newRequest == null) { return; } LinkedListNode <RankNode> pLinkNode = pNode.getRankNode(); // the request has been token before if (pLinkNode == null) { return; } pLinkNode.Value.addReference(newRequest.getRank()); int newRank = Convert.ToInt32(pLinkNode.Value.calcRank()); if (newRank != pNode.getRankTableEntry().getRankLevel()) { RankNode rankNode = pLinkNode.Value; pNode.getRankTableEntry().removeNode(pLinkNode); pNode.setRankTableEntry(_rankLevels[newRank]); LinkedListNode <RankNode> newNode = pNode.getRankTableEntry().addFirstNode(rankNode); pNode.setRankNode(newNode); //if (newRank < _minRank) _minRank = newRank; //if (newRank > _maxRank) _maxRank = newRank; update(); } }
/** * returns the max ranked element (pop) */ public Url pop() { if (_count <= 0) { return(null); } RankNode rankNode = _rankLevels[_maxRank].readFirstNode(); _rankLevels[_maxRank].removeFirstNode(); bool match = _urlTrie.Matcher.NewMatch(rankNode.getRequest().getUrl().Trim()); if (match == true) { PointingNode pNode = _urlTrie.Matcher.GetExactMatch(); pNode.setRankTableEntry(null); pNode.setRankNode(null); } _count--; update(); Url request = rankNode.getRequest(); int rank = Convert.ToInt32(rankNode.calcRank()); return(new Url(request.getUrl(), request.getUrlHashCode(), rank, request.getDomain(), request.getDomainHashCode())); }
/** * adds request to the data structure: * if the request is new it will be added normally * if the request exists from before it will updated (rank) * if the request exists but has been used (poped) it will do nothing */ public void add(Url request) { if (request == null) return; bool match = _urlTrie.Matcher.NewMatch(request.getUrl().Trim()); if (match == false) { PointingNode pNode = new PointingNode(); LinkedListNode<RankNode> pLinkNode = _rankLevels[request.getRank()].addFirstNode(new RankNode(request)); pNode.setRankNode(pLinkNode); pNode.setRankTableEntry(_rankLevels[request.getRank()]); _urlTrie.Put(request.getUrl().Trim(), pNode); if (request.getRank() < _minRank) _minRank = request.getRank(); if (request.getRank() > _maxRank) _maxRank = request.getRank(); _count++; } else { PointingNode pNode = _urlTrie.Matcher.GetExactMatch(); updateRequest(pNode, request); } }
/** * updates the request ranking */ private void updateRequest(PointingNode pNode, Url newRequest) { if (pNode == null || newRequest == null) return; LinkedListNode<RankNode> pLinkNode = pNode.getRankNode(); // the request has been token before if (pLinkNode == null) return; pLinkNode.Value.addReference(newRequest.getRank()); int newRank = Convert.ToInt32(pLinkNode.Value.calcRank()); if (newRank != pNode.getRankTableEntry().getRankLevel()) { RankNode rankNode = pLinkNode.Value; pNode.getRankTableEntry().removeNode(pLinkNode); pNode.setRankTableEntry(_rankLevels[newRank]); LinkedListNode<RankNode> newNode = pNode.getRankTableEntry().addFirstNode(rankNode); pNode.setRankNode(newNode); //if (newRank < _minRank) _minRank = newRank; //if (newRank > _maxRank) _maxRank = newRank; update(); } }