5195N/A * The contents of this file are subject to the terms of the 5195N/A * Common Development and Distribution License, Version 1.0 only 5195N/A * (the "License"). You may not use this file except in compliance 5195N/A * You can obtain a copy of the license at 5195N/A * See the License for the specific language governing permissions 5195N/A * and limitations under the License. 5195N/A * When distributing Covered Code, include this CDDL HEADER in each 5195N/A * file and include the License file at 5195N/A * add the following below this CDDL HEADER, with the fields enclosed 5195N/A * by brackets "[]" replaced with your own identifying information: 5195N/A * Portions Copyright [yyyy] [name of copyright owner] 5195N/A * Copyright 2009-2010 Sun Microsystems, Inc. 6353N/A * Portions Copyright 2013 ForgeRock AS. 5195N/A * This class represents a index buffer used to store the keys and entry IDs 5195N/A * processed from the LDIF file during phase one of an import, or rebuild index 5195N/A * process. Each key and ID is stored in a record in the buffer. 5195N/A * The records in the buffer are eventually sorted, based on the key, when the 5195N/A * maximum size of the buffer is reached and no more records will fit into the 5195N/A * buffer. The buffer is the scheduled to be flushed to an indexes scratch file 5195N/A * and then re-cycled by the import, or rebuild-index process. 5195N/A * The records are packed as much as possible, to optimize the buffer space. 5195N/A * This class is not thread safe. 5195N/A * Enumeration used when sorting a buffer. 5195N/A //Buffer records are either insert records or delete records. 5195N/A //Byte array holding the actual buffer data. 5195N/A //id is used to break a tie (keys equal) when the buffers are being merged 5195N/A //for writing to the index scratch file. 5195N/A //Temporary buffer used to store integer values. 5195N/A keyOffset - offSet where next key is written 5195N/A recordOffset- offSet where next value record is written 5195N/A bytesLeft - amount of bytes left in the buffer 5195N/A //keys - number of keys in the buffer 5195N/A //position - used to iterate over the buffer when writing to a scratch file. 5195N/A //The comparator to use sort the keys. 5195N/A //This is used to make sure that an instance of this class is put on the 5195N/A //correct scratch file writer work queue for processing. 5195N/A //Initial capacity of re-usable buffer used in key compares. 5195N/A //This buffer is reused during key compares. It's main purpose is to keep 5195N/A //memory footprint as small as possible. 5195N/A //Set to {@code true} if the buffer should not be recycled. Used when the 5195N/A * Create an instance of a IndexBuffer using the specified size. 5195N/A * @param size The size of the underlying byte array. 5195N/A * Reset an IndexBuffer so it can be re-cycled. 5195N/A * Set the ID of a buffer to the specified value. 5195N/A * @param id The value to set the ID to. 5195N/A * Return the ID of a buffer. 5195N/A * @return The value of a buffer's ID. 5195N/A * Determines if a buffer is a poison buffer. A poison buffer is used to 5195N/A * A poison buffer has a 0 size. 5195N/A * @return {@code true} if a buffer is a poison buffer, or {@code false} 5195N/A * Determines of a buffer should be re-cycled. 5195N/A * @return {@code true} if buffer should be recycled, or {@code false} if it 5195N/A * Set the discard flag to {@code true}. 5195N/A * Returns {@code true} if there is enough space available to write the 5195N/A * specified byte array in the buffer. It returns {@code false} otherwise. 5195N/A * @param kBytes The byte array to check space against. 5195N/A * @param id The id value to check space against. 5195N/A * @return {@code true} if there is space to write the byte array in a 5195N/A * buffer, or {@code false} otherwise. 5195N/A * Set the comparator to be used in the buffer processing to the specified 5195N/A * @param comparator The comparator to set the buffer's comparator to. 5195N/A * Return a buffer's current position value. 5195N/A * @return The buffer's current position value. 5195N/A * Set a buffer's position value to the specified position. 5195N/A * @param position The value to set the position to. 5195N/A * Add the specified key byte array and EntryID to the buffer. 5195N/A * @param keyBytes The key byte array. 5195N/A * @param entryID The EntryID. 5195N/A * @param indexID The index ID the record belongs. 5195N/A * @param insert <CODE>True</CODE> if key is an insert, false otherwise. 6353N/A * Computes the full size of the record. 6353N/A * @param keyLen The length of the key of index 6353N/A * @return The size that such record would take in the IndexOutputBuffer 5195N/A * Write record at specified index to the specified output stream. Used when 5195N/A * when writing the index scratch files. 5195N/A * @param stream The stream to write the record at the index to. 5195N/A * @param index The index of the record to write. 5195N/A * Return {@code true} if the record specified by the index is an insert 5195N/A * record, or {@code false} if it a delete record. 5195N/A * @param index The index of the record. 5195N/A * @return {@code true} if the record is an insert record, or {@code false} 5195N/A * if it is a delete record. 5195N/A * Return the size of the key part of the record. 5195N/A * @return The size of the key part of the record. 5195N/A * Return the key value part of a record indicated by the current buffer 5195N/A * @return byte array containing the key value. 5195N/A //Used to minimized memory usage when comparing keys. 5195N/A //Re-allocate if the key is bigger than the capacity. 5195N/A * Return the key value part of a record specified by the index. 5195N/A * @param x index to return. 5195N/A * @return byte array containing the key value. 5195N/A * Return index id associated with the current position's record. 5195N/A * Compare the byte array at the current position with the specified one and 5195N/A * using the specified index id. It will return {@code true} if the byte 6353N/A * array at the current position is equal to the specified byte array as 5195N/A * determined by the comparator and the index ID is is equal. It will 5195N/A * return {@code false} otherwise. 5195N/A * @param b The byte array to compare. 5195N/A * @param bIndexID The index key. 5195N/A * @return <CODE>True</CODE> if the byte arrays are equal. 5195N/A * Compare current IndexBuffer to the specified index buffer using both the 5195N/A * comparator and index ID of both buffers. 5195N/A * The key at the value of position in both buffers are used in the compare. 5195N/A * @param b The IndexBuffer to compare to. 5195N/A * @return 0 if the buffers are equal, -1 if the current buffer is less 5195N/A * than the specified buffer, or 1 if it is greater. 5195N/A //This is tested in a tree set remove when a buffer is removed from 5195N/A * Write a record to specified output stream using the record pointed to by 5195N/A * the current position and the specified byte stream of ids. 5195N/A * @param dataStream The data output stream to write to. 5195N/A * @throws IOException If an I/O error occurs writing the record. 5195N/A * Compare the byte array at the current position with the byte array at the 5195N/A * @param i The index pointing to the byte array to compare. 5195N/A * @return {@code true} if the byte arrays are equal, or {@code false} 5195N/A * Return the current number of keys. 5195N/A * @return The number of keys currently in an index buffer. 5195N/A * Return {@code true} if the buffer has more data to process, or 5195N/A * {@code false} otherwise. Used when iterating over the buffer writing the 5195N/A * @return {@code true} if a buffer has more data to process, or 5195N/A * Advance the position pointer to the next record in the buffer. Used when 5195N/A * iterating over the buffer examining keys. 5195N/A for (
int i =
3; i >=
0; i--) {
5195N/A // Swap partition elements back to middle 5195N/A // Recursively sort non-partition-elements 5195N/A for (
int i=
0; i<n; i++, a++, b++)
5195N/A * Interface that defines two methods used to compare keys used in this 5195N/A * class. The Comparator interface cannot be used in this class, so this 5195N/A * special one is used that knows about the special properties of this class. 5195N/A * @param <T> object to use in the compare 5195N/A * Compare two offsets in an object, usually a byte array. 5195N/A * @param offset The first offset. 5195N/A * @param length The first length. 5195N/A * @param indexID The first index id. 5195N/A * @param otherOffset The second offset. 5195N/A * @param otherLength The second length. 5195N/A * @param otherIndexID The second index id. 5195N/A * @return a negative integer, zero, or a positive integer as the first 5195N/A * offset value is less than, equal to, or greater than the second. 5195N/A * Compare an offset in an object with the specified object. 5195N/A * @param o The first object. 5195N/A * @param offset The first offset. 5195N/A * @param length The first length. 5195N/A * @param indexID The first index id. 5195N/A * @param other The second object. 5195N/A * @param otherLength The length of the second object. 5195N/A * @param otherIndexID The second index id. 5195N/A * @return a negative integer, zero, or a positive integer as the first 5195N/A * offset value is less than, equal to, or greater than the second 5195N/A * Compare an offset in an object with the specified object. 5195N/A * @param o The first object. 5195N/A * @param offset The first offset. 5195N/A * @param length The first length. 5195N/A * @param other The second object. 5195N/A * @param otherLen The length of the second object. 5195N/A * @return a negative integer, zero, or a positive integer as the first 5195N/A * offset value is less than, equal to, or greater than the second 5195N/A * Implementation of ComparatorBuffer interface. Used to compare keys when 5195N/A * Compare two offsets in an byte array using the index compare 6353N/A * algorithm. The specified index ID is used in the comparison if the 5195N/A * @param offset The first offset. 5195N/A * @param length The first length. 5195N/A * @param indexID The first index id. 5195N/A * @param otherOffset The second offset. 5195N/A * @param otherLength The second length. 5195N/A * @param otherIndexID The second index id. 5195N/A * @return a negative integer, zero, or a positive integer as the first 5195N/A * offset value is less than, equal to, or greater than the second. 5195N/A //The arrays are equal, make sure they are in the same index since 5195N/A //multiple suffixes might have the same key. 5195N/A * Compare an offset in an byte array with the specified byte array, 5195N/A * using the DN compare algorithm. The specified index ID is used in the 6353N/A * comparison if the byte arrays are equal. 5195N/A * @param offset The first offset. 5195N/A * @param length The first length. 5195N/A * @param indexID The first index id. 5195N/A * @param other The second byte array to compare to. 5195N/A * @param otherLength The second byte array's length. 5195N/A * @param otherIndexID The second index id. 5195N/A * @return a negative integer, zero, or a positive integer as the first 5195N/A * offset value is less than, equal to, or greater than the second 5195N/A //The arrays are equal, make sure they are in the same index since 5195N/A //multiple suffixes might have the same key. 5195N/A * Compare an offset in an byte array with the specified byte array, 5195N/A * using the DN compare algorithm. 5195N/A * @param offset The first offset. 5195N/A * @param length The first length. 5195N/A * @param other The second byte array to compare to. 5195N/A * @param otherLength The second byte array's length. 5195N/A * @return a negative integer, zero, or a positive integer as the first 5195N/A * offset value is less than, equal to, or greater than the second 5195N/A * Set the index key associated with an index buffer. 5195N/A * @param indexKey The index key. 5195N/A * Return the index key of an index buffer. 5195N/A * @return The index buffer's index key.