Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-538 - Delete unused classes under o.a.n.util.

Tacettin Guney3fdaed8baf2b
diff --git a/CHANGES.txt b/CHANGES.txt
index 1844f9642..dbf0d4ceb 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -164,6 +164,8 @@ Unreleased changes (1.0-dev)
56. NUTCH-548 - Move URLNormalizer from Outlink to ParseOutputFormat.
(Emmanuel Joke via dogacan)
+57. NUTCH-538 - Delete unused classes under o.a.n.util. (dogacan)
+
Release 0.9 - 2007-04-02
1. Changed log4j confiquration to log to stdout on commandline
diff --git a/src/java/org/apache/nutch/util/FibonacciHeap.java b/src/java/org/apache/nutch/util/FibonacciHeap.java
deleted file mode 100644
index 0cb239903..000000000
--- a/src/java/org/apache/nutch/util/FibonacciHeap.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.nutch.util;
-
-import java.util.HashMap;
-
-/**
- * A Fibonacci Heap, as described in <i>Introduction to Algorithms</i> by
- * Charles E. Leiserson, Thomas H. Cormen, Ronald L. Rivest.
- *
- * <p>
- *
- * A Fibonacci heap is a very efficient data structure for priority
- * queuing.
- *
- */
-public class FibonacciHeap {
- private FibonacciHeapNode min;
- private HashMap<Object, FibonacciHeapNode> itemsToNodes;
-
- // private node class
- private static class FibonacciHeapNode {
- private Object userObject;
- private int priority;
-
- private FibonacciHeapNode parent;
- private FibonacciHeapNode prevSibling;
- private FibonacciHeapNode nextSibling;
- private FibonacciHeapNode child;
- private int degree;
- private boolean mark;
-
- FibonacciHeapNode(Object userObject, int priority) {
- this.userObject= userObject;
- this.priority= priority;
-
- this.parent= null;
- this.prevSibling= this;
- this.nextSibling= this;
- this.child= null;
- this.degree= 0;
- this.mark= false;
- }
-
- public String toString() {
- return "["+userObject+", "+degree+"]";
- }
- }
-
- /**
- * Creates a new <code>FibonacciHeap</code>.
- */
- public FibonacciHeap() {
- this.min= null;
- this.itemsToNodes= new HashMap<Object, FibonacciHeapNode>();
- }
-
- /**
- * Adds the Object <code>item</code>, with the supplied
- * <code>priority</code>.
- */
- public void add(Object item, int priority) {
- if (itemsToNodes.containsKey(item))
- throw new IllegalStateException("heap already contains item! (item= "
- + item + ")");
- FibonacciHeapNode newNode= new FibonacciHeapNode(item, priority);
- itemsToNodes.put(item, newNode);
-
- if (min == null) {
- min= newNode;
- } else {
- concatenateSiblings(newNode, min);
- if (newNode.priority < min.priority)
- min= newNode;
- }
- }
-
- /**
- * Returns <code>true</code> if <code>item</code> exists in this
- * <code>FibonacciHeap</code>, false otherwise.
- */
- public boolean contains(Object item) {
- return itemsToNodes.containsKey(item);
- }
-
- // makes x's nextSibling and prevSibling point to itself
- private void removeFromSiblings(FibonacciHeapNode x) {
- if (x.nextSibling == x)
- return;
- x.nextSibling.prevSibling= x.prevSibling;
- x.prevSibling.nextSibling= x.nextSibling;
- x.nextSibling= x;
- x.prevSibling= x;
- }
-
- // joins siblings lists of a and b
- private void concatenateSiblings(FibonacciHeapNode a, FibonacciHeapNode b) {
- a.nextSibling.prevSibling= b;
- b.nextSibling.prevSibling= a;
- FibonacciHeapNode origAnext= a.nextSibling;
- a.nextSibling= b.nextSibling;
- b.nextSibling= origAnext;
- }
-
- /**
- * Returns the same Object that {@link #popMin()} would, without
- * removing it.
- */
- public Object peekMin() {
- if (min == null)
- return null;
- return min.userObject;
- }
-
- /**
- * Returns the number of objects in the heap.
- */
- public int size() {
- return itemsToNodes.size();
- }
-
- /**
- * Returns the object which has the <em>lowest</em> priority in the
- * heap. If the heap is empty, <code>null</code> is returned.
- */
- public Object popMin() {
- if (min == null)
- return null;
- if (min.child != null) {
- FibonacciHeapNode tmp= min.child;
- // rempve parent pointers to min
- while (tmp.parent != null) {
- tmp.parent= null;
- tmp= tmp.nextSibling;
- }
- // add children of min to root list
- concatenateSiblings(tmp, min);
- }
- // remove min from root list
- FibonacciHeapNode oldMin= min;
- if (min.nextSibling == min) {
- min= null;
- } else {
- min= min.nextSibling;
- removeFromSiblings(oldMin);
- consolidate();
- }
- itemsToNodes.remove(oldMin.userObject);
- return oldMin.userObject;
- }
-
- // consolidates heaps of same degree
- private void consolidate() {
- int size= size();
- FibonacciHeapNode[] newRoots= new FibonacciHeapNode[size];
-
- FibonacciHeapNode node= min;
- FibonacciHeapNode start= min;
- do {
- FibonacciHeapNode x= node;
- int currDegree= node.degree;
- while (newRoots[currDegree] != null) {
- FibonacciHeapNode y= newRoots[currDegree];
- if (x.priority > y.priority) {
- FibonacciHeapNode tmp= x;
- x= y;
- y= tmp;
- }
- if (y == start) {
- start= start.nextSibling;
- }
- if (y == node) {
- node= node.prevSibling;
- }
- link(y, x);
- newRoots[currDegree++]= null;
- }
- newRoots[currDegree]= x;
- node= node.nextSibling;
- } while (node != start);
-
- min= null;
- for (int i= 0; i < newRoots.length; i++)
- if (newRoots[i] != null) {
- if ( (min == null)
- || (newRoots[i].priority < min.priority) )
- min= newRoots[i];
- }
- }
-
- // links y under x
- private void link(FibonacciHeapNode y, FibonacciHeapNode x) {
- removeFromSiblings(y);
- y.parent= x;
- if (x.child == null)
- x.child= y;
- else
- concatenateSiblings(x.child, y);
- x.degree++;
- y.mark= false;
- }
-
- /**
- * Decreases the <code>priority</code> value associated with
- * <code>item</code>.
- *
- * <p>
- *
- * <code>item<code> must exist in the heap, and it's current
- * priority must be greater than <code>priority</code>.
- *
- * @throws IllegalStateException if <code>item</code> does not exist
- * in the heap, or if <code>item</code> already has an equal or
- * lower priority than the supplied<code>priority</code>.
- */
- public void decreaseKey(Object item, int priority) {
- FibonacciHeapNode node=
- itemsToNodes.get(item);
- if (node == null)
- throw new IllegalStateException("No such element: " + item);
- if (node.priority < priority)
- throw new IllegalStateException("decreaseKey(" + item + ", "
- + priority + ") called, but priority="
- + node.priority);
- node.priority= priority;
- FibonacciHeapNode parent= node.parent;
- if ( (parent != null) && (node.priority < parent.priority) ) {
- cut(node, parent);
- cascadingCut(parent);
- }
- if (node.priority < min.priority)
- min= node;
-
- }
-
- // cut node x from below y
- private void cut(FibonacciHeapNode x, FibonacciHeapNode y) {
- // remove x from y's children
- if (y.child == x)
- y.child= x.nextSibling;
- if (y.child == x)
- y.child= null;
-
- y.degree--;
- removeFromSiblings(x);
- concatenateSiblings(x, min);
- x.parent= null;
- x.mark= false;
-
- }
-
- private void cascadingCut(FibonacciHeapNode y) {
- FibonacciHeapNode z= y.parent;
- if (z != null) {
- if (!y.mark) {
- y.mark= true;
- } else {
- cut(y, z);
- cascadingCut(z);
- }
- }
- }
-
-}
diff --git a/src/java/org/apache/nutch/util/ThreadPool.java b/src/java/org/apache/nutch/util/ThreadPool.java
deleted file mode 100644
index acbeafbb4..000000000
--- a/src/java/org/apache/nutch/util/ThreadPool.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.nutch.util;
-
-import java.util.*;
-
-// Commons Logging imports
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-
-/************************************************
- * ThreadPool.java
- *
- * ThreadPool maintains a large set of threads, which
- * can be dedicated to a certain task, and then recycled.
- ***********************************************/
-public class ThreadPool {
- /**
- * A TaskThread sits in a loop, asking the pool
- * for a job, and servicing it. That's all it does.
- */
- class TaskThread extends Thread {
- /**
- * Get a job from the pool, run it, repeat.
- * If the job is null, we exit the loop.
- */
- public void run() {
- while (true) {
- Runnable r = obtainJob();
- if (r == null) {
- break;
- }
- try {
- r.run();
- } catch (Exception e) {
- System.err.println("E: " + e);
- e.printStackTrace();
- }
- }
- }
- }
-
- int numThreads;
- boolean running = false;
- Vector<Runnable> jobs;
-
- /**
- * Creates a pool of numThreads size.
- * These threads sit around waiting for jobs to
- * be posted to the list.
- */
- public ThreadPool(int numThreads) {
- this.numThreads = numThreads;
- jobs = new Vector<Runnable>(37);
- running = true;
-
- for (int i = 0; i < numThreads; i++) {
- TaskThread t = new TaskThread();
- t.start();
- }
- Log l = LogFactory.getLog("org.apache.nutch.util");
- if (l.isDebugEnabled()) {
- l.debug("ThreadPool created with " + numThreads + " threads.");
- }
- }
-
- /**
- * Gets a job from the queue, returns to worker thread.
- * When the pool is closed down, return null for all
- * obtainJob() requests. That tells the thread to
- * shut down.
- */
- Runnable obtainJob() {
- Runnable job = null;
-
- synchronized (jobs) {
- while (job == null && running) {
- try {
- if (jobs.size() == 0) {
- jobs.wait();
- }
- } catch (InterruptedException ie) {
- }
-
- if (jobs.size() > 0) {
- job = jobs.firstElement();
- jobs.removeElementAt(0);
- }
- }
- }
-
- if (running) {
- // Got a job from the queue
- return job;
- } else {
- // Shut down the pool
- return null;
- }
- }
-
- /**
- * Post a Runnable to the queue. This will be
- * picked up by an active thread.
- */
- public void addJob(Runnable runnable) {
- synchronized (jobs) {
- jobs.add(runnable);
- jobs.notifyAll();
- }
- }
-
- /**
- * Turn off the pool. Every thread, when finished with
- * its current work, will realize that the pool is no
- * longer running, and will exit.
- */
- public void shutdown() {
- running = false;
- Log l = LogFactory.getLog("org.apache.nutch.util");
- if (l.isDebugEnabled()) {
- l.debug("ThreadPool shutting down.");
- }
- }
-}