public static void main(String[] args) { UrlValue uv = null; while (true) { uv = new UrlValue(); uv.url = "12345678901234567890"; uv.value = 1; add(uv); System.out.println(size()); } }
// 清除所有优先队列的数据,设置优先种子 private static void SetSeeds(String filepath) throws Exception { pq.clear(); BufferedReader br = new BufferedReader(new FileReader(filepath)); String line = null; UrlValue cur = null; visitedPrint(); while ((line = br.readLine()) != null) { line = line.trim(); // System.out.println(line); if (!line.equals("")) { if (!visitedUrl.contains(line)) { cur = new UrlValue(); cur.url = line; cur.value = 1; pq.offer(cur); } else { System.out.println("contain"); } } } br.close(); }
// 加载待访问的url private static void SetPriorQueue(String filePath) throws Exception { BufferedReader br = new BufferedReader(new FileReader(filePath)); Scanner sc = null; String line = null; String url = null; UrlValue cur = null; while ((line = br.readLine()) != null) { line = line.trim(); if (!line.equals("")) { sc = new Scanner(line); url = sc.next(); if (!visitedUrl.contains(url)) { cur = new UrlValue(); cur.url = url; cur.value = sc.nextDouble(); pq.offer(cur); } } } br.close(); }
public static void add(UrlValue url) { if (url != null && !url.url.trim().equals("") && !visitedUrl.contains(url.url)) { url.url = url.url.trim(); pq.offer(url); } }