1 19 package org.netbeans.mdr.persistence.btreeimpl.btreeindex; 20 21 import java.io.PrintStream ; 22 23 public class TreeMetrics { 24 25 private int depth; 26 private int numOfPages; 27 private long totalBytes; 28 private long usedBytes; 29 private long numOfEntries; 30 private long numOfLeafEntries; 31 32 public TreeMetrics(int depth, int numOfPages, long totalBytes, long usedBytes, long numOfEntries, 33 long numberOfLeafEntries) { 34 35 this.depth = depth; 36 this.numOfPages = numOfPages; 37 this.totalBytes = totalBytes; 38 this.usedBytes = usedBytes; 39 this.numOfEntries = numOfEntries; 40 this.numOfLeafEntries = numberOfLeafEntries; 41 } 42 43 52 53 public int getDepth() { 54 return depth; 55 } 56 57 public int getNumberOfPages() { 58 return numOfPages; 59 } 60 61 public double getLoadFactor() { 62 return totalBytes > 0 ? (double)usedBytes / (double)totalBytes : 0; 63 } 64 65 public long getTotalBytes() { 66 return totalBytes; 67 } 68 69 public long getUsedBytes() { 70 return usedBytes; 71 } 72 73 public void setDepth(int depth) { 74 this.depth = depth; 75 } 76 77 public void setNumberOfPages(int numOfPages) { 78 this.numOfPages = numOfPages; 79 } 80 81 public void setTotalBytes(long totalBytes) { 82 this.totalBytes = totalBytes; 83 } 84 85 public void setUsedBytes(long usedBytes) { 86 this.usedBytes = usedBytes; 87 } 88 89 public void print(PrintStream stream) { 90 stream.println("depth: " + depth); stream.println("#pages: " + numOfPages); stream.println("#entries: " + numOfEntries); stream.println("#leaf entries: " + numOfLeafEntries); stream.println("used bytes: " + usedBytes); stream.println("total bytes: " + totalBytes); stream.println("load factor: " + getLoadFactor()); } 98 99 public static TreeMetrics computeParent(TreeMetrics[] m, long tBytes, long uBytes, long entries) { 100 int d = 0; 101 int pages = 0; 102 long bytes = 0; 103 long used = 0; 104 long entrs = 0; 105 long leafEntries = 0; 106 107 for (int x = 0; x < m.length; x++) { 108 if (m[x].getDepth() > d) { 109 d = m[x].getDepth(); 110 } 111 pages += m[x].getNumberOfPages(); 112 bytes += m[x].getTotalBytes(); 113 used += m[x].getUsedBytes(); 114 entrs += m[x].getNumOfEntries(); 115 leafEntries += m[x].getNumOfLeafEntries(); 116 } 117 return new TreeMetrics(d + 1, pages + 1, bytes + tBytes, used + uBytes, entrs + entries, leafEntries); 118 } 119 120 public long getNumOfEntries() { 121 return numOfEntries; 122 } 123 124 public void setNumOfEntries(long numOfEntries) { 125 this.numOfEntries = numOfEntries; 126 } 127 128 public long getNumOfLeafEntries() { 129 return numOfLeafEntries; 130 } 131 132 public void setNumOfLeafEntries(long numOfLeafEntries) { 133 this.numOfLeafEntries = numOfLeafEntries; 134 } 135 136 } 137 | Popular Tags |