998 lines
35 KiB
C
998 lines
35 KiB
C
/*----------------------------------------------------------------------------*/
|
|
/* dsbench.c */
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
/* This file is part of LibDataStr. */
|
|
/* */
|
|
/* LibDataStr is free software: you can redistribute it and/or modify it */
|
|
/* under the terms of the GNU General Public License as published by */
|
|
/* the Free Software Foundation, either version 3 of the License, or */
|
|
/* (at your option) any later version. */
|
|
/* */
|
|
/* LibDataStr is distributed in the hope that it will be useful, */
|
|
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
/* GNU General Public License for more details. */
|
|
/* */
|
|
/* You should have received a copy of the GNU General Public License */
|
|
/* along with LibDataStr. If not, see <https://www.gnu.org/licenses/>. */
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
/* Includes */
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
#define DS_MODE 2
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/time.h>
|
|
#include <stdarg.h>
|
|
|
|
#include <log.h>
|
|
#include <node.h>
|
|
#include <datastr.h>
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
/* Defines */
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
#define LGD_MODULE_NAME "dsb"
|
|
|
|
extern char * strdup ( const char *);
|
|
|
|
#define QUIT 0
|
|
#define CREATE_STRUCT 1
|
|
#define OPEN_STRUCT 2
|
|
#define CLOSE_STRUCT 3
|
|
#define DELETE_STRUCT 4
|
|
#define ADD_VALUE 5
|
|
#define REMOVE_VALUE 6
|
|
#define FIND_VALUE 7
|
|
#define CHG_LIST_TYPE 8
|
|
#define CONVERT_TO_TREE 9
|
|
#define CONVERT_TO_LIST 10
|
|
#define REORG 11
|
|
#define INFO 12
|
|
#define SHOW 13
|
|
#define CHECK 14
|
|
|
|
|
|
|
|
char DataStruct_Name [100];
|
|
char menu [1000];
|
|
char buf [100];
|
|
long int random ( void );
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
/* Prototype */
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
NDT_Status Module_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *);
|
|
|
|
void Menu_Init ( NDT_Root *);
|
|
int Menu_Print ( NDT_Root *);
|
|
|
|
/* Mesure des temps d'exécution */
|
|
|
|
typedef struct {
|
|
double sec;
|
|
struct timeval start;
|
|
struct timeval stop;
|
|
} T_Cpt;
|
|
|
|
#define t_start(x) { gettimeofday (&(x.start), NULL);}
|
|
#define t_stop( x) { gettimeofday (&(x.stop), NULL); x.sec = (double)(x.stop.tv_sec) - (double)(x.start.tv_sec) + ((double)(x.stop.tv_usec) - (double)(x.start.tv_usec)) / 1000000;}
|
|
|
|
T_Cpt t_exec;
|
|
|
|
|
|
|
|
/* Définition des valeurs attachées aux noeuds de la structure */
|
|
|
|
typedef struct
|
|
{
|
|
int Id;
|
|
char Nom[ DSD_NAME_SIZE];
|
|
} T_Module;
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* Module_Manager */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
NDT_Status Module_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node *Node_Ptr, NDT_Command Command, va_list *Args_Ptr)
|
|
{
|
|
NDT_Command_Name Command_Name;
|
|
|
|
|
|
LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Manager command: (%d) called", Command);
|
|
|
|
switch( Command)
|
|
{
|
|
case NDD_CMD_MANAGER_VERSION:
|
|
{
|
|
ND_VA_ARG_GET( Version_Name_Ptr, *Args_Ptr, NDT_Version_Name *);
|
|
|
|
|
|
Command_Name = "NDD_CMD_MANAGER_VERSION";
|
|
|
|
*Version_Name_Ptr = "Module Manager - DSBench";
|
|
|
|
return( NDS_OK);
|
|
}
|
|
|
|
case NDD_CMD_INDEX_GET:
|
|
{
|
|
/*
|
|
ND_VA_ARG_GET( Reply_Index_Id_Ptr, *Args_Ptr, NDT_Index_Id *);
|
|
ND_VA_ARG_GET( Reply_Command_Ptr, *Args_Ptr, NDT_Command *);
|
|
ND_VA_ARG_GET( Cmd, *Args_Ptr, NDT_Command);
|
|
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
|
|
*/
|
|
ND_VA_ARG_GET( Reply_Index_Id_Ptr, *Args_Ptr, NDT_Index_Id *);
|
|
ND_VA_ARG_GET( Reply_Command_Ptr, *Args_Ptr, NDT_Command *);
|
|
ND_VA_ARG_GET( Cmd, *Args_Ptr, NDT_Command);
|
|
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
|
|
|
|
|
|
Command_Name = "NDD_CMD_INDEX_GET";
|
|
|
|
switch(Cmd)
|
|
{
|
|
/*
|
|
case NDT_CMD_SOME_USER_CMD:
|
|
{
|
|
*Reply_Index_Id_Ptr = 0;
|
|
*Reply_Command_Ptr = NDD_CMD_SOME_OTHER_CMD;
|
|
break;
|
|
}
|
|
|
|
...
|
|
*/
|
|
|
|
default:
|
|
{
|
|
*Reply_Index_Id_Ptr = Index_Id;
|
|
*Reply_Command_Ptr = Cmd;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return( NDS_OK);
|
|
}
|
|
|
|
case NDD_CMD_VALUE_ALLOC:
|
|
{
|
|
/*
|
|
ND_VA_ARG_GET( Value_Ptr_Ptr, *Args_Ptr, void **);
|
|
|
|
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
|
|
|
|
ND_VA_ARG_GET( user_data, user_args, user_type);
|
|
ND_VA_ARG_GET( ..., user_args, ...);
|
|
|
|
ND_VA_LIST_CLOSE( user_args);
|
|
*/
|
|
|
|
ND_VA_ARG_GET( Module_Ptr_Ptr, *Args_Ptr, T_Module **);
|
|
|
|
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
|
|
|
|
ND_VA_ARG_GET( Id, user_args, int);
|
|
ND_VA_ARG_GET( Nom, user_args, char *);
|
|
|
|
ND_VA_LIST_CLOSE( user_args);
|
|
|
|
|
|
Command_Name = "NDD_CMD_VALUE_ALLOC";
|
|
|
|
LG_LOG_TRACE_0( LGD_LOG_LEVEL_DEFAULT, "CMD_VALUE_ALLOC called...");
|
|
|
|
|
|
if( DS_Alloc( (void **)Module_Ptr_Ptr, Root_Ptr, sizeof( T_Module)) != DSS_OK)
|
|
{
|
|
LG_LOG_ERROR_0( "Allocation error");
|
|
|
|
return( DSS_KO);
|
|
}
|
|
else
|
|
{
|
|
( *Module_Ptr_Ptr)->Id = Id;
|
|
strncpy( ( *Module_Ptr_Ptr)->Nom, Nom, DSD_NAME_LEN);
|
|
( *Module_Ptr_Ptr)->Nom[ DSD_NAME_LEN] = '\0';
|
|
|
|
return( DSS_OK);
|
|
}
|
|
}
|
|
|
|
case NDD_CMD_VALUE_FREE:
|
|
{
|
|
/*
|
|
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
|
|
|
|
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
|
|
|
|
ND_VA_ARG_GET( user_data, user_args, user_type);
|
|
ND_VA_ARG_GET( ..., user_args, ...);
|
|
|
|
ND_VA_LIST_CLOSE( user_args);
|
|
*/
|
|
|
|
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
|
|
|
|
|
|
Command_Name = "NDD_CMD_VALUE_FREE";
|
|
|
|
/*
|
|
DS_Free( Root_Ptr, Value_Ptr);
|
|
*/
|
|
return( NDS_OK);
|
|
}
|
|
|
|
case NDD_CMD_VALUE_COMP:
|
|
{
|
|
/*
|
|
ND_VA_ARG_GET( Value1_Ptr, *Args_Ptr, void *);
|
|
ND_VA_ARG_GET( Value2_Ptr, *Args_Ptr, void *);
|
|
|
|
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
|
|
|
|
ND_VA_ARG_GET( user_data, user_args, user_type);
|
|
ND_VA_ARG_GET( ..., user_args, ...);
|
|
|
|
ND_VA_LIST_CLOSE( user_args);
|
|
*/
|
|
|
|
ND_VA_ARG_GET( Value1_Ptr, *Args_Ptr, T_Module *);
|
|
ND_VA_ARG_GET( Value2_Ptr, *Args_Ptr, T_Module *);
|
|
|
|
|
|
Command_Name = "NDD_CMD_VALUE_COMP";
|
|
|
|
|
|
switch( Index_Id)
|
|
{
|
|
case 0:
|
|
{
|
|
if( Value1_Ptr->Id < Value2_Ptr->Id)
|
|
{
|
|
return( NDS_LOWER);
|
|
}
|
|
else
|
|
{
|
|
if( Value1_Ptr->Id > Value2_Ptr->Id)
|
|
{
|
|
return( NDS_GREATER);
|
|
}
|
|
else
|
|
{
|
|
return( NDS_EQUAL);
|
|
}
|
|
}
|
|
}
|
|
|
|
default:
|
|
{
|
|
LG_LOG_ERROR_1( "Unknown comp index: (%d)", Index_Id);
|
|
|
|
return( NDS_KO);
|
|
}
|
|
}
|
|
|
|
return( NDS_OK);
|
|
}
|
|
|
|
case NDD_CMD_VALUE_ADD:
|
|
{
|
|
/*
|
|
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
|
|
|
|
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
|
|
|
|
ND_VA_ARG_GET( user_data, user_args, user_type);
|
|
ND_VA_ARG_GET( ..., user_args, ...);
|
|
|
|
ND_VA_LIST_CLOSE( user_args);
|
|
*/
|
|
|
|
|
|
Command_Name = "NDD_CMD_VALUE_ADD";
|
|
|
|
/*
|
|
return( NDS_OK);
|
|
*/
|
|
}
|
|
|
|
case NDD_CMD_VALUE_REMOVE:
|
|
{
|
|
/*
|
|
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
|
|
|
|
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
|
|
|
|
ND_VA_ARG_GET( user_data, user_args, user_type);
|
|
ND_VA_ARG_GET( ..., user_args, ...);
|
|
|
|
ND_VA_LIST_CLOSE( user_args);
|
|
*/
|
|
|
|
Command_Name = "NDD_CMD_VALUE_REMOVE";
|
|
|
|
return( NDS_OK);
|
|
}
|
|
|
|
case NDD_CMD_VALUE_PRINT:
|
|
{
|
|
/*
|
|
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
|
|
|
|
ND_VA_LIST_OPEN( lib_args, *Args_Ptr);
|
|
|
|
ND_VA_ARG_GET( Out, lib_args, FILE *);
|
|
ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode);
|
|
ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth);
|
|
ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset);
|
|
|
|
ND_VA_LIST_OPEN( user_args, lib_args);
|
|
|
|
ND_VA_ARG_GET( user_data, user_args, user_type);
|
|
ND_VA_ARG_GET( ..., user_args, ...);
|
|
|
|
ND_VA_LIST_CLOSE( user_args);
|
|
ND_VA_LIST_CLOSE( lib_args);
|
|
|
|
void *Value_Ptr = Node_Ptr->Value;
|
|
*/
|
|
|
|
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
|
|
|
|
ND_VA_LIST_OPEN( lib_args, *Args_Ptr);
|
|
|
|
ND_VA_ARG_GET( Out, lib_args, FILE *);
|
|
ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode);
|
|
ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth);
|
|
ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset);
|
|
|
|
ND_VA_LIST_CLOSE( lib_args);
|
|
|
|
T_Module *Module_Ptr = (T_Module *)Node_Ptr->Value;
|
|
|
|
|
|
Command_Name = "NDD_CMD_VALUE_PRINT";
|
|
|
|
LG_LOG_INFO_2( "Id Module: (%d) Nom Module: [%s]", Module_Ptr->Id, Module_Ptr->Nom);
|
|
|
|
return( NDS_OK);
|
|
}
|
|
|
|
case NDD_CMD_INFO_PRINT:
|
|
{
|
|
/*
|
|
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
|
|
|
|
ND_VA_LIST_OPEN( lib_args, *Args_Ptr);
|
|
|
|
ND_VA_ARG_GET( Out, lib_args, FILE *);
|
|
ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode);
|
|
ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth);
|
|
ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset);
|
|
|
|
ND_VA_LIST_OPEN( user_args, lib_args);
|
|
|
|
ND_VA_ARG_GET( user_data, user_args, user_type);
|
|
ND_VA_ARG_GET( ..., user_args, ...);
|
|
|
|
ND_VA_LIST_CLOSE( user_args);
|
|
ND_VA_LIST_CLOSE( lib_args);
|
|
*/
|
|
|
|
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
|
|
|
|
ND_VA_LIST_OPEN( lib_args, *Args_Ptr);
|
|
|
|
ND_VA_ARG_GET( Out, lib_args, FILE *);
|
|
ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode);
|
|
ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth);
|
|
ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset);
|
|
|
|
ND_VA_LIST_CLOSE( lib_args);
|
|
|
|
char *Root_Type;
|
|
DST_RootDesc *RootDesc;
|
|
|
|
|
|
Command_Name = "NDD_CMD_INFO_PRINT";
|
|
|
|
/*
|
|
switch( (int)(Root_Ptr->Type & NDD_DS_MSK))
|
|
{
|
|
case NDD_DS_LIST:
|
|
{
|
|
switch ((int)(Root_Ptr->Type & NDD_MN_MSK))
|
|
{
|
|
case NDD_MN_ORDERED: Root_Type = strdup ("liste triée"); break;
|
|
case NDD_MN_FILO: Root_Type = strdup ("liste FILO"); break;
|
|
case NDD_MN_FIFO: Root_Type = strdup ("liste FIFO"); break;
|
|
default: Root_Type = strdup ("inconnu"); break;
|
|
}
|
|
break;
|
|
}
|
|
|
|
case NDD_DS_TREE :
|
|
{
|
|
switch( (int)(Root_Ptr->Type & NDD_MN_MSK))
|
|
{
|
|
case NDD_MN_AUTO_EQU: Root_Type = strdup ("arbre auto-équilibré"); break;
|
|
default: Root_Type = strdup ("arbre non auto-équilibré"); break;
|
|
}
|
|
break;
|
|
}
|
|
|
|
default: Root_Type = strdup ("inconnu"); break;
|
|
}
|
|
|
|
RootDesc = (DST_RootDesc *)(Root->User);
|
|
fprintf( Out, \
|
|
"\nStructure de type %s :\n\t- Nom = %s\n\t- Manager = %s\n\t- Nombre de modules = %ld\n", \
|
|
Root_Type, RootDesc->Heap_Name, RootDesc->Manager_FileName, Root_Ptr->Node_Number);
|
|
|
|
if( ( Root->Type & NDD_DS_MSK) == NDD_DS_TREE)
|
|
fprintf( Out, "\t- Profondeur maxi = %ld\n\t- Profondeur mini = %ld\n\t- Différence maximale autorisée = %ld\n\t- Nombre d'équilibrages = %ld\n", \
|
|
Root_Ptr->Max_Depth, Root_Ptr->Min_Depth, Root_Ptr->Max_Dif, Root_Ptr->Nb_Equ);
|
|
|
|
if( Root_Type) free( Root_Type);
|
|
*/
|
|
return( NDS_OK);
|
|
}
|
|
|
|
case NDD_CMD_USER_TRAVERSE:
|
|
{
|
|
/*
|
|
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
|
|
|
|
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
|
|
|
|
ND_VA_ARG_GET( user_data, user_args, user_type);
|
|
ND_VA_ARG_GET( ..., user_args, ...);
|
|
|
|
ND_VA_LIST_CLOSE( user_args);
|
|
|
|
|
|
void *Value_Ptr = Node_Ptr->Value;
|
|
*/
|
|
|
|
|
|
Command_Name = "NDD_CMD_USER_TRAVERSE";
|
|
|
|
/*
|
|
return( NDS_OK);
|
|
*/
|
|
}
|
|
|
|
default:
|
|
{
|
|
LG_LOG_ERROR_1( "Manager called with an undefined command: (%d)", Command);
|
|
return( NDS_ERRAPI);
|
|
}
|
|
}
|
|
|
|
LG_LOG_ERROR_2( "Manager internal error with command: (%d) name: [%s]", Command, Command_Name);
|
|
return( NDS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* Menu_Init */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
void Menu_Init( NDT_Root *Root )
|
|
{
|
|
sprintf (menu, "Menu :\n");
|
|
sprintf (buf, " - %d) %-30s\n", QUIT, "Quitter");
|
|
strcat (menu, buf);
|
|
sprintf (buf, " - %d) %-30s", CREATE_STRUCT, "Création de structure");
|
|
strcat (menu, buf);
|
|
sprintf (buf, " - %d) %-30s\n", OPEN_STRUCT, "Ouverture de structure");
|
|
strcat (menu, buf);
|
|
if (Root != NULL)
|
|
{
|
|
sprintf (buf, " - %d) %-30s", CLOSE_STRUCT, "Fermer la structure");
|
|
strcat (menu, buf);
|
|
sprintf (buf, " - %d) %-30s\n", DELETE_STRUCT, "Détruire la structure");
|
|
strcat (menu, buf);
|
|
sprintf (buf, " - %d) %-30s", ADD_VALUE, "Ajout de valeurs");
|
|
strcat (menu, buf);
|
|
sprintf (buf, " - %d) %-30s\n", REMOVE_VALUE, "Suppression de valeurs");
|
|
strcat (menu, buf);
|
|
sprintf (buf, " - %d) %-30s\n", FIND_VALUE, "Recherche de valeurs aléatoires");
|
|
strcat (menu, buf);
|
|
|
|
if( ND_INDEX_TYPE_LIST_IS( Root, NDD_INDEX_PRIMARY))
|
|
{
|
|
sprintf (buf, " - %d) %-30s", CHG_LIST_TYPE, "Changement de type de liste");
|
|
strcat (menu, buf);
|
|
sprintf (buf, " - %d) %-30s\n", CONVERT_TO_TREE, "Conversion en arbre");
|
|
strcat (menu, buf);
|
|
}
|
|
else
|
|
{
|
|
sprintf (buf, " - %d) %-30s", CONVERT_TO_LIST, "Conversion en liste triée");
|
|
strcat (menu, buf);
|
|
}
|
|
|
|
sprintf (buf, " - %d) %-30s\n", REORG, "Réorganisation");
|
|
strcat (menu, buf);
|
|
sprintf (buf, " - %d) %-30s", INFO, "Informations sur la structure");
|
|
strcat (menu, buf);
|
|
sprintf (buf, " - %d) %-30s\n", SHOW, "Affichage de la structure");
|
|
strcat (menu, buf);
|
|
sprintf (buf, " - %d) %-30s\n", CHECK, "Vérification de la structure");
|
|
strcat (menu, buf);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* Menu_Print */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
int Menu_Print( NDT_Root *Root )
|
|
{
|
|
Menu_Init (Root);
|
|
fprintf (stdout, "\n---------------------------------------------------------\n");
|
|
fprintf (stdout, menu);
|
|
buf [0] = '\0';
|
|
while (buf [0] == '\0')
|
|
{
|
|
printf ("\nChoice ? ");
|
|
fgets( buf, 100, stdin);
|
|
}
|
|
|
|
return atoi (buf);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* main */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
int main( int argc, char **argv)
|
|
{
|
|
DST_Status status;
|
|
LGT_Status lg_status;
|
|
int rc;
|
|
NDT_Root *Root_Ptr = NULL;
|
|
NDT_Index_Type index_type = ( NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_FIFO);
|
|
char *tmp;
|
|
int n, m, i, j;
|
|
int choice, nb_removed, locked;
|
|
int Nb_Detected, Nb_Corrected;
|
|
T_Module *Module, Ref_Module;
|
|
NDT_Node *Node;
|
|
|
|
|
|
if( ( lg_status = LG_Library_Open( LGD_LOG_WRITER_DEFAULT, true)) != LGS_OK)
|
|
{
|
|
fprintf( stderr, "Can't open LibLog library: (%d)\n", lg_status);
|
|
return( -1);
|
|
}
|
|
|
|
LG_LOG_INFO_0( "Start DSBench");
|
|
|
|
|
|
if( argc > 1 && !strcmp (argv[1], "-h"))
|
|
{
|
|
fprintf( stdout, "Usage : %s [-h] [instance [context]]\n", argv[0]);
|
|
rc = 0;
|
|
}
|
|
else
|
|
{
|
|
if( DS_Library_Open( 0, NULL, DSD_DEBUG_ALL) != DSS_OK)
|
|
{
|
|
LG_LOG_ERROR_0( "Can't open DataStr library");
|
|
rc = -1;
|
|
}
|
|
else
|
|
{
|
|
choice = Menu_Print( Root_Ptr);
|
|
|
|
while (choice != QUIT)
|
|
{
|
|
switch (choice)
|
|
{
|
|
case CREATE_STRUCT:
|
|
{
|
|
fprintf( stdout, "\nNom de la structure à créer ? ");
|
|
fgets( DataStruct_Name, 100, stdin);
|
|
|
|
if( strlen( DataStruct_Name) < 2)
|
|
{
|
|
fprintf( stdout, "Bad name!\n");
|
|
}
|
|
else
|
|
{
|
|
DataStruct_Name[ strlen( DataStruct_Name) - 1] = 0;
|
|
if( ( status = DS_DataStruct_Open( &Root_Ptr, DataStruct_Name, 1, &index_type, "Module_Manager", 0, DSD_CREATE, TRUE)) != DSS_OK)
|
|
{
|
|
LG_LOG_ERROR_1( "Can't create data structure: (%d)", status);
|
|
}
|
|
else
|
|
{
|
|
LG_LOG_INFO_1( "Data structure: [%s] created", DataStruct_Name);
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
case DELETE_STRUCT:
|
|
{
|
|
if( ( status = DS_DataStruct_Close( Root_Ptr, DSD_DESTROY)) != DSS_OK)
|
|
{
|
|
LG_LOG_ERROR_2( "Can't delete data structure: [%s], status: (%d)", DataStruct_Name, status);
|
|
}
|
|
else
|
|
{
|
|
LG_LOG_INFO_1( "Data structure: [%s] deleted", DataStruct_Name);
|
|
|
|
Root_Ptr = NULL;
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
case OPEN_STRUCT:
|
|
{
|
|
fprintf (stdout, "\nNom de la structure à ouvrir ? ");
|
|
fgets( DataStruct_Name, 100, stdin);
|
|
|
|
if( strlen( DataStruct_Name) < 2)
|
|
{
|
|
fprintf( stdout, "Bad name!\n");
|
|
}
|
|
else
|
|
{
|
|
DataStruct_Name[ strlen( DataStruct_Name) - 1] = 0;
|
|
if( ( status = DS_DataStruct_Open( &Root_Ptr, DataStruct_Name, 1, &index_type, "Module_Manager", 0, DSD_OPEN, TRUE)) != DSS_OK)
|
|
{
|
|
LG_LOG_ERROR_1( "Can't open data structure: (%d)", status);
|
|
}
|
|
else
|
|
{
|
|
LG_LOG_INFO_1( "Data structure: [%s] opened", DataStruct_Name);
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
case CLOSE_STRUCT:
|
|
{
|
|
if( ( status = DS_DataStruct_Close( Root_Ptr, DSD_CLOSE) != DSS_OK))
|
|
{
|
|
LG_LOG_ERROR_1( "Can't close data structure: (%d)", status);
|
|
}
|
|
else
|
|
{
|
|
LG_LOG_INFO_1( "Data structure: [%s] Closed", DataStruct_Name);
|
|
Root_Ptr = NULL;
|
|
}
|
|
|
|
break;
|
|
}
|
|
/*
|
|
case FIND_VALUE:
|
|
{
|
|
fprintf (stdout, "\nPlage de recherche (?->?) : ");
|
|
gets (buf);
|
|
tmp = strstr (buf, "->");
|
|
if (tmp != NULL)
|
|
{
|
|
* tmp = '\0';
|
|
n = atoi (buf);
|
|
tmp++;
|
|
tmp++;
|
|
m = atoi (tmp);
|
|
if (m < n)
|
|
{
|
|
printf ("\nEntrées non valides\n");
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
printf ("\nEntrées non valides\n");
|
|
break;
|
|
}
|
|
|
|
DS_DataStruct_Lock (Root, DSD_READ, &Locked);
|
|
|
|
i = n;
|
|
j = m + 1;
|
|
t_start (t_exec);
|
|
while (i < j)
|
|
{
|
|
Module->Id = n + (random () % m);
|
|
DS_Node_Find (Root, &Node, Module, NULL);
|
|
i++;
|
|
}
|
|
t_stop (t_exec);
|
|
|
|
DS_DataStruct_Unlock (Root);
|
|
|
|
fprintf (stdout, "\n%d valeur(s) recherchée(s) en %.4f sec (%.2f select/sec)\n", \
|
|
m - n + 1, t_exec.sec, (m - n + 1) / t_exec.sec);
|
|
break;
|
|
}
|
|
*/
|
|
case ADD_VALUE:
|
|
{
|
|
fprintf (stdout, "\nPlage des valeurs à ajouter (?-?) : ");
|
|
fgets( buf, 100, stdin);
|
|
tmp = strstr( buf, "-");
|
|
|
|
if( tmp != NULL)
|
|
{
|
|
*tmp = '\0';
|
|
n = atoi( buf);
|
|
tmp++;
|
|
m = atoi( tmp);
|
|
|
|
if( m < n)
|
|
{
|
|
printf ("\nEntrées non valides\n");
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
printf( "\nEntrées non valides\n");
|
|
break;
|
|
}
|
|
|
|
DS_DataStruct_Lock( Root_Ptr, DSD_WRITE, &locked);
|
|
|
|
fprintf (stdout, "\nOrdre d'ajout (croissant=0 décroissant=1) ? ");
|
|
fgets( buf, 100, stdin);
|
|
choice = atoi (buf);
|
|
|
|
if( choice == 0)
|
|
{
|
|
i = n;
|
|
j = m + 1;
|
|
t_start (t_exec);
|
|
|
|
while( i < j)
|
|
{
|
|
if( DS_Value_Alloc( (void **)&Module, Root_Ptr, i, "x") == NDS_OK) DS_Value_Add( Root_Ptr, Module);
|
|
i++;
|
|
}
|
|
|
|
t_stop( t_exec);
|
|
}
|
|
else
|
|
{
|
|
i = m;
|
|
j = n - 1;
|
|
t_start( t_exec);
|
|
|
|
while( i > j)
|
|
{
|
|
if( DS_Value_Alloc( (void **)&Module, Root_Ptr, i, "x") == NDS_OK) DS_Value_Add( Root_Ptr, Module);
|
|
i--;
|
|
}
|
|
|
|
t_stop (t_exec);
|
|
}
|
|
|
|
DS_DataStruct_Unlock( Root_Ptr);
|
|
|
|
fprintf( stdout, "\n%d valeur(s) ajoutée(s) en %.4f sec (%.2f ajouts/sec)\n", m - n + 1, \
|
|
t_exec.sec, (m - n + 1) / t_exec.sec);
|
|
break;
|
|
}
|
|
/*
|
|
case REMOVE_VALUE:
|
|
{
|
|
Nb_Removed = 0;
|
|
fprintf (stdout, "\nPlage des valeurs à supprimer (?->?) : ");
|
|
gets (buf);
|
|
tmp = strstr (buf, "->");
|
|
if (tmp != NULL)
|
|
{
|
|
* tmp = '\0';
|
|
n = atoi (buf);
|
|
tmp++;
|
|
tmp++;
|
|
m = atoi (tmp);
|
|
if (m < n)
|
|
{
|
|
printf ("\nEntrées non valides\n");
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
printf ("\nEntrées non valides\n");
|
|
break;
|
|
}
|
|
|
|
DS_DataStruct_Lock (Root, DSD_WRITE, &Locked);
|
|
|
|
fprintf (stdout, "\nOrdre de suppression (croissant=0 décroissant=1) ? ");
|
|
gets (buf);
|
|
choice = atoi (buf);
|
|
if (choice == 0)
|
|
{
|
|
i = n;
|
|
j = m + 1;
|
|
t_start (t_exec);
|
|
while (i < j)
|
|
{
|
|
Ref_Module.Id = i;
|
|
if (DS_Value_Remove (Root, &Ref_Module, (void **)&Module) == NDS_OK)
|
|
{
|
|
DS_Value_Free (Root, Module);
|
|
Nb_Removed++;
|
|
}
|
|
i++;
|
|
}
|
|
t_stop (t_exec);
|
|
}
|
|
else
|
|
{
|
|
i = m;
|
|
j = n - 1;
|
|
t_start (t_exec);
|
|
while (i > j)
|
|
{
|
|
Ref_Module.Id = i;
|
|
if (DS_Value_Remove (Root, &Ref_Module, (void **)&Module) == NDS_OK)
|
|
{
|
|
DS_Value_Free (Root, Module);
|
|
Nb_Removed++;
|
|
}
|
|
i--;
|
|
}
|
|
t_stop (t_exec);
|
|
}
|
|
|
|
DS_DataStruct_Unlock (Root);
|
|
|
|
fprintf (stdout, "\n%d valeur(s) supprimée(s) en %.4f sec (%.2f suppressions/sec)\n",\
|
|
Nb_Removed, t_exec.sec, (m - n + 1) / t_exec.sec);
|
|
break;
|
|
}
|
|
|
|
case CHG_LIST_TYPE:
|
|
{
|
|
fprintf (stdout, "\nType de liste (FIFO=0 ; FILO=1 ; triée=2) ? ");
|
|
gets (buf);
|
|
choice = atoi (buf);
|
|
DS_DataStruct_Lock (Root, DSD_WRITE, &Locked);
|
|
switch (choice)
|
|
{
|
|
case 0:
|
|
Root->Type = NDD_DS_LIST | NDD_MN_FIFO;
|
|
break;
|
|
case 1:
|
|
Root->Type = NDD_DS_LIST | NDD_MN_FILO;
|
|
break;
|
|
case 2:
|
|
Root->Type = NDD_DS_LIST | NDD_MN_ORDERED;
|
|
break;
|
|
default:
|
|
printf ("\nChoix non valide\n");
|
|
break;
|
|
}
|
|
DS_DataStruct_Unlock (Root);
|
|
break;
|
|
}
|
|
|
|
case REORG:
|
|
{
|
|
t_start (t_exec);
|
|
DS_DataStruct_Lock (Root, DSD_WRITE, &Locked);
|
|
DS_DataStruct_Reorg (Root);
|
|
DS_DataStruct_Unlock (Root);
|
|
t_stop (t_exec);
|
|
fprintf (stdout, "\nRéorganisation de la structure en %.4f sec\n", t_exec.sec);
|
|
break;
|
|
}
|
|
|
|
case CONVERT_TO_LIST:
|
|
{
|
|
t_start (t_exec);
|
|
DS_DataStruct_Lock (Root, DSD_WRITE, &Locked);
|
|
DS_DataStruct_Convert (Root, NDD_DS_LIST | NDD_MN_ORDERED);
|
|
DS_DataStruct_Unlock (Root);
|
|
t_stop (t_exec);
|
|
fprintf (stdout, "\nConversion arbre vers liste en %.4f sec\n", t_exec.sec);
|
|
break;
|
|
}
|
|
|
|
case CONVERT_TO_TREE:
|
|
{
|
|
t_start (t_exec);
|
|
DS_DataStruct_Lock (Root, DSD_WRITE, &Locked);
|
|
DS_DataStruct_Convert (Root, NDD_DS_TREE | NDD_MN_AUTO_EQU);
|
|
DS_DataStruct_Unlock (Root);
|
|
t_stop (t_exec);
|
|
fprintf (stdout, "\nConversion liste vers arbre en %.4f sec\n", t_exec.sec);
|
|
break;
|
|
}
|
|
|
|
*/
|
|
case INFO:
|
|
{
|
|
// DS_DataStruct_Lock (Root, DSD_READ, &Locked);
|
|
DS_DataStruct_Info_Print( stdout, Root_Ptr);
|
|
// DS_DataStruct_Unlock (Root);
|
|
break;
|
|
}
|
|
|
|
case SHOW:
|
|
{
|
|
DS_DataStruct_Lock( Root_Ptr, DSD_READ, &locked);
|
|
DS_DataStruct_Value_Print( stdout, Root_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
|
DS_DataStruct_Unlock( Root_Ptr);
|
|
break;
|
|
}
|
|
/*
|
|
case CHECK:
|
|
{
|
|
Nb_Corrected = Nb_Detected = 0;
|
|
ND_DataStruct_Check (Root, &Nb_Detected, &Nb_Corrected, stderr);
|
|
break;
|
|
}
|
|
*/
|
|
default:
|
|
{
|
|
fprintf (stdout, "\nChoix %d non défini\n", choice);
|
|
}
|
|
}
|
|
choice = Menu_Print( Root_Ptr);
|
|
}
|
|
|
|
DS_Library_Close();
|
|
|
|
rc = 0;
|
|
}
|
|
}
|
|
|
|
LG_LOG_INFO_0( "End DSBench");
|
|
|
|
if( ( lg_status = LG_Library_Close( true)) != LGS_OK)
|
|
{
|
|
fprintf( stderr, "Can't close LibLog library: (%d)\n", lg_status);
|
|
rc = -1;
|
|
}
|
|
|
|
return( rc);
|
|
}
|
|
|
|
|