Java Code Examples for com.sleepycat.bind.tuple.TupleBinding#entryToInput()

The following examples show how to use com.sleepycat.bind.tuple.TupleBinding#entryToInput() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSearchStructure.java    From multimedia-indexing with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a {@link LatLng} object with the geolocation of the vector with the given internal id or null
 * if the internal id does not exist. Accesses the BDB store!
 * 
 * @param iid
 *            The internal id of the vector
 * @return The geolocation mapped to the given internal id or null if the internal id does not exist
 */
public LatLng getGeolocation(int iid) {
	if (iid < 0 || iid > loadCounter) {
		System.out.println("Internal id " + iid + " is out of range!");
		return null;
	}
	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(iid, key);
	DatabaseEntry data = new DatabaseEntry();
	if ((iidToGeolocationDB.get(null, key, data, null) == OperationStatus.SUCCESS)) {
		TupleInput input = TupleBinding.entryToInput(data);
		double latitude = input.readDouble();
		double longitude = input.readDouble();
		LatLng geolocation = new LatLng(latitude, longitude);
		return geolocation;
	} else {
		System.out.println("Internal id " + iid + " is in range but gelocation was not found.");
		return null;
	}
}
 
Example 2
Source File: IVFPQ.java    From multimedia-indexing with Apache License 2.0 6 votes vote down vote up
/**
 * This is a utility method that can be used to dump the contents of the iidToIvfpqDB to a txt file.<br>
 * Currently, only the list id of each item is dumped.
 * 
 * @param dumpFilename
 *            Full path to the file where the dump will be written.
 * @throws Exception
 */
public void dumpIidToIvfpqDB(String dumpFilename) throws Exception {
	DatabaseEntry foundKey = new DatabaseEntry();
	DatabaseEntry foundData = new DatabaseEntry();

	ForwardCursor cursor = iidToIvfpqDB.openCursor(null, null);
	BufferedWriter out = new BufferedWriter(new FileWriter(new File(dumpFilename)));
	while (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
		int iid = IntegerBinding.entryToInt(foundKey);
		TupleInput input = TupleBinding.entryToInput(foundData);
		int listId = input.readInt();
		out.write(iid + " " + listId + "\n");
	}
	cursor.close();
	out.close();
}
 
Example 3
Source File: IVFPQ.java    From multimedia-indexing with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the pq code of the image with the given id.
 * 
 * @param id
 * @return
 * @throws Exception
 */
public byte[] getPQCodeByte(String id) throws Exception {
	int iid = getInternalId(id);
	if (iid == -1) {
		throw new Exception("Id does not exist!");
	}
	if (numProductCentroids > 256) {
		throw new Exception("Call the short variant of the method!");
	}

	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(iid, key);
	DatabaseEntry data = new DatabaseEntry();
	if ((iidToIvfpqDB.get(null, key, data, null) == OperationStatus.SUCCESS)) {
		TupleInput input = TupleBinding.entryToInput(data);
		input.readInt(); // skip the list id
		byte[] code = new byte[numSubVectors];
		for (int i = 0; i < numSubVectors; i++) {
			code[i] = input.readByte();
		}
		return code;
	} else {
		throw new Exception("Id does not exist!");
	}
}
 
Example 4
Source File: IVFPQ.java    From multimedia-indexing with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the pq code of the image with the given id.
 * 
 * @param id
 * @return
 * @throws Exception
 */
public short[] getPQCodeShort(String id) throws Exception {
	int iid = getInternalId(id);
	if (iid == -1) {
		throw new Exception("Id does not exist!");
	}
	if (numProductCentroids <= 256) {
		throw new Exception("Call the short variant of the method!");
	}

	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(iid, key);
	DatabaseEntry data = new DatabaseEntry();
	if ((iidToIvfpqDB.get(null, key, data, null) == OperationStatus.SUCCESS)) {
		TupleInput input = TupleBinding.entryToInput(data);
		input.readInt(); // skip the list id
		short[] code = new short[numSubVectors];
		for (int i = 0; i < numSubVectors; i++) {
			code[i] = input.readShort();
		}
		return code;
	} else {
		throw new Exception("Id does not exist!");
	}
}
 
Example 5
Source File: IVFPQ.java    From multimedia-indexing with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the inverted list of the image with the given id.
 * 
 * @param id
 * @return
 * @throws Exception
 */
public int getInvertedListId(String id) throws Exception {
	int iid = getInternalId(id);
	if (iid == -1) {
		throw new Exception("Id does not exist!");
	}

	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(iid, key);
	DatabaseEntry data = new DatabaseEntry();
	if ((iidToIvfpqDB.get(null, key, data, null) == OperationStatus.SUCCESS)) {
		TupleInput input = TupleBinding.entryToInput(data);
		int listId = input.readInt();
		return listId;
	} else {
		throw new Exception("Id does not exist!");
	}
}
 
Example 6
Source File: PreparedTransactionBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public static PreparedTransaction entryToObject(final CachingUUIDFactory uuidFactory, final DatabaseEntry value)
{
    TupleInput input = TupleBinding.entryToInput(value);
    Transaction.EnqueueRecord[] enqueues = readEnqueueRecords(uuidFactory, input);
    Transaction.DequeueRecord[] dequeues = readDequeueRecords(uuidFactory, input);
    return new PreparedTransaction(enqueues, dequeues);
}
 
Example 7
Source File: Linear.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the persistent index in memory.
 * 
 * @throws Exception
 */
private void loadIndexInMemory() throws Exception {
	long start = System.currentTimeMillis();
	System.out.println("Loading persistent index in memory.");

	DatabaseEntry foundKey = new DatabaseEntry();
	DatabaseEntry foundData = new DatabaseEntry();

	ForwardCursor cursor = null;
	if (useDiskOrderedCursor) { // disk ordered cursor
		DiskOrderedCursorConfig docc = new DiskOrderedCursorConfig();
		cursor = iidToVectorDB.openCursor(docc);
	} else {
		cursor = iidToVectorDB.openCursor(null, null);
	}

	int counter = 0;
	while (cursor.getNext(foundKey, foundData, null) == OperationStatus.SUCCESS
			&& counter < maxNumVectors) {
		TupleInput input = TupleBinding.entryToInput(foundData);
		double[] vector = new double[vectorLength];
		for (int i = 0; i < vectorLength; i++) {
			vector[i] = input.readDouble();
		}
		// update ram based index
		vectorsList.add(vector);
		counter++;
		if (counter % 1000 == 0) {
			System.out.println(counter + " vectors loaded in memory!");
		}
	}
	cursor.close();
	long end = System.currentTimeMillis();
	System.out.println(counter + " vectors loaded in " + (end - start) + " ms!");
}
 
Example 8
Source File: Linear.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the vector which was assigned the given internal id or null if the internal id does not exist.
 * The vector is taken either from the ram-based (if loadIndexInMemory is true) or from the disk-based
 * index.
 * 
 * @param iid
 *            The internal id of the vector
 * @return The vector with the given internal id or null if the internal id does not exist
 */
public double[] getVector(int iid) {
	if (iid < 0 || iid > loadCounter) {
		System.out.println("Internal id " + iid + " is out of range!");
		return null;
	}
	double[] vector = new double[vectorLength];
	if (loadIndexInMemory) {
		for (int i = 0; i < vectorLength; i++) {
			vector[i] = vectorsList.getQuick(iid * vectorLength + i);
		}
	} else {
		// get the vector from the BDB structure
		DatabaseEntry key = new DatabaseEntry();
		IntegerBinding.intToEntry(iid, key);
		DatabaseEntry foundData = new DatabaseEntry();
		if (iidToVectorDB.get(null, key, foundData, null) == OperationStatus.SUCCESS) {
			TupleInput input = TupleBinding.entryToInput(foundData);
			for (int i = 0; i < vectorLength; i++) {
				vector[i] = input.readDouble();
			}
		} else {
			System.out.println("Internal id " + iid + " is in range but vector was not found..");
			System.out.println("Index is probably corrupted");
			System.exit(0);
			return null;
		}
	}
	return vector;
}