svn commit: r523125 - in /xml/xindice/trunk/java/src/org/apache/xindice/core/filer: BTree.java BTreeFiler.java HashFiler.java Paged.java

[email protected]
Newsgroups gmane.text.xml.xindice.devel
Message-ID <[email protected]>
Author: vgritsenko
Date: Tue Mar 27 17:22:42 2007
New Revision: 523125

URL: http://svn.apache.org/viewvc?view=rev&rev=523125
Log:
replace Long with long

Modified:
    xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java?view=diff&rev=523125&r1=523124&r2=523125
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java Tue Mar 27 17:22:42 2007
@@ -124,7 +124,7 @@
                 super.open();
 
                 Page p = getFreePage();
-                long pn = p.getPageNum().longValue();
+                long pn = p.getPageNum();
                 fileHeader.setRootPage(pn);
 
                 rootInfo = new BTreeRootInfo(pn);
@@ -134,7 +134,7 @@
                 rootNode.ph.setStatus(LEAF);
                 rootNode.write();
                 synchronized (cache) {
-                    cache.put(rootNode.page.getPageNum(), new WeakReference(rootNode));
+                    cache.put(rootNode.page, new WeakReference(rootNode));
                 }
                 close();
                 return true;
@@ -256,7 +256,7 @@
         BTreeNode n = createBTreeNode(BTree.LEAF, null);
         n.write();
 
-        long position = n.page.getPageNum().longValue();
+        long position = n.page.getPageNum();
         addValue(v, position);
         return new BTreeRootInfo(v, position);
     }
@@ -273,7 +273,7 @@
         BTreeNode n = createBTreeNode(BTree.LEAF, null);
         n.write();
 
-        long position = n.page.getPageNum().longValue();
+        long position = n.page.getPageNum();
         addValue(v, position);
         return new BTreeRootInfo(root, v, position);
     }
@@ -317,11 +317,11 @@
         BTreeRootInfo parent = root.getParent();
         if (parent == null) {
             rootNode = newRoot;
-            long p = rootNode.page.getPageNum().longValue();
+            long p = rootNode.page.getPageNum();
             rootInfo.setPage(p);
             fileHeader.setRootPage(p);
         } else {
-            long p = newRoot.page.getPageNum().longValue();
+            long p = newRoot.page.getPageNum();
             root.setPage(p);
             addValue(parent, root.name, p);
         }
@@ -367,7 +367,7 @@
         try {
             BTreeNode node = null;
             synchronized (cache) {
-                WeakReference ref = (WeakReference) cache.get(new Long(page));
+                WeakReference ref = (WeakReference) cache.get(new PageKey(page));
                 if (ref != null) {
                     node = (BTreeNode) ref.get();
                 }
@@ -378,7 +378,7 @@
                     node.parent = parent;
                 }
 
-                cache.put(node.page.getPageNum(), new WeakReference(node));
+                cache.put(node.page, new WeakReference(node));
             }
 
             node.read();
@@ -396,7 +396,7 @@
         BTreeNode node = new BTreeNode(p, parent, new Value[0], new long[0]);
         node.ph.setStatus(status);
         synchronized (cache) {
-            cache.put(p.getPageNum(), new WeakReference(node));
+            cache.put(p, new WeakReference(node));
         }
         return node;
     }
@@ -725,8 +725,8 @@
                         separator
                     },
                     new long[] {
-                        lNode.page.getPageNum().longValue(),
-                        rNode.page.getPageNum().longValue()
+                        lNode.page.getPageNum(),
+                        rNode.page.getPageNum()
                     });
 
                 write();
@@ -741,7 +741,7 @@
                 write();
                 rNode.write();
                 parent.promoteValue(separator,
-                                    rNode.page.getPageNum().longValue());
+                                    rNode.page.getPageNum());
             }
         }
 
@@ -922,7 +922,6 @@
                                 if (rightIdx < 0) {
                                     rightIdx = -(rightIdx + 1);
                                 }
-
                                 for (int i = rightIdx; i < ptrs.length; i++) {
                                     if (query.testValue(values[i])) {
                                         callback.indexInfo(values[i], ptrs[i]);

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java?view=diff&rev=523125&r1=523124&r2=523125
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java Tue Mar 27 17:22:42 2007
@@ -135,7 +135,7 @@
                 p = getPage(pos);
             } catch (BTreeNotFoundException e) {
                 p = getFreePage();
-                addValue(key, p.getPageNum().longValue());
+                addValue(key, p.getPageNum());
                 fileHeader.incRecordCount();
             }
 

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java?view=diff&rev=523125&r1=523124&r2=523125
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java Tue Mar 27 17:22:42 2007
@@ -171,7 +171,7 @@
                     // Reached end of chain, add new page
                     Page np = getFreePage();
 
-                    ph.setNextCollision(np.getPageNum().longValue());
+                    ph.setNextCollision(np.getPageNum());
                     p.write();
 
                     p = np;
@@ -238,7 +238,7 @@
     protected void unlinkPages(Page page) throws IOException {
         // Handle the page if it's in primary space by setting its status to
         // DELETED and freeing any overflow pages linked to it.
-        if (page.getPageNum().longValue() < fileHeader.getPageCount()) {
+        if (page.getPageNum() < fileHeader.getPageCount()) {
             long nextPage = page.getPageHeader().getNextPage();
             page.getPageHeader().setStatus(DELETED);
             page.getPageHeader().setNextPage(NO_PAGE);

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java?view=diff&rev=523125&r1=523124&r2=523125
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java Tue Mar 27 17:22:42 2007
@@ -338,11 +338,11 @@
      * @throws IOException if an Exception occurs
      */
     protected final Page getPage(long pageNum) throws IOException {
-        final Page lp = new Page(new Long(pageNum));
+        final PageKey k = new PageKey(pageNum);
         Page p = null;
         synchronized (pagesLock) {
             // Check if page is already loaded in the page cache
-            WeakReference ref = (WeakReference) pages.get(lp);
+            WeakReference ref = (WeakReference) pages.get(k);
             if (ref != null) {
                 p = (Page) ref.get();
                 // Fall through to p.read(). Even if page present in the pages
@@ -352,7 +352,7 @@
 
             // If not found, create it and add it to the pages cache
             if (p == null) {
-                p = new Page(new Long(pageNum));
+                p = new Page(pageNum);
                 pages.put(p, new WeakReference(p));
             }
         }
@@ -439,7 +439,7 @@
             } else {
                 // Create a new overflow page
                 page = getFreePage();
-                lhdr.setNextPage(page.getPageNum().longValue());
+                lhdr.setNextPage(page.getPageNum());
             }
 
             // Mark the page as an overflow page.
@@ -483,11 +483,11 @@
     protected void unlinkPages(Page page) throws IOException {
         // Add any overflow pages to the list of free pages.
         // Get the first and last page in the chain.
-        long firstPage = page.pageNum.longValue();
+        long firstPage = page.pageNum;
         while (page.header.nextPage != NO_PAGE) {
             page = getPage(page.header.nextPage);
         }
-        long lastPage = page.pageNum.longValue();
+        long lastPage = page.pageNum;
 
         // Free the chain
         synchronized (fileHeader) {
@@ -685,7 +685,7 @@
     void addDirty(Page page) throws IOException {
         boolean flush;
         synchronized (dirtyLock) {
-            dirty.put(page.pageNum, page);
+            dirty.put(page, page);
             flush = dirty.size() > MAX_DIRTY_SIZE;
         }
 
@@ -1224,13 +1224,63 @@
     }
 
     /**
-     * Paged file's page
+     * The object wrapping page number.
      */
-    protected final class Page implements Comparable {
+    protected static class PageKey implements Comparable {
+
         /**
          * This page number
          */
-        private final Long pageNum;
+        protected final long pageNum;
+
+
+        public PageKey(long pageNum) {
+            this.pageNum = pageNum;
+        }
+
+        // No synchronization - pageNum is final
+        public long getPageNum() {
+            return pageNum;
+        }
+
+        // No synchronization: pageNum is final.
+        public int compareTo(Object o) {
+            return (int) (pageNum - ((PageKey) o).pageNum);
+        }
+
+        /**
+         * Return page hash code, which is hash code of its {@link #pageNum}.
+         *
+         * @return Page hash code
+         */
+        public int hashCode() {
+            // Unroll new Long(pageNum).hashCode()
+            return (int) (pageNum ^ (pageNum >> 32));
+        }
+
+        /**
+         * Pages are equal if they are the same or have equal pageNum.
+         *
+         * @param obj Another page
+         * @return true if pages are equal
+         */
+        public boolean equals(Object obj) {
+            if (obj == this) {
+                return true;
+            }
+
+            if (obj instanceof PageKey) {
+                return pageNum == ((PageKey) obj).pageNum;
+            }
+
+            return false;
+        }
+    }
+
+    /**
+     * Paged file's page
+     */
+    protected final class Page extends PageKey {
 
         /**
          * The Header for this Page
@@ -1258,10 +1308,10 @@
         private int dataPos;
 
 
-        private Page(Long pageNum) {
+        private Page(long pageNum) {
+            super(pageNum);
             this.header = createPageHeader();
-            this.pageNum = pageNum;
-            this.offset = fileHeader.headerSize + (pageNum.longValue() * fileHeader.pageSize);
+            this.offset = fileHeader.headerSize + (pageNum * fileHeader.pageSize);
         }
 
         /**
@@ -1328,11 +1378,6 @@
             }
         }
 
-        // No synchronization - pageNum is final
-        public Long getPageNum() {
-            return this.pageNum;
-        }
-
         // No synchronization - header is final
         public PageHeader getPageHeader() {
             return this.header;
@@ -1370,38 +1415,6 @@
             if (header.dataLen > 0) {
                 is.read(this.data, this.keyPos + header.keyLen, header.dataLen);
             }
-        }
-
-        // No synchronization: pageNum is final.
-        public int compareTo(Object o) {
-            return (int) (pageNum.longValue() - ((Page) o).pageNum.longValue());
-        }
-
-        /**
-         * Return page hash code, which is hash code of its {@link #pageNum}.
-         *
-         * @return Page hash code
-         */
-        public int hashCode() {
-            return pageNum.hashCode();
-        }
-
-        /**
-         * Pages are equal if they are the same or have equal pageNum.
-         *
-         * @param obj Another page
-         * @return true if pages are equal
-         */
-        public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
-            }
-
-            if (obj instanceof Page) {
-                return pageNum.longValue() == ((Page) obj).pageNum.longValue();
-            }
-
-            return false;
         }
     }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.