package dev ; import org.openjena.atlas.lib.Bytes ; import org.openjena.atlas.lib.FileOps ; import org.openjena.atlas.logging.Log ; import com.hp.hpl.jena.tdb.base.file.FileSet ; import com.hp.hpl.jena.tdb.base.record.RecordFactory ; import com.hp.hpl.jena.tdb.index.ext.ExtHash ; import com.hp.hpl.jena.tdb.index.factories.IndexFactoryExtHash ; /* * (c) Copyright 2010 Talis Systems Ltd. * All rights reserved. * [See end of file] */ public class ExtHashTest { static { Log.setLog4j() ; } private static final int MASK = 0xff; IndexFactoryExtHash proxIndexFactory; RecordFactory proxRecordFactory; ExtHash proxIndex; FileSet fileset; public static void main(String args[]) { (new ExtHashTest()).insert(); } public void insert() { byte[] key, k1, k2; this.fileset = new FileSet("indexes", "proximity"); FileOps.clearDirectory("indexes") ; //ExtHash.Logging = true ; //ExtHash.Debugging = true ; ExtHash.Checking = true ; this.proxIndexFactory = new IndexFactoryExtHash(); this.proxRecordFactory = new RecordFactory(16, 4); this.proxIndex = (ExtHash) this.proxIndexFactory.createIndex(this.fileset, this.proxRecordFactory); float n1 = 0.4567f; int counter = 1; for (long i = 0; i < 510; i++) { k1 = Bytes.packLong(i); for (long j = 0; j < 510; j++) { //System.out.println("Inserting record " + counter + "..."); k2 = Bytes.packLong(j); key = new byte[16]; System.arraycopy(k1, 0, key, 0, 8); System.arraycopy(k2, 0, key, 8, 8); this.proxIndex.add(this.proxRecordFactory.create(key, floatToByteArray(n1))); counter++; } } this.proxIndex.close(); } public static byte[] floatToByteArray(float f) { int i = Float.floatToRawIntBits(f); return intToByteArray(i); } public static byte[] intToByteArray(int param) { byte[] result = new byte[4]; for (int i = 0; i < 4; i++) { int offset = (result.length - 1 - i) * 8; result[i] = (byte) ((param >>> offset) & MASK); } return result; } } /* * (c) Copyright 2010 Talis Systems Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */