/* ==================================================== */
/*      Copyright (c) Atelier de BioInformatique        */
/*      Mar. 92                                         */
/*      File: libstki.h                                 */
/*      Purpose: library of dynamic stacks holding      */
/*               integer values                         */
/*      History:                                        */
/*      00/03/92 : <Gloup> first draft                  */
/*      07/07/93 : <Gloup> complete revision            */
/*      10/03/94 : <Gloup> added xxxVector funcs        */
/*      14/05/99 : <Gloup> last revision                */
/*      07/12/21 : <Zafacs> last some cleaning for 2020 */
/* ==================================================== */

#ifndef _H_libstki
#define _H_libstki

#include <stdint.h>
#include <stdbool.h>
#include "apat_mem.h" 

/* ==================================================== */
/* Constantes de dimensionnement                        */
/* ==================================================== */

#ifndef kMinStackiSize
#define kMinStackiSize          2       /* taille mini stack    */
#endif


#define kStkiNoErr              0       /* ok                   */
#define kStkiMemErr             1       /* not enough memory    */

#define kStkiReset              true
#define kStkiGet                false


/* ==================================================== */
/*  Types & Structures de donnees                       */
/* ==================================================== */

                                                /* -------------------- */
                                                /* structure : pile     */
                                                /* -------------------- */
typedef struct Stacki {
                                                /* ---------------------*/
        int32_t                   size;         /* stack size           */
        int32_t                   top;          /* current free pos.    */
        int32_t                   cursor;       /* current cursor       */
        int32_t                   *val;         /* values               */
                                                /* ---------------------*/
} Stacki, *StackiPtr, **StackiHdle;      



/* ==================================================== */
/*  Prototypes (generated by mproto)                    */
/* ==================================================== */

                                        /* libstki.c    */
                                        
int16_t         StkiError          (bool       reset                    );
StackiPtr       NewStacki          (int32_t    size                     );
StackiPtr       FreeStacki         (StackiPtr  stki                     );
StackiHdle      NewStackiVector    (int32_t vectSize, int32_t stackSize );
StackiHdle      FreeStackiVector   (StackiHdle stkh , int32_t vectSize  );
int32_t         ResizeStacki       (StackiHdle stkh , int32_t size      );
bool            PushiIn            (StackiHdle stkh , int32_t val       );
bool            PopiOut            (StackiHdle stkh , int32_t *val      );
bool            ReadiDown          (StackiPtr  stki , int32_t *val      );
bool            ReadiUp            (StackiPtr  stki , int32_t *val      );
void            CursiToTop         (StackiPtr  stki                     );
void            CursiToBottom      (StackiPtr  stki                     );
void            CursiSwap          (StackiPtr  stki                     );
bool            SearchDownStacki   (StackiPtr  stki  , int32_t sval     );
bool            BinSearchStacki    (StackiPtr  stki  , int32_t sval     );
bool            SameStacki         (StackiPtr  stki1 , StackiPtr stki2  );
bool            ReverseStacki      (StackiPtr  stki                     );
bool            EmptyStacki        (StackiPtr stki                      );

#endif /* _H_libstki */