|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/uds-releases/jasper/src/uds/deltaIndex.h#4 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef DELTAINDEX_H
|
|
Packit Service |
310c69 |
#define DELTAINDEX_H 1
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "compiler.h"
|
|
Packit Service |
310c69 |
#include "deltaMemory.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
enum {
|
|
Packit Service |
310c69 |
// the number of extra bytes and bits needed to store a collision entry
|
|
Packit Service |
310c69 |
COLLISION_BYTES = UDS_CHUNK_NAME_SIZE,
|
|
Packit Service |
310c69 |
COLLISION_BITS = COLLISION_BYTES * CHAR_BIT
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef struct deltaIndex {
|
|
Packit Service |
310c69 |
DeltaMemory *deltaZones; // The zones
|
|
Packit Service |
310c69 |
unsigned int numZones; // The number of zones
|
|
Packit Service |
310c69 |
unsigned int numLists; // The number of delta lists
|
|
Packit Service |
310c69 |
unsigned int listsPerZone; // Lists per zone (last zone can be smaller)
|
|
Packit Service |
310c69 |
bool isMutable; // True if this index is mutable
|
|
Packit Service |
310c69 |
byte tag; // Tag belonging to this delta index
|
|
Packit Service |
310c69 |
} DeltaIndex;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* A DeltaIndexPage describes a single page of a chapter index. The deltaIndex
|
|
Packit Service |
310c69 |
* field allows the page to be treated as an immutable DeltaIndex. We use the
|
|
Packit Service |
310c69 |
* deltaMemory field to treat the chapter index page as a single zone index,
|
|
Packit Service |
310c69 |
* and without the need to do an additional memory allocation.
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef struct deltaIndexPage {
|
|
Packit Service |
310c69 |
DeltaIndex deltaIndex;
|
|
Packit Service |
310c69 |
// These values are loaded from the DeltaPageHeader
|
|
Packit Service |
310c69 |
unsigned int lowestListNumber;
|
|
Packit Service |
310c69 |
unsigned int highestListNumber;
|
|
Packit Service |
310c69 |
uint64_t virtualChapterNumber;
|
|
Packit Service |
310c69 |
// This structure describes the single zone of a delta index page.
|
|
Packit Service |
310c69 |
DeltaMemory deltaMemory;
|
|
Packit Service |
310c69 |
} DeltaIndexPage;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Notes on the DeltaIndexEntries:
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* The fields documented as "public" can be read by any code that uses a
|
|
Packit Service |
310c69 |
* DeltaIndex. The fields documented as "private" carry information
|
|
Packit Service |
310c69 |
* between DeltaIndex method calls and should not be used outside the
|
|
Packit Service |
310c69 |
* DeltaIndex module.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* (1) The DeltaIndexEntry is used like an iterator when searching a delta
|
|
Packit Service |
310c69 |
* list.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* (2) And it is also the result of a successful search and can be used to
|
|
Packit Service |
310c69 |
* refer to the element found by the search.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* (3) And it is also the result of an unsuccessful search and can be used
|
|
Packit Service |
310c69 |
* to refer to the insertion point for a new record.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* (4) If atEnd==true, the DeltaListEntry can only be used as the insertion
|
|
Packit Service |
310c69 |
* point for a new record at the end of the list.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* (5) If atEnd==false and isCollision==true, the DeltaListEntry fields
|
|
Packit Service |
310c69 |
* refer to a collision entry in the list, and the DeltaListEntry can
|
|
Packit Service |
310c69 |
* be used a a reference to this entry.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* (6) If atEnd==false and isCollision==false, the DeltaListEntry fields
|
|
Packit Service |
310c69 |
* refer to a non-collision entry in the list. Such DeltaListEntries
|
|
Packit Service |
310c69 |
* can be used as a reference to a found entry, or an insertion point
|
|
Packit Service |
310c69 |
* for a non-collision entry before this entry, or an insertion point
|
|
Packit Service |
310c69 |
* for a collision entry that collides with this entry.
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef struct deltaIndexEntry {
|
|
Packit Service |
310c69 |
// Public fields
|
|
Packit Service |
310c69 |
unsigned int key; // The key for this entry
|
|
Packit Service |
310c69 |
bool atEnd; // We are after the last entry in the list
|
|
Packit Service |
310c69 |
bool isCollision; // This record is a collision
|
|
Packit Service |
310c69 |
// Private fields (but DeltaIndex_t1 cheats and looks at them)
|
|
Packit Service |
310c69 |
bool listOverflow; // This delta list overflowed
|
|
Packit Service |
310c69 |
unsigned short valueBits; // The number of bits used for the value
|
|
Packit Service |
310c69 |
unsigned short entryBits; // The number of bits used for the entire entry
|
|
Packit Service |
310c69 |
DeltaMemory *deltaZone; // The delta index zone
|
|
Packit Service |
310c69 |
DeltaList *deltaList; // The delta list containing the entry,
|
|
Packit Service |
310c69 |
unsigned int listNumber; // The delta list number
|
|
Packit Service |
310c69 |
uint32_t offset; // Bit offset of this entry within the list
|
|
Packit Service |
310c69 |
unsigned int delta; // The delta between this and previous entry
|
|
Packit Service |
310c69 |
DeltaList tempDeltaList; // Temporary delta list for immutable indices
|
|
Packit Service |
310c69 |
} DeltaIndexEntry;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef struct {
|
|
Packit Service |
310c69 |
size_t memoryAllocated; // Number of bytes allocated
|
|
Packit Service |
310c69 |
RelTime rebalanceTime; // The time spent rebalancing
|
|
Packit Service |
310c69 |
int rebalanceCount; // Number of memory rebalances
|
|
Packit Service |
310c69 |
long recordCount; // The number of records in the index
|
|
Packit Service |
310c69 |
long collisionCount; // The number of collision records
|
|
Packit Service |
310c69 |
long discardCount; // The number of records removed
|
|
Packit Service |
310c69 |
long overflowCount; // The number of UDS_OVERFLOWs detected
|
|
Packit Service |
310c69 |
unsigned int numLists; // The number of delta lists
|
|
Packit Service |
310c69 |
} DeltaIndexStats;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Initialize a delta index.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index to initialize
|
|
Packit Service |
310c69 |
* @param numZones The number of zones in the index
|
|
Packit Service |
310c69 |
* @param numLists The number of delta lists in the index
|
|
Packit Service |
310c69 |
* @param meanDelta The mean delta value
|
|
Packit Service |
310c69 |
* @param numPayloadBits The number of bits in the payload or value
|
|
Packit Service |
310c69 |
* @param memorySize The number of bytes in memory for the index
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return error code or UDS_SUCCESS
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int initializeDeltaIndex(DeltaIndex *deltaIndex, unsigned int numZones,
|
|
Packit Service |
310c69 |
unsigned int numLists, unsigned int meanDelta,
|
|
Packit Service |
310c69 |
unsigned int numPayloadBits, size_t memorySize)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Initialize an immutable delta index page.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndexPage The delta index page to initialize
|
|
Packit Service |
310c69 |
* @param expectedNonce If non-zero, the expected nonce.
|
|
Packit Service |
310c69 |
* @param meanDelta The mean delta value
|
|
Packit Service |
310c69 |
* @param numPayloadBits The number of bits in the payload or value
|
|
Packit Service |
310c69 |
* @param memory The memory page
|
|
Packit Service |
310c69 |
* @param memSize The size of the memory page
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return error code or UDS_SUCCESS
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int initializeDeltaIndexPage(DeltaIndexPage *deltaIndexPage,
|
|
Packit Service |
310c69 |
uint64_t expectedNonce,
|
|
Packit Service |
310c69 |
unsigned int meanDelta,
|
|
Packit Service |
310c69 |
unsigned int numPayloadBits,
|
|
Packit Service |
310c69 |
byte *memory,
|
|
Packit Service |
310c69 |
size_t memSize)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Uninitialize a delta index.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index to uninitialize
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void uninitializeDeltaIndex(DeltaIndex *deltaIndex);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Empty the delta index.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index being emptied.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void emptyDeltaIndex(const DeltaIndex *deltaIndex);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Empty a zone of the delta index.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
* @param zoneNumber The zone being emptied
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void emptyDeltaIndexZone(const DeltaIndex *deltaIndex,
|
|
Packit Service |
310c69 |
unsigned int zoneNumber);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Pack delta lists from a mutable delta index into an immutable delta index
|
|
Packit Service |
310c69 |
* page. A range of delta lists (starting with a specified list index) is
|
|
Packit Service |
310c69 |
* copied from the mutable delta index into a memory page used in the immutable
|
|
Packit Service |
310c69 |
* index. The number of lists copied onto the page is returned to the caller.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index being converted
|
|
Packit Service |
310c69 |
* @param headerNonce The header nonce to store
|
|
Packit Service |
310c69 |
* @param headerNativeEndian If true, write native endian header
|
|
Packit Service |
310c69 |
* @param memory The memory page to use
|
|
Packit Service |
310c69 |
* @param memSize The size of the memory page
|
|
Packit Service |
310c69 |
* @param virtualChapterNumber The virtual chapter number
|
|
Packit Service |
310c69 |
* @param firstList The first delta list number to be copied
|
|
Packit Service |
310c69 |
* @param numLists The number of delta lists that were copied
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return error code or UDS_SUCCESS. On UDS_SUCCESS, the numLists
|
|
Packit Service |
310c69 |
* argument contains the number of lists copied.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int packDeltaIndexPage(const DeltaIndex *deltaIndex,
|
|
Packit Service |
310c69 |
uint64_t headerNonce,
|
|
Packit Service |
310c69 |
bool headerNativeEndian,
|
|
Packit Service |
310c69 |
byte *memory,
|
|
Packit Service |
310c69 |
size_t memSize,
|
|
Packit Service |
310c69 |
uint64_t virtualChapterNumber,
|
|
Packit Service |
310c69 |
unsigned int firstList,
|
|
Packit Service |
310c69 |
unsigned int *numLists)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Set the tag value used when saving and/or restoring a delta index.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
* @param tag The tag value
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void setDeltaIndexTag(DeltaIndex *deltaIndex, byte tag);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Start restoring a delta index from an input stream.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index to read into
|
|
Packit Service |
310c69 |
* @param bufferedReaders The buffered readers to read the delta index from
|
|
Packit Service |
310c69 |
* @param numReaders The number of buffered readers
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS on success, or an error code on failure
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int startRestoringDeltaIndex(const DeltaIndex *deltaIndex,
|
|
Packit Service |
310c69 |
BufferedReader **bufferedReaders, int numReaders)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Have all the data been read while restoring a delta index from an
|
|
Packit Service |
310c69 |
* input stream?
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return true if all the data are read
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
bool isRestoringDeltaIndexDone(const DeltaIndex *deltaIndex);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Restore a saved delta list
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
* @param dlsi The DeltaListSaveInfo describing the delta list
|
|
Packit Service |
310c69 |
* @param data The saved delta list bit stream
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return error code or UDS_SUCCESS
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int restoreDeltaListToDeltaIndex(const DeltaIndex *deltaIndex,
|
|
Packit Service |
310c69 |
const DeltaListSaveInfo *dlsi,
|
|
Packit Service |
310c69 |
const byte data[DELTA_LIST_MAX_BYTE_COUNT])
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Abort restoring a delta index from an input stream.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void abortRestoringDeltaIndex(const DeltaIndex *deltaIndex);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Start saving a delta index zone to a buffered output stream.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
* @param zoneNumber The zone number
|
|
Packit Service |
310c69 |
* @param bufferedWriter The index state component being written
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS on success, or an error code on failure
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int startSavingDeltaIndex(const DeltaIndex *deltaIndex,
|
|
Packit Service |
310c69 |
unsigned int zoneNumber,
|
|
Packit Service |
310c69 |
BufferedWriter *bufferedWriter)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Have all the data been written while saving a delta index zone to an
|
|
Packit Service |
310c69 |
* output stream? If the answer is yes, it is still necessary to call
|
|
Packit Service |
310c69 |
* finishSavingDeltaIndex(), which will return quickly.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
* @param zoneNumber The zone number
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return true if all the data are written
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
bool isSavingDeltaIndexDone(const DeltaIndex *deltaIndex,
|
|
Packit Service |
310c69 |
unsigned int zoneNumber);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Finish saving a delta index zone to an output stream. Force the writing
|
|
Packit Service |
310c69 |
* of all of the remaining data. If an error occurred asynchronously
|
|
Packit Service |
310c69 |
* during the save operation, it will be returned here.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
* @param zoneNumber The zone number
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS on success, or an error code on failure
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int finishSavingDeltaIndex(const DeltaIndex *deltaIndex,
|
|
Packit Service |
310c69 |
unsigned int zoneNumber)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Abort saving a delta index zone to an output stream. If an error
|
|
Packit Service |
310c69 |
* occurred asynchronously during the save operation, it will be dropped.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
* @param zoneNumber The zone number
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS on success, or an error code on failure
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int abortSavingDeltaIndex(const DeltaIndex *deltaIndex,
|
|
Packit Service |
310c69 |
unsigned int zoneNumber)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Compute the number of bytes required to save a delta index
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param numLists The number of delta lists in the index
|
|
Packit Service |
310c69 |
* @param memorySize The number of bytes in memory for the index
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return numBytes The number of bytes required to save the master index
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
size_t computeDeltaIndexSaveBytes(unsigned int numLists, size_t memorySize)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Validate the delta index
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS on success, or an error code on failure
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int validateDeltaIndex(const DeltaIndex *deltaIndex)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Prepare to search for an entry in the specified delta list.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This is always the first routine to be called when dealing with delta
|
|
Packit Service |
310c69 |
* index entries. It is always followed by calls to nextDeltaIndexEntry to
|
|
Packit Service |
310c69 |
* iterate through a delta list. The fields of the DeltaIndexEntry argument
|
|
Packit Service |
310c69 |
* will be set up for iteration, but will not contain an entry from the list.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index to search
|
|
Packit Service |
310c69 |
* @param listNumber The delta list number
|
|
Packit Service |
310c69 |
* @param key First delta list key that the caller is interested in
|
|
Packit Service |
310c69 |
* @param readOnly True if this is a read-only operation
|
|
Packit Service |
310c69 |
* @param iterator The index entry being used to search through the list
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS on success, or an error code on failure
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int startDeltaIndexSearch(const DeltaIndex *deltaIndex,
|
|
Packit Service |
310c69 |
unsigned int listNumber, unsigned int key,
|
|
Packit Service |
310c69 |
bool readOnly, DeltaIndexEntry *iterator)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Find the next entry in the specified delta list
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaEntry Info about an entry, which is updated to describe the
|
|
Packit Service |
310c69 |
* following entry
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS on success, or an error code on failure
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int nextDeltaIndexEntry(DeltaIndexEntry *deltaEntry)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Remember the position of a delta index entry, so that we can use it when
|
|
Packit Service |
310c69 |
* starting the next search.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaEntry Info about an entry found during a search. This should
|
|
Packit Service |
310c69 |
* be the first entry that matches the key exactly (i.e.
|
|
Packit Service |
310c69 |
* not a collision entry), or the first entry with a key
|
|
Packit Service |
310c69 |
* greater than the entry sought for.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS on success, or an error code on failure
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int rememberDeltaIndexOffset(const DeltaIndexEntry *deltaEntry)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Find the delta index entry, or the insertion point for a delta index
|
|
Packit Service |
310c69 |
* entry.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index to search
|
|
Packit Service |
310c69 |
* @param listNumber The delta list number
|
|
Packit Service |
310c69 |
* @param key The key field being looked for
|
|
Packit Service |
310c69 |
* @param name The 256 bit full name
|
|
Packit Service |
310c69 |
* @param readOnly True if this is a read-only index search
|
|
Packit Service |
310c69 |
* @param deltaEntry Updated to describe the entry being looked for
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int getDeltaIndexEntry(const DeltaIndex *deltaIndex, unsigned int listNumber,
|
|
Packit Service |
310c69 |
unsigned int key, const byte *name, bool readOnly,
|
|
Packit Service |
310c69 |
DeltaIndexEntry *deltaEntry)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the full name from a collision DeltaIndexEntry
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaEntry The delta index record
|
|
Packit Service |
310c69 |
* @param name The 256 bit full name
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int getDeltaEntryCollision(const DeltaIndexEntry *deltaEntry, byte *name)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the bit offset into delta memory of a delta index entry.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaEntry The delta index entry
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the bit offset into delta memory
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static INLINE uint64_t getDeltaEntryOffset(const DeltaIndexEntry *deltaEntry)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return getDeltaListStart(deltaEntry->deltaList) + deltaEntry->offset;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the number of bits used to encode the entry key (the delta).
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param entry The delta index record
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the number of bits used to encode the key
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static INLINE unsigned int getDeltaEntryKeyBits(const DeltaIndexEntry *entry)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Derive keyBits by subtracting the sizes of the other two fields from the
|
|
Packit Service |
310c69 |
* total. We don't actually use this for encoding/decoding, so it doesn't
|
|
Packit Service |
310c69 |
* need to be super-fast. We save time where it matters by not storing it.
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
return (entry->entryBits - entry->valueBits
|
|
Packit Service |
310c69 |
- (entry->isCollision ? COLLISION_BITS : 0));
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the value field of the DeltaIndexEntry
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaEntry The delta index record
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the value
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static INLINE unsigned int getDeltaEntryValue(const DeltaIndexEntry *deltaEntry)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return getField(deltaEntry->deltaZone->memory,
|
|
Packit Service |
310c69 |
getDeltaEntryOffset(deltaEntry), deltaEntry->valueBits);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Set the value field of the DeltaIndexEntry
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaEntry The delta index record
|
|
Packit Service |
310c69 |
* @param value The new value
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int setDeltaEntryValue(const DeltaIndexEntry *deltaEntry, unsigned int value)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Create a new entry in the delta index
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaEntry The delta index entry that indicates the insertion point
|
|
Packit Service |
310c69 |
* for the new record. For a collision entry, this is the
|
|
Packit Service |
310c69 |
* non-collision entry that the new entry collides with.
|
|
Packit Service |
310c69 |
* For a non-collision entry, this new entry is inserted
|
|
Packit Service |
310c69 |
* before the specified entry.
|
|
Packit Service |
310c69 |
* @param key The key field
|
|
Packit Service |
310c69 |
* @param value The value field
|
|
Packit Service |
310c69 |
* @param name For collision entries, the 256 bit full name;
|
|
Packit Service |
310c69 |
* Otherwise null
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int putDeltaIndexEntry(DeltaIndexEntry *deltaEntry, unsigned int key,
|
|
Packit Service |
310c69 |
unsigned int value, const byte *name)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Remove an existing delta index entry, and advance to the next entry in
|
|
Packit Service |
310c69 |
* the delta list.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaEntry On call the delta index record to remove. After
|
|
Packit Service |
310c69 |
* returning, the following entry in the delta list.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int removeDeltaIndexEntry(DeltaIndexEntry *deltaEntry)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Map a delta list number to a delta zone number
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
* @param listNumber The delta list number
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the zone number containing the delta list
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static INLINE unsigned int getDeltaIndexZone(const DeltaIndex *deltaIndex,
|
|
Packit Service |
310c69 |
unsigned int listNumber)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return listNumber / deltaIndex->listsPerZone;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the first delta list number in a zone
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
* @param zoneNumber The zone number
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the first delta list index in the zone
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
unsigned int getDeltaIndexZoneFirstList(const DeltaIndex *deltaIndex,
|
|
Packit Service |
310c69 |
unsigned int zoneNumber);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the number of delta lists in a zone
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
* @param zoneNumber The zone number
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the number of delta lists in the zone
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
unsigned int getDeltaIndexZoneNumLists(const DeltaIndex *deltaIndex,
|
|
Packit Service |
310c69 |
unsigned int zoneNumber);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the number of bytes used for master index entries in a zone
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
* @param zoneNumber The zone number
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The number of bits in use
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
uint64_t getDeltaIndexZoneDlistBitsUsed(const DeltaIndex *deltaIndex,
|
|
Packit Service |
310c69 |
unsigned int zoneNumber)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the number of bytes used for master index entries.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The number of bits in use
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
uint64_t getDeltaIndexDlistBitsUsed(const DeltaIndex *deltaIndex)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the number of bytes allocated for master index entries.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The number of bits allocated
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
uint64_t getDeltaIndexDlistBitsAllocated(const DeltaIndex *deltaIndex)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the delta index statistics.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaIndex The delta index
|
|
Packit Service |
310c69 |
* @param stats The statistics
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void getDeltaIndexStats(const DeltaIndex *deltaIndex, DeltaIndexStats *stats);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the number of pages needed for an immutable delta index.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param numEntries The number of entries in the index
|
|
Packit Service |
310c69 |
* @param numLists The number of delta lists
|
|
Packit Service |
310c69 |
* @param meanDelta The mean delta value
|
|
Packit Service |
310c69 |
* @param numPayloadBits The number of bits in the payload or value
|
|
Packit Service |
310c69 |
* @param bytesPerPage The number of bytes in a page
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the number of pages needed for the index
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
unsigned int getDeltaIndexPageCount(unsigned int numEntries,
|
|
Packit Service |
310c69 |
unsigned int numLists,
|
|
Packit Service |
310c69 |
unsigned int meanDelta,
|
|
Packit Service |
310c69 |
unsigned int numPayloadBits,
|
|
Packit Service |
310c69 |
size_t bytesPerPage);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Log a delta index entry, and any error conditions related to the entry.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param deltaEntry The delta index entry.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void logDeltaIndexEntry(DeltaIndexEntry *deltaEntry);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif /* DELTAINDEX_H */
|