- Add DS_DataStruct_Value_Find(), DS_Index_Reorg(),
- DSBech: Implement DS_Value_Remove, DS_Value_Find, Index_Close, Index_Reorg, Index_List_To_Tree & Index_Tree_To_List commands.
This commit is contained in:
189
lib/libdatastr.c
189
lib/libdatastr.c
@@ -197,11 +197,6 @@ DST_Status DS_Library_Stderr_Set_I( FILE *Out)
|
||||
/* (I) Open_Mode : mode d'ouverture de la structure */
|
||||
/* (I) Own_Value : indique si la structure possède ses valeurs */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
//ND_DataStruct_Open( &OpenedDS_List, 1, &index_type, "DS_OpenedDS_List_Manager", NULL, NULL, NULL, NULL, NULL, TRUE, NULL)) != NDS_OK)
|
||||
|
||||
//DST_Status DS_DataStruct_Open_I( NDT_Root **Root, const char *DS_Name, NDT_DataStruct_Type Type, const char *Manager_FileName, size_t Segment_Size, DST_Flags Open_Mode, int Own_Values);
|
||||
|
||||
//DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT_Index_Nb Index_Nb, NDT_Index_Type *Index_Type_Tab, char *Manager_Name, size_t Segment_Size, DST_Flags Open_Mode, short Own_Value)
|
||||
|
||||
DST_Status DS_DataStruct_Open_I( DST_Root **Root_Ptr_Ptr, char *DS_Name, NDT_Index_Nb Index_Nb, NDT_Index_Type *Index_Type_Tab, char *Manager_Name, size_t Segment_Size, DST_Flags Open_Mode, short Own_Value)
|
||||
{
|
||||
@@ -282,7 +277,7 @@ DST_Status DS_DataStruct_Open_I( DST_Root **Root_Ptr_Ptr, char *DS_Name, NDT
|
||||
rootdesc_tmp.Heap_Name[ DSD_NAME_LEN] = '\0';
|
||||
*/
|
||||
// if( ( nd_status = ND_DataStruct_Open( Root_Ptr_Ptr, Index_Nb, Index_Type_Tab, Manager_Name, NULL, "DS_DataStruct_Alloc", NULL, "DS_DataStruct_Free", NULL, Own_Value, &rootdesc_tmp)) != NDS_OK)
|
||||
if( ( nd_status = ND_DataStruct_Open( &nd_root_ptr, Index_Nb, Index_Type_Tab, Manager_Name, NULL, "DS_DataStruct_Alloc", NULL, "DS_DataStruct_Free", NULL, Own_Value, &root_tmp)) != NDS_OK)
|
||||
if( ( nd_status = ND_DataStruct_Open( &nd_root_ptr, Index_Nb, Index_Type_Tab, Manager_Name, NULL, "DS_Allocator", NULL, "DS_Deallocator", NULL, Own_Value, &root_tmp)) != NDS_OK)
|
||||
{
|
||||
LG_LOG_ERROR_2( "Unable to create a new node structure in the existing heap: [%s], status: (%d)", heap_ptr->Name, nd_status);
|
||||
|
||||
@@ -500,7 +495,7 @@ Strange: why end the heap here ?
|
||||
rootdesc_tmp.Heap_Name[ DSD_NAME_LEN] = '\0';
|
||||
*/
|
||||
// if( ( nd_status = ND_DataStruct_Open( Root_Ptr_Ptr, Index_Nb, Index_Type_Tab, Manager_Name, NULL, "DS_DataStruct_Alloc", NULL, "DS_DataStruct_Free", NULL, Own_Value, &rootdesc_tmp)) != NDS_OK)
|
||||
if( ( nd_status = ND_DataStruct_Open( &nd_root_ptr, Index_Nb, Index_Type_Tab, Manager_Name, NULL, "DS_DataStruct_Alloc", NULL, "DS_DataStruct_Free", NULL, Own_Value, &root_tmp)) != NDS_OK)
|
||||
if( ( nd_status = ND_DataStruct_Open( &nd_root_ptr, Index_Nb, Index_Type_Tab, Manager_Name, NULL, "DS_Allocator", NULL, "DS_Deallocator", NULL, Own_Value, &root_tmp)) != NDS_OK)
|
||||
{
|
||||
LG_LOG_ERROR_2( "Unable to create a new node structure in new heap: [%s], status: (%d)", heap_ptr->Name, nd_status);
|
||||
|
||||
@@ -913,7 +908,7 @@ DST_Status DS_DataStruct_Close_I( DST_Root *Root_Ptr, DST_Flags Close_Mode)
|
||||
return( DSS_KO);
|
||||
}
|
||||
|
||||
if( ( status = DS_DataStruct_Free( Root_Ptr, &( Root_Ptr->ND_Root), NULL)) != DSS_OK)
|
||||
if( ( status = DS_Deallocator( Root_Ptr, &( Root_Ptr->ND_Root), NULL)) != DSS_OK)
|
||||
{
|
||||
LG_LOG_ERROR_2( "Unable to free data structure: [%s], status: (%d)", ds_name, status);
|
||||
}
|
||||
@@ -1396,6 +1391,10 @@ DST_Status DS_DataStruct_Print_I ( NDT_Root * Root, FILE * Out )
|
||||
return DS_DataStruct_Traverse_I (Root, NDD_CMD_PRINT_VALUE, Out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Add a new value to a data structure */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -1407,7 +1406,6 @@ DST_Status DS_DataStruct_Value_Add_I( DST_Root *Root_Ptr, void *Value_Ptr)
|
||||
{
|
||||
// DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr);
|
||||
|
||||
DST_Status status;
|
||||
NDT_Status nd_status;
|
||||
|
||||
|
||||
@@ -1425,9 +1423,7 @@ DST_Status DS_DataStruct_Value_Add_I( DST_Root *Root_Ptr, void *Value_Ptr)
|
||||
|
||||
if( ( nd_status = ND_DataStruct_Value_Add( &( Root_Ptr->ND_Root), Value_Ptr)) != NDS_OK)
|
||||
{
|
||||
LG_LOG_ERROR_1( "Unable to add a value to the data structure: (%d)", nd_status);
|
||||
|
||||
// if (!DS_ERROR(rc)) RootDesc->Valid = TRUE;
|
||||
LG_LOG_ERROR_1( "Unable to add a value to the data structure, status: (%d)", nd_status);
|
||||
|
||||
return( DSS_KO);
|
||||
}
|
||||
@@ -1445,59 +1441,42 @@ DST_Status DS_DataStruct_Value_Add_I( DST_Root *Root_Ptr, void *Value_Ptr)
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Suppression du premier noeud correspondant à une valeur donnée */
|
||||
/* Remove the first matching value from a data structure */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* (I) Root : pointeur sur la racine de la structure de données */
|
||||
/* (I) Reference_Value : pointeur sur la valeur de référence */
|
||||
/* (I) Removed_Value : adresse d'un pointeur sur la valeur supprimée */
|
||||
/* (I) Root_Ptr: Data structure pointer */
|
||||
/* (I) Ref_Value_Ptr: Reference value pointer to search */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*
|
||||
DST_Status DS_Value_Remove_I ( NDT_Root * Root, void * Reference_Value, void ** Removed_Value )
|
||||
|
||||
DST_Status DS_DataStruct_Value_Remove_I( DST_Root *Root_Ptr, void *Ref_Value_Ptr)
|
||||
{
|
||||
DST_Status rc;
|
||||
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
|
||||
NDT_Status nd_status;
|
||||
|
||||
|
||||
/* On vérifie que la data structure est valide */
|
||||
/*
|
||||
if (RootDesc->Valid == FALSE)
|
||||
{
|
||||
int Nb_Detected, Nb_Corrected;
|
||||
|
||||
/* On vérifie la structure */
|
||||
/*
|
||||
Nb_Detected = Nb_Corrected = 0;
|
||||
rc = DS_DataStruct_Check_L (Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
|
||||
if (rc != DSS_OK)
|
||||
{
|
||||
sprintf (DS_Error_Msg, "Error DS_Value_Remove : unable to check the data structure");
|
||||
DS_Error_Print ();
|
||||
DS_STRUCT_VALID_CHECK( Root_Ptr);
|
||||
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
/* On rend la structure invalide le temps de la suppression de valeur */
|
||||
/*
|
||||
RootDesc->Valid = FALSE;
|
||||
/* On rend la structure invalide le temps de l'ajout */
|
||||
|
||||
Root_Ptr->Status = DSD_DATASTRUCT_STATUS_INVALID;
|
||||
|
||||
|
||||
/* Suppression du noeud correspondant à la valeur de référence */
|
||||
/*
|
||||
rc = ND_Value_Remove (Root, Reference_Value, Removed_Value);
|
||||
if (rc != NDS_OK)
|
||||
|
||||
if( ( nd_status = ND_DataStruct_Value_Remove( &( Root_Ptr->ND_Root), Ref_Value_Ptr)) != NDS_OK)
|
||||
{
|
||||
sprintf (DS_Error_Msg, "Error DS_Value_Remove : unable to remove a value from the data structure");
|
||||
DS_Error_Print ();
|
||||
LG_LOG_ERROR_1( "Unable to remove a value to the data structure, status: (%d)", nd_status);
|
||||
|
||||
if (!DS_ERROR(rc)) RootDesc->Valid = TRUE;
|
||||
|
||||
return rc;
|
||||
return( DSS_KO);
|
||||
}
|
||||
|
||||
|
||||
/* On rend la structure à nouveau valide */
|
||||
/*
|
||||
RootDesc->Valid = TRUE;
|
||||
|
||||
return DSS_OK;
|
||||
Root_Ptr->Status = DSD_DATASTRUCT_STATUS_VALID;
|
||||
|
||||
return( DSS_OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -1517,11 +1496,9 @@ DST_Status DS_Value_Remove_I ( NDT_Root * Root, void * Reference_Value, void **
|
||||
|
||||
DST_Status DS_DataStruct_Value_Print_I( FILE *Out_Ptr, DST_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset, ...)
|
||||
{
|
||||
// DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr);
|
||||
|
||||
DST_Status status;
|
||||
NDT_Status nd_status;
|
||||
va_list user_args;
|
||||
DST_Status status;
|
||||
NDT_Status nd_status;
|
||||
va_list user_args;
|
||||
|
||||
|
||||
va_start( user_args, Recursive_Offset);
|
||||
@@ -1535,7 +1512,7 @@ DST_Status DS_DataStruct_Value_Print_I( FILE *Out_Ptr, DST_Root *Root_Ptr, ND
|
||||
|
||||
if( ( nd_status = ND_DataStruct_Value_Print_VI( Out_Ptr, &( Root_Ptr->ND_Root), Recursive_Mode, Recursive_Depth, Recursive_Offset, &user_args)) != NDS_OK)
|
||||
{
|
||||
LG_LOG_ERROR_1( "Unable to dump the node structure: (%d)", nd_status);
|
||||
LG_LOG_ERROR_1( "Unable to print the data structure values, status: (%d)", nd_status);
|
||||
|
||||
status = DSS_KO;
|
||||
}
|
||||
@@ -1553,6 +1530,54 @@ DST_Status DS_DataStruct_Value_Print_I( FILE *Out_Ptr, DST_Root *Root_Ptr, ND
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Find a value in a data structure */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* (O) Value_Ptr_Ptr: Value pointer address found */
|
||||
/* (I) Root_Ptr: Data structure pointer */
|
||||
/* (I) Ref_Value_Ptr: Reference value pointer to search */
|
||||
/* (I) ...: User args */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
DST_Status DS_DataStruct_Value_Find_I( void **Value_Ptr_Ptr, DST_Root *Root_Ptr, void *Ref_Value_Ptr, ...)
|
||||
{
|
||||
DST_Status status;
|
||||
NDT_Status nd_status;
|
||||
va_list user_args;
|
||||
|
||||
|
||||
va_start( user_args, Ref_Value_Ptr);
|
||||
|
||||
*Value_Ptr_Ptr = NULL;
|
||||
|
||||
|
||||
/* On vérifie que la data structure est valide */
|
||||
|
||||
DS_STRUCT_VALID_CHECK( Root_Ptr);
|
||||
|
||||
|
||||
/* Recherche dans la node structure */
|
||||
|
||||
if( ( nd_status = ND_DataStruct_Value_Find_VI( Value_Ptr_Ptr, &( Root_Ptr->ND_Root), Ref_Value_Ptr, &user_args)) != NDS_OK)
|
||||
{
|
||||
LG_LOG_ERROR_1( "Unable to search a value in the data structure, status: (%d)", nd_status);
|
||||
|
||||
status = DSS_KO;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = DSS_OK;
|
||||
}
|
||||
|
||||
va_end( user_args);
|
||||
|
||||
return( status);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Create a new index */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -1561,7 +1586,7 @@ DST_Status DS_DataStruct_Value_Print_I( FILE *Out_Ptr, DST_Root *Root_Ptr, ND
|
||||
/* (I) Index_Type: Index type (List, tree, ...) */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
NDT_Status DS_Index_Open_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type)
|
||||
DST_Status DS_Index_Open_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type)
|
||||
{
|
||||
NDT_Status nd_status;
|
||||
|
||||
@@ -1589,7 +1614,7 @@ NDT_Status DS_Index_Open_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_In
|
||||
/* (I) Index_Id: Id of the index */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
NDT_Status DS_Index_Close_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id)
|
||||
DST_Status DS_Index_Close_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id)
|
||||
{
|
||||
NDT_Status nd_status;
|
||||
|
||||
@@ -1618,7 +1643,7 @@ NDT_Status DS_Index_Close_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id)
|
||||
/* (I) Index_Type: Index type (List, tree, ...) */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
NDT_Status DS_Index_Convert_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type)
|
||||
DST_Status DS_Index_Convert_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type)
|
||||
{
|
||||
NDT_Status nd_status;
|
||||
|
||||
@@ -1639,6 +1664,36 @@ NDT_Status DS_Index_Convert_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Reorganise a data structure index: */
|
||||
/* - Sort a non-sorted list */
|
||||
/* - Rebalance a non auto-balanced tree */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* (I) Root_Ptr: Data structure pointer */
|
||||
/* (I) Index_Id: Id of the index */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
DST_Status DS_Index_Reorg_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id)
|
||||
{
|
||||
NDT_Status nd_status;
|
||||
|
||||
|
||||
if( ( nd_status = ND_Index_Reorg_I( &( Root_Ptr->ND_Root), Index_Id)) != NDS_OK)
|
||||
{
|
||||
LG_LOG_ERROR_2( "Unable to reorg index: (%d), status: (%d)", Index_Id, nd_status);
|
||||
|
||||
return( DSS_KO);
|
||||
}
|
||||
else
|
||||
{
|
||||
return( DSS_OK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Récupération du premier noeud d'une structure */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -1996,10 +2051,10 @@ DST_Status DS_Value_Alloc_I( void **Value_Ptr_Ptr, DST_Root *Root_Ptr, ... )
|
||||
/* (I) Root : pointeur sur la racine de la structure de données */
|
||||
/* (I) Value : pointeur sur la valeur à désallouer */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*
|
||||
DST_Status DS_Value_Free_I ( NDT_Root * Root, void * Value )
|
||||
|
||||
DST_Status DS_Value_Free_I( DST_Root *Root_Ptr, void *Value_Ptr)
|
||||
{
|
||||
return ND_Value_Free (Root, Value);
|
||||
return ND_Value_Free( &( Root_Ptr->ND_Root), Value_Ptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -2016,7 +2071,7 @@ DST_Status DS_Value_Free_I ( NDT_Root * Root, void * Value )
|
||||
|
||||
DST_Status DS_Alloc_I( void **Ptr_Ptr, NDT_Root *ND_Root_Ptr, size_t Size)
|
||||
{
|
||||
return( DS_DataStruct_Alloc( Ptr_Ptr, ND_Root_Ptr, Size, NULL));
|
||||
return( DS_Allocator( Ptr_Ptr, ND_Root_Ptr, Size, NULL)); // TBC: Use defined allocator!
|
||||
}
|
||||
|
||||
|
||||
@@ -2032,7 +2087,7 @@ DST_Status DS_Alloc_I( void **Ptr_Ptr, NDT_Root *ND_Root_Ptr, size_t Size)
|
||||
|
||||
DST_Status DS_Free_I( NDT_Root *ND_Root_Ptr, void *Ptr)
|
||||
{
|
||||
return( DS_DataStruct_Free( Ptr, ND_Root_Ptr, NULL));
|
||||
return( DS_Deallocator( Ptr, ND_Root_Ptr, NULL)); // TBC: Use defined allocator!
|
||||
}
|
||||
|
||||
|
||||
@@ -2722,7 +2777,7 @@ DST_Status DS_Value_Free_L ( NDT_Root * Root, void * Value )
|
||||
/*
|
||||
DST_Status DS_Alloc_L ( NDT_Root * Root, size_t Size, void ** Ptr )
|
||||
{
|
||||
return DS_DataStruct_Alloc (Size, Ptr, Root->User);
|
||||
return DS_Allocator (Size, Ptr, Root->User);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -2734,7 +2789,7 @@ DST_Status DS_Alloc_L ( NDT_Root * Root, size_t Size, void ** Ptr )
|
||||
/*
|
||||
DST_Status DS_Free_L ( NDT_Root * Root, void * Ptr )
|
||||
{
|
||||
return DS_DataStruct_Free (Ptr, Root->User);
|
||||
return DS_Deallocator (Ptr, Root->User);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -3508,7 +3563,7 @@ DST_Status DS_DataStruct_IsOpen( DST_Root **Root_Ptr_Ptr, char *DS_Name)
|
||||
/* Fonction d'allocation attachée à une structure de données : */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
DST_Status DS_DataStruct_Alloc( void **Ptr_Ptr, NDT_Root *ND_Root_Ptr, size_t Size, void *User_Ptr)
|
||||
DST_Status DS_Allocator( void **Ptr_Ptr, NDT_Root *ND_Root_Ptr, size_t Size, void *User_Ptr)
|
||||
{
|
||||
// DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)Data_Ptr;
|
||||
// char *Heap_Name = RootDesc_Ptr->Heap_Name;
|
||||
@@ -3665,7 +3720,7 @@ DST_Status DS_DataStruct_Alloc( void **Ptr_Ptr, size_t Size, void *Data_Ptr)
|
||||
/* Fonction de désallocation attachée à une structure de données : */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
DST_Status DS_DataStruct_Free( void *Ptr, NDT_Root *ND_Root_Ptr, void *User_Ptr)
|
||||
DST_Status DS_Deallocator( void *Ptr, NDT_Root *ND_Root_Ptr, void *User_Ptr)
|
||||
{
|
||||
// DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)Data_Ptr;
|
||||
// char *Heap_Name = RootDesc_Ptr->Heap_Name;
|
||||
|
||||
@@ -126,7 +126,7 @@ DST_Status DS_Semaphore_Operate (int, struct sembuf *, unsigned int);
|
||||
/* Fonction d'allocation attachée à une structure de données : */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
DST_Status DS_DataStruct_Alloc ( void **Ptr_Ptr, NDT_Root *ND_Root_Ptr, size_t Size, void *User_Ptr);
|
||||
DST_Status DS_Allocator( void **Ptr_Ptr, NDT_Root *ND_Root_Ptr, size_t Size, void *User_Ptr);
|
||||
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ DST_Status DS_DataStruct_Alloc ( void **Ptr_Ptr, NDT_Root *ND_Root_Ptr, size_
|
||||
/* Fonction de désallocation attachée à une structure de données : */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
DST_Status DS_DataStruct_Free ( void *Ptr, NDT_Root *ND_Root_Ptr, void *User_Ptr );
|
||||
DST_Status DS_Deallocator( void *Ptr, NDT_Root *ND_Root_Ptr, void *User_Ptr );
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user