SortValuesSet.java revision a395dd575518d9e5280fc5d5d5ef47c61b174647
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
*/
/**
* This class representsa partial sorted set of sorted entries in a VLV
* index.
*/
public class SortValuesSet
{
private static final int ENCODED_VALUE_SIZE = 16;
private static final int ENCODED_VALUE_LENGTH_SIZE =
private static final int ENCODED_ATTRIBUTE_VALUE_SIZE =
private long[] entryIDs;
private byte[] valuesBytes;
private byte[] keyBytes;
/**
* Construct an empty sort values set with the given information.
*
* @param vlvIndex The VLV index using this set.
* @param id2entry The ID2Entry database.
*/
{
this.keyBytes = new byte[0];
this.valuesBytes = null;
}
/**
* Construct a sort values set from the database.
*
* @param keyBytes The database key used to locate this set.
* @param dataBytes The bytes to decode and construct this set.
* @param vlvIndex The VLV index using this set.
* @param id2entry The ID2Entry database.
*/
{
{
entryIDs = new long[0];
return;
}
}
{
this.valuesBytes = valuesBytes;
}
/**
* Add the given entryID and values from this VLV idnex.
*
* @param entryID The entry ID to add.
* @param values The values to add.
* @return True if the information was successfully added or False
* otherwise.
* @throws DirectoryException If a Directory Server error occurs.
* @throws DatabaseException If an error occurs in the JE database.
* @throws JebException If an error occurs in the JE database.
*/
{
{
return false;
}
{
entryIDs = new long[1];
return true;
}
values) < 0)
{
return true;
}
else
{
if(pos >= 0)
{
{
// The entry ID is alreadly present.
return false;
}
}
else
{
// For a negative return value r, the vlvIndex -(r+1) gives the array
// ndex at which the specified value can be inserted to maintain
// the sorted order of the array.
}
}
return true;
}
/**
* Remove the given entryID and values from this VLV idnex.
*
* @param entryID The entry ID to remove.
* @param values The values to remove.
* @return True if the information was successfully removed or False
* otherwise.
* @throws DirectoryException If a Directory Server error occurs.
* @throws DatabaseException If an error occurs in the JE database.
* @throws JebException If an error occurs in the JE database.
*/
{
{
return false;
}
if(pos < 0)
{
// Not found.
return false;
}
else
{
// Found it.
return true;
}
}
/**
* Split portions of this set into another set. The values of the new set is
* from the front of this set.
*
* @param splitLength The size of the new set.
* @return The split set.
*/
{
long[] splitEntryIDs = new long[splitLength];
byte[] splitValuesBytes = new byte[splitLength *
return splitValuesSet;
}
/**
* Encode this set to its database format.
*
* @return The encoded bytes representing this set.
*/
public byte[] toDatabase()
{
for (int j = 3; j >= 0; j--)
{
concatBytes[j] = (byte) (v & 0xFF);
v >>>= 8;
}
return concatBytes;
}
/**
* Get the size of the provided encoded set.
*
* @param bytes The encoded bytes of a SortValuesSet to decode the size from.
* @param offset The byte offset to start decoding.
* @return The size of the provided encoded set.
*/
{
int v = 0;
{
v <<= 8;
v |= (bytes[i] & 0xFF);
}
return v;
}
/**
* Get the IDs from the provided encoded set.
*
* @param bytes The encoded bytes of a SortValuesSet to decode the IDs from.
* @param offset The byte offset to start decoding.
* @return The decoded IDs in the provided encoded set.
*/
{
}
/**
* Searches this set for the specified values and entry ID using the binary
* search algorithm.
*
* @param entryID The entry ID to match or -1 if not matching on entry ID.
* @param values The values to match.
* @return Index of the entry matching the values and optionally the entry ID
* if it is found or a negative index if its not found.
* @throws DirectoryException If a Directory Server error occurs.
* @throws DatabaseException If an error occurs in the JE database.
* @throws JebException If an error occurs in the JE database.
*/
{
{
return -1;
}
int i = 0;
{
int k = i + j >> 1;
if(l < 0)
i = k + 1;
else
if(l > 0)
j = k - 1;
else
return k;
}
return -(i + 1);
}
/**
* Retrieve the size of this set.
*
* @return The size of this set.
*/
public int size()
{
{
return 0;
}
}
/**
* Retrieve the entry IDs in this set.
*
* @return The entry IDs in this set.
*/
public long[] getEntryIDs()
{
return entryIDs;
}
private static int encodedLengthSize(int length)
{
{
return 1;
}
{
return 2;
}
{
return 3;
}
else
{
return 4;
}
}
throws DirectoryException
{
{
int length;
byte[] lengthBytes = new byte[ENCODED_VALUE_LENGTH_SIZE];
{
length = 0;
}
else
{
{
}
else
{
}
}
{
length >>>= 8;
}
i * (ENCODED_ATTRIBUTE_VALUE_SIZE),
}
return valuesBytes;
}
/**
* Returns the key to use for this set of sort values in the database.
*
* @return The key as an array of bytes that should be used for this set in
* the database or NULL if this set is empty.
* @throws DirectoryException If a Directory Server error occurs.
* @throws DatabaseException If an error occurs in the JE database.
* @throws JebException If an error occurs in the JE database.
*/
public byte[] getKeyBytes()
{
{
return null;
}
{
return keyBytes;
}
AttributeValue[] values =
new AttributeValue[numValues];
i++, j++)
{
new ASN1OctetString(getValue(i)));
}
return keyBytes;
}
/**
* Returns the key to use for this set of sort values in the database.
*
* @return The key as a sort values object that should be used for this set in
* the database or NULL if this set is empty or unbounded.
* @throws DirectoryException If a Directory Server error occurs.
* @throws DatabaseException If an error occurs in the JE database.
* @throws JebException If an error occurs in the JE database.
*/
public SortValues getKeySortValues()
{
{
return null;
}
{
return null;
}
AttributeValue[] values =
new AttributeValue[numValues];
i++, j++)
{
new ASN1OctetString(getValue(i)));
}
}
/**
* Returns the sort values at the index in this set.
*
* @param index The index of the sort values to get.
* @return The sort values object at the specified index.
* @throws DirectoryException If a Directory Server error occurs.
* @throws DatabaseException If an error occurs in the JE database.
* @throws JebException If an error occurs in the JE database.
**/
{
{
return null;
}
AttributeValue[] values =
new AttributeValue[numValues];
i++, j++)
{
{
new ASN1OctetString(value));
}
}
}
/**
* Retrieve an attribute value from this values set. The index is the
* absolute index. (ie. for a sort on 3 attributes per entry, an vlvIndex of 6
* will be the 1st attribute value of the 3rd entry).
*
* @param index The vlvIndex of the attribute value to retrieve.
* @return The byte array representation of the attribute value.
* @throws DirectoryException If a Directory Server error occurs.
* @throws DatabaseException If an error occurs in the JE database.
* @throws JebException If an error occurs in the JE database.
*/
{
// If values bytes is null, we have to get the value by getting the
// entry by ID and getting the value.
if(valuesBytes != null)
{
int length = 0;
byte[] valueBytes;
{
length <<= 8;
}
if(length == 0)
{
return null;
}
// If the value has exceeded the max value size, we have to get the
// value by getting the entry by ID.
{
valueBytes = new byte[length];
return valueBytes;
}
}
{
return new byte[0];
}
// Get the entry from id2entry and assign the values from the entry.
// Once the values are assigned from the retrieved entry, it will
// not be retrieve again from future compares.
{
}
}
}