1.1 --- a/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreeindex/Btree.java Thu Nov 18 14:07:38 2004 +0000
1.2 +++ b/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreeindex/Btree.java Thu Nov 18 14:10:51 2004 +0000
1.3 @@ -514,6 +514,13 @@
1.4 pageSource.unpinPage(root);
1.5 }
1.6
1.7 + public TreeMetrics computeMetrics() throws StorageException {
1.8 + BtreePage root = pageSource.getPage(rootPageId, this);
1.9 + TreeMetrics m = root.computeMetrics();
1.10 + pageSource.unpinPage(root);
1.11 + return m;
1.12 + }
1.13 +
1.14 /**
1.15 * Check the btree for consistency, for testing and debugging.
1.16 *
2.1 --- a/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreeindex/BtreePage.java Thu Nov 18 14:07:38 2004 +0000
2.2 +++ b/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreeindex/BtreePage.java Thu Nov 18 14:10:51 2004 +0000
2.3 @@ -1272,6 +1272,22 @@
2.4 *
2.5 * *****************************************************************/
2.6
2.7 + public TreeMetrics computeMetrics() throws StorageException {
2.8 + int totalBytes = pageBuffer.length - headerLength;
2.9 + int usedBytes = totalBytes - freeStart;
2.10 + int num = numEntries();
2.11 + if (!isLeaf()) {
2.12 + TreeMetrics[] m = new TreeMetrics[num];
2.13 + for (int x = 0; x < num; x++) {
2.14 + BtreePage page = pageSource.getPage(getData(x), btree);
2.15 + m[x] = page.computeMetrics();
2.16 + }
2.17 + return TreeMetrics.computeParent(m, totalBytes, usedBytes, num);
2.18 + } else {
2.19 + return new TreeMetrics(1, 1, totalBytes, usedBytes, num, num);
2.20 + }
2.21 + }
2.22 +
2.23 /**
2.24 * Print BtreePage contents for debugging.
2.25 *
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreeindex/TreeMetrics.java Thu Nov 18 14:10:51 2004 +0000
3.3 @@ -0,0 +1,130 @@
3.4 +/*
3.5 + * Sun Public License Notice
3.6 + *
3.7 + * The contents of this file are subject to the Sun Public License
3.8 + * Version 1.0 (the "License"). You may not use this file except in
3.9 + * compliance with the License. A copy of the License is available at
3.10 + * http://www.sun.com/
3.11 + *
3.12 + * The Original Code is NetBeans. The Initial Developer of the Original
3.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
3.14 + * Microsystems, Inc. All Rights Reserved.
3.15 + */
3.16 +package org.netbeans.mdr.persistence.btreeimpl.btreeindex;
3.17 +
3.18 +import java.util.*;
3.19 +
3.20 +public class TreeMetrics {
3.21 +
3.22 + private int depth;
3.23 + private int numOfPages;
3.24 + private long totalBytes;
3.25 + private long usedBytes;
3.26 + private long numOfEntries;
3.27 + private long numOfLeafEntries;
3.28 +
3.29 + public TreeMetrics(int depth, int numOfPages, long totalBytes, long usedBytes, long numOfEntries,
3.30 + long numberOfLeafEntries) {
3.31 +
3.32 + this.depth = depth;
3.33 + this.numOfPages = numOfPages;
3.34 + this.totalBytes = totalBytes;
3.35 + this.usedBytes = usedBytes;
3.36 + this.numOfEntries = numOfEntries;
3.37 + this.numOfLeafEntries = numOfLeafEntries;
3.38 + }
3.39 +
3.40 + /*
3.41 + public TreeMetrics() {
3.42 + this.depth = 0;
3.43 + this.numOfPages = 0;
3.44 + this.totalBytes = 0;
3.45 + this.usedBytes = 0;
3.46 + this.numOfEntries = 0;
3.47 + }
3.48 + */
3.49 +
3.50 + public int getDepth() {
3.51 + return depth;
3.52 + }
3.53 +
3.54 + public int getNumberOfPages() {
3.55 + return numOfPages;
3.56 + }
3.57 +
3.58 + public double getLoadFactor() {
3.59 + return totalBytes > 0 ? (double)usedBytes / (double)totalBytes : 0;
3.60 + }
3.61 +
3.62 + public long getTotalBytes() {
3.63 + return totalBytes;
3.64 + }
3.65 +
3.66 + public long getUsedBytes() {
3.67 + return usedBytes;
3.68 + }
3.69 +
3.70 + public void setDepth(int depth) {
3.71 + this.depth = depth;
3.72 + }
3.73 +
3.74 + public void setNumberOfPages(int numOfPages) {
3.75 + this.numOfPages = numOfPages;
3.76 + }
3.77 +
3.78 + public void setTotalBytes(long totalBytes) {
3.79 + this.totalBytes = totalBytes;
3.80 + }
3.81 +
3.82 + public void setUsedBytes(long usedBytes) {
3.83 + this.usedBytes = usedBytes;
3.84 + }
3.85 +
3.86 + public void print() {
3.87 + System.out.println("depth: " + depth); // NOI18N
3.88 + System.out.println("#pages: " + numOfPages); // NOI18N
3.89 + System.out.println("#entries: " + numOfEntries); // NOI18N
3.90 + System.out.println("#leaf entries: " + numOfEntries); // NOI18N
3.91 + System.out.println("used bytes: " + usedBytes); // NOI18N
3.92 + System.out.println("total bytes: " + totalBytes); // NOI18N
3.93 + System.out.println("load factor: " + getLoadFactor()); // NOI18N
3.94 + }
3.95 +
3.96 + public static TreeMetrics computeParent(TreeMetrics[] m, long tBytes, long uBytes, long entries) {
3.97 + int d = 0;
3.98 + int pages = 0;
3.99 + long bytes = 0;
3.100 + long used = 0;
3.101 + long entrs = 0;
3.102 + long leafEntries = 0;
3.103 +
3.104 + for (int x = 0; x < m.length; x++) {
3.105 + if (m[x].getDepth() > d) {
3.106 + d = m[x].getDepth();
3.107 + }
3.108 + pages += m[x].getNumberOfPages();
3.109 + bytes += m[x].getTotalBytes();
3.110 + used += m[x].getUsedBytes();
3.111 + entrs += m[x].getNumOfEntries();
3.112 + leafEntries += m[x].getNumOfLeafEntries();
3.113 + }
3.114 + return new TreeMetrics(d + 1, pages + 1, bytes + tBytes, used + uBytes, entrs + entries, leafEntries);
3.115 + }
3.116 +
3.117 + public long getNumOfEntries() {
3.118 + return numOfEntries;
3.119 + }
3.120 +
3.121 + public void setNumOfEntries(long numOfEntries) {
3.122 + this.numOfEntries = numOfEntries;
3.123 + }
3.124 +
3.125 + public long getNumOfLeafEntries() {
3.126 + return numOfLeafEntries;
3.127 + }
3.128 +
3.129 + public void setNumOfLeafEntries(long numOfLeafEntries) {
3.130 + this.numOfLeafEntries = numOfLeafEntries;
3.131 + }
3.132 +
3.133 +}