table.h revision 00314ca59bb0358d05053ee753174724d82adff4
308N/A * Copyright (C) 2006-2007 innotek GmbH 308N/A * This file is part of VirtualBox Open Source Edition (OSE), as 308N/A * you can redistribute it and/or modify it under the terms of the GNU 308N/A * General Public License as published by the Free Software Foundation, 308N/A * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE 308N/A * distribution. VirtualBox OSE is distributed in the hope that it will 308N/A * be useful, but WITHOUT ANY WARRANTY of any kind. 308N/A/** @defgroup grp_rt_tab RTTab - Generic Tree and Table Interface. 815N/A/** Pointer to an allocator. */ 618N/A * @returns Pointer to the allocated memory. 1258N/A * @returns NULL on failure. (don't throw!) 308N/A * @param pAllocator The allocator structure. 308N/A * @param cb The number of bytes to allocate. (Never 0.) 308N/A/** Pointer to a FNRTTABALLOC() function. */ 308N/A * @param pAllocator The allocator structure. 308N/A * @param pv The memory to free. (can be NULL) 308N/A/** Pointer to a FNRTTABFREE() function. */ 308N/A * The allocator structure. * (Hint: use this as like 'base class' for your custom allocators.) /** The allocation function. */ /** The free function. */ * Gets the default allocator. * @returns Pointer to the default allocator. * Compares two table items. * @returns <0 if pvItem1 is less than pvItem2 (pvItem2 is then greater than pvItem1). * @returns >0 if pvItem1 is less than pvItem2 (pvItem1 is then greater than pvItem2). * @param pvItem1 The first item. * @param pvItem2 The second item. * @param pvUser The user argument. /** Pointer to a FNRTTABCOMP() function. */ * Duplicates a table item. * This is used when duplicating or copying a table. * @returns Pointer to the copy. * @returns NULL on failure. * @param pvItem The item to copy. * @param pvUser The user argument. /** Pointer to a FNRTTABDUPLICATE() function. */ * Callback function for doing something with an item. * What exactly we're doing is specific to the context of the call. * @param pvItem The item. * @param pvUser The user argument. /** Pointer to a FNRTTABCALLBACK() function. */ /** Pointer to const table operations. */ /** Pointer to a table. */ /** Pointer to a const table. */ /** Pointer to a traverser. */ /** Pointer to a const traverser. */ /** Pointer to a traverser core. */ /** Pointer to a const traverser core. */ * @returns Pointer to the new table. * @returns NULL if we're out of memory or some other resource. * @param pOps The table operations. * @param fCreateFlags The table type specific creation flags. * @param pAllocator Custom allocator. Pass NULL for the default allocator. * @param pfnComp The comparision function. * Duplicates a table to a table of the same type. * @returns Pointer to the new table. * @returns NULL if we're out of memory or some other resource. * @param pTab The table to duplicate. * @param pfnDuplicate Pointer to the item duplication function. If NULL the new table will * be referencing the same data as the old one. * @param pfnNewCB Callback which is called for all the items in the new table. Optional. * @param pAllocator Custom allocator. Pass NULL to use the same allocator as pTab. * @param pTab The table to destroy. * Inserts an item into the table, if a matching item is encountered * the pointer to the pointer to it will be returned. * @returns Pointer to the item pointer in the table. * This can be used to replace existing items (don't break anything, dude). * @returns NULL if we failed to allocate memory for the new node. * @param pvItem The item which will be inserted if an matching item was not found in the table. * Inserts an item into the table, fail if a matching item exists. * @returns NULL on success and allocation failure. * @returns Pointer to the matching item. * @param pvItem The item which is to be inserted. * Inserts an item into the table, if a matching item is encountered * it will be replaced and returned. * @returns NULL if inserted and allocation failure. * @returns Pointer to the replaced item. * @param pvItem The item which is to be inserted. * Removes an item from the table if found. * @returns Pointer to the removed item. * @returns NULL if no item matched pvItem. * @param pvItem The item which is to be inserted. * Finds an item in the table. * @returns Pointer to the item it found. * @returns NULL if no item matched pvItem. * @param pvItem The item which is to be inserted. * Initializes a traverser to the NULL item. * The NULL item is an imaginary table item before the first and after * the last items in the table. * @returns Pointer to the traverser positioned at the NULL item. * @returns NULL on failure to allocate the traverser. * @param pTravNew Pointer to a preallocated structure. Optional. * Initializes a traverser to the first item in the table. * If the table is empty, the traverser will be positioned at the NULL item * like with RTTabTravInit(). * @returns Pointer to the traverser positioned at the first item or NULL item. * @returns NULL on failure to allocate the traverser. * @param pTravNew Pointer to a preallocated structure. Optional. * Initializes a traverser to the last item in the table. * If the table is empty, the traverser will be positioned at the NULL item * like with RTTabTravInit(). * @returns Pointer to the traverser positioned at the last item or NULL item. * @returns NULL on failure to allocate the traverser. * @param pTravNew Pointer to a preallocated structure. Optional. * Initializes a traverser to an item matching the given one. * If the item isn't found, the traverser will be positioned at the NULL item * like with RTTabTravInit(). * @returns Pointer to the traverser positioned at the matching item or NULL item. * @returns NULL on failure to allocate the traverser. * @param pTravNew Pointer to a preallocated structure. Optional. * @param pvItem The item to find the match to. * Initializes a traverser to the inserted item. * If there already exists an item in the tree matching pvItem, the traverser * is positioned at that item like with RTTabTravFind(). * If the insert operation failes because of an out of memory condition, the * traverser will be positioned at the NULL item like with RTTabTravInit(). * @returns Pointer to the traverser positioned at the inserted, existing or NULL item. * @returns NULL on failure to allocate the traverser. * @param pTravNew Pointer to a preallocated structure. Optional. * @param pvItem The item to be inserted. * Duplicates a traverser. * @returns The pointer to the duplicate. * @returns NULL on allocation failure. * @param pTrav The traverser to duplicate. * @param pTravNew Pointer to a preallocated structure. Optional. * This can safely be called even if the traverser structure * wasn't dynamically allocated or the constructor failed. * @param pTrav The traverser which is to be free. * @returns The current item. (NULL indicates the imaginary NULL item.) * @param pTrav The traverser. * Advances to the next item. * @returns The new current item. (NULL indicates the imaginary NULL item.) * @param pTrav The traverser. * Advances to the previous item. * @returns The new current item. (NULL indicates the imaginary NULL item.) * @param pTrav The traverser. * Replaces the current item. * This has the same restrictions as RTTabProbe(), e.g. it's not permitted to * break the order of the table. * @returns The replaced item. * @returns NULL if the current item is the NULL item. The traverser * and table remains unchanged. * @param pTrav The traverser. * @param pvItem The item to be inserted. /** The type of table type. */ /** The table operations. */ /** The function for comparing table items. */ /** The number of items in the table. */ /** The table generation number. * This must be updated whenever the table changes. */ * @returns Pointer to the new table. * @returns NULL if we're out of memory or some other resource. * @param pOps The table operations. * @param fCreateFlags The table type specific creation flags. * @param pAllocator Custom allocator. Pass NULL for the default allocator. * @param pfnComp The comparision function. * Duplicates a table to a table of the same type. * @returns Pointer to the new table. * @returns NULL if we're out of memory or some other resource. * @param pTab The table to duplicate. * @param pfnDuplicate Pointer to the item duplication function. If NULL the new table will * be referencing the same data as the old one. * @param pfnNewCB Callback which is called for all the items in the new table. Optional. * @param pAllocator Custom allocator. Pass NULL to use the same allocator as pTab. * @param pTab The table to destroy. * Count the item in the table. * @returns Number of items in the table. * @param pTab The table to count. * Inserts an item into the table, if a matching item is encountered * the pointer to the pointer to it will be returned. * @returns Pointer to the item pointer in the table. * This can be used to replace existing items (don't break anything, dude). * @returns NULL if we failed to allocate memory for the new node. * @param pvItem The item which will be inserted if an matching item was not found in the table. * Inserts an item into the table, fail if a matching item exists. * @returns NULL on success and allocation failure. * @returns Pointer to the matching item. * @param pvItem The item which is to be inserted. * Inserts an item into the table, if a matching item is encountered * it will be replaced and returned. * @returns NULL if inserted and allocation failure. * @returns Pointer to the replaced item. * @param pvItem The item which is to be inserted. * Removes an item from the table if found. * @returns Pointer to the removed item. * @returns NULL if no item matched pvItem. * @param pvItem The item which is to be inserted. * Finds an item in the table. * @returns Pointer to the item it found. * @returns NULL if no item matched pvItem. * @param pvItem The item to find the match to. /** The table being traversed. */ /** Indicates that this traverser was allocated. */ /** The table generation id this traverser was last updated for. * This is used to catch up with table changes. */ * Generic traverser structure. * Tree implementations will use the tree specific part by mapping * this structure onto their own internal traverser structure. * @remark It would be better to use alloca() for allocating the structure, * OTOH this is simpler for the user. /** The common core of the traverser data. */ /** The tree specific data. */ * Initializes a traverser to the NULL item. * The NULL item is an imaginary table item before the first and after * the last items in the table. * @returns Pointer to the traverser positioned at the NULL item. * @returns NULL on failure to allocate the traverser. * @param pTravNew Pointer to a preallocated structure. Optional. * Initializes a traverser to the first item in the table. * If the table is empty, the traverser will be positioned at the NULL item * like with RTTabTravInit(). * @returns Pointer to the traverser positioned at the first item or NULL item. * @returns NULL on failure to allocate the traverser. * @param pTravNew Pointer to a preallocated structure. Optional. * Initializes a traverser to the last item in the table. * If the table is empty, the traverser will be positioned at the NULL item * like with RTTabTravInit(). * @returns Pointer to the traverser positioned at the last item or NULL item. * @returns NULL on failure to allocate the traverser. * @param pTravNew Pointer to a preallocated structure. Optional. * Initializes a traverser to an item matching the given one. * If the item isn't found, the traverser will be positioned at the NULL item * like with RTTabTravInit(). * @returns Pointer to the traverser positioned at the matching item or NULL item. * @returns NULL on failure to allocate the traverser. * @param pTravNew Pointer to a preallocated structure. Optional. * @param pvItem The item to find the match to. * Initializes a traverser to the inserted item. * If there already exists an item in the tree matching pvItem, the traverser * is positioned at that item like with RTTabTravFind(). * If the insert operation failes because of an out of memory condition, the * traverser will be positioned at the NULL item like with RTTabTravInit(). * @returns Pointer to the traverser positioned at the inserted, existing or NULL item. * @returns NULL on failure to allocate the traverser. * @param pTravNew Pointer to a preallocated structure. Optional. * @param pvItem The item to be inserted. * Duplicates a traverser. * @returns The pointer to the duplicate. * @returns NULL on allocation failure. * @param pTrav The traverser to duplicate. * @param pTravNew Pointer to a preallocated structure. Optional. * This can safely be called even if the traverser structure * wasn't dynamically allocated or the constructor failed. * @param pTrav The traverser which is to be free. * @returns The current item. (NULL indicates the imaginary NULL item.) * @param pTrav The traverser. * Advances to the next item. * @returns The new current item. (NULL indicates the imaginary NULL item.) * @param pTrav The traverser. * Advances to the previous item. * @returns The new current item. (NULL indicates the imaginary NULL item.) * @param pTrav The traverser. * Replaces the current item. * This has the same restrictions as RTTabProbe(), e.g. it's not permitted to * break the order of the table. * @returns The replaced item. * @returns NULL if the current item is the NULL item. The traverser * and table remains unchanged. * @param pTrav The traverser. * @param pvItem The item to be inserted.