📄 containerlocationloc.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Core License version 1 published by ozone-db.org.//// Copyright (C) 2003-@year@, Leo Mekenkamp. All rights reserved.//// $Id: ContainerLocationLoc.java,v 1.3 2004/03/21 21:05:51 leomekenkamp Exp $package org.ozoneDB.core.storage.gammaStore;import java.io.BufferedOutputStream;import java.io.FileOutputStream;import java.io.ObjectOutputStream;/** * @author <a href="mailto:leoATmekenkampD0Tcom">Leo Mekenkamp (mind the anti sp@m)</a> * @version $Id: ContainerLocationLoc.java,v 1.3 2004/03/21 21:05:51 leomekenkamp Exp $ */public class ContainerLocationLoc extends Loc { protected int[] dataFileIds; protected int[] positions; // Encoding both clusterId and position into a long and storing it into one// long[] instead of two int[] yielded no significant performance increase.// Maybe there is something I missed, so the code will remain in the source, in// the form of comments.// protected long[] both; public ContainerLocationLoc(int capacity, float bufferFactor) { super(capacity, bufferFactor); init(); } public ContainerLocationLoc(int capacity, int slack) { super(capacity, slack); init(); } private void init() {// dataFileIds = new int[keys.length]; positions = new int[keys.length];// both = new long[keys.length]; } /** * Note that we do not store <code>containerLocation</code> as an * object, we simply take its values and copy it into internal arrays. * This saves a _lot_ of execution time during (de)serialization. */ public void putContainerLocation(int pos, ContainerLocation containerLocation) {// dataFileIds[pos] = containerLocation.getDataFileId(); positions[pos] = containerLocation.getPosition();// both[pos] = toLong(containerLocation); } protected void move(int from, int to) { super.move(from, to);// dataFileIds[to] = dataFileIds[from]; positions[to] = positions[from];// both[to] = both[from]; } // /**// * Convenience method to make it easy to reuse <code>ContainerLocation</code>// * instances.// */// public void fillContainerLocation(int pos, ContainerLocation containerLocation) {////// containerLocation.getDataFileId() = dataFileIds[pos];// containerLocation.getPosition() = positions[pos];//// fromLong(both[pos], containerLocation);2// } public ContainerLocation getContainerLocation(int pos) { ContainerLocation result = new ContainerLocation(dataFileIds[pos], positions[pos]); return result; } // private static long toLong(ContainerLocation containerLocation) {// long result = (long) containerLocation.getDataFileId() << 32;// result |= containerLocation.getPosition() & 0xFFFFFFFFL;// return result;// }// // private static void fromLong(long encoded, ContainerLocation containerLocation) {// containerLocation.getDataFileId() = (int) (encoded >> 32);// containerLocation.getPosition() = (int) encoded;// } public String toString() { StringBuffer result = new StringBuffer(super.toString()); result.append(" nodes ["); // comment for-loop out when using a long[] for (int i = 0; i < dataFileIds.length; i++) { result.append(dataFileIds[i]); if (!isInUse(i)) { result.append("D"); } if (i < dataFileIds.length - 1) { result.append(", "); } else { result.append("]"); } } return result.toString(); } // DEBUG and TEST code following only public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); for (int test = 0; test < 1000; test++) { int SIZE = 100; ContainerLocationLoc containerLocationLoc = new ContainerLocationLoc(SIZE, 0.1F); for(int i = 0; i < SIZE; i++) { ContainerLocation loc = new ContainerLocation((int) (Math.random() * Integer.MAX_VALUE), (int) (Math.random() * Integer.MAX_VALUE)); int pos = containerLocationLoc.putKey(i); containerLocationLoc.putContainerLocation(pos, loc); } ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("/home/leo/delme." + test), 8192)); out.writeObject(containerLocationLoc); out.close(); } System.out.println("that took " + (System.currentTimeMillis() - start) + " msec."); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -