/***********************************************************************
*
* Projet   : DilibPro
* Module   : Index
* Fichier  : IndexFast.h
* Auteur   : Ducloy
* Date     : 12/96
*
*************************************************************************/

#ifndef _INDEX_FAST_H
#define _INDEX_FAST_H
#include <stdio.h>
#include <string.h>

/** Index fast list */
struct IndexFl_struct
{
  char *str;		/**< string containing the list */
  int  nElem;		/**< number of elements */
  int  sizeElem;	/**< Size of an element of the list (key+tags) */
  int  sizeKey;		/**< Size of the Hfd keys */
};

typedef struct IndexFl_struct IndexFl;

/** Fast Index */
struct IndexFast_struct
{
  char *buffer;		/**< matching line of an index file */
  char *keyZone;	/**< pointer to the first character of the key */
  char *endKeyZone;	/**< pointer to the first character following the key
			   zone (end tag included), generally a @c < */
  int  f;		/**< frequence (@c idx/f# ) */
  IndexFl* listElem;	/**< list of elements matching the key (@c l/e ) */
};

typedef struct IndexFast_struct IndexFast;

IndexFl *IndexFlCreate();

     void IndexFlEdit();

     IndexFl *IndexFlCreateFromIndexFl();

#define IndexFlCopy(s1,s2) (                     \
                 s1->str=s2->str,               \
                 s1->nElem=s2->nElem,           \
                 s1->sizeElem=s2->sizeElem,     \
                 s1->sizeKey=s2->sizeKey,       \
                 s1)

#define IndexFlCdr(s1) (                        \
                 (s1->nElem)  ?                \
                    (                          \
                     s1->str+=s1->sizeElem,    \
                     s1->nElem--,              \
                     s1                       \
                    )                          \
                 : NULL)

#define IndexFlCarCmp(s1,s2) strncmp(s1->str, s2->str, s1->sizeKey)

     int IndexFlInternalAssocCount();

#define IndexFlAssocCount(s1,s2) IndexFlInternalAssocCount \
      (IndexFlCreateFromIndexFl(s1),IndexFlCreateFromIndexFl(s2))

     IndexFast *IndexFastFromString();
     IndexFast *IndexFastRead();
     void IndexFastPrintKeyZone();

#define IndexFastAssocCount(i1,i2) IndexFlAssocCount(i1->listElem, i2->listElem)
    
     void IndexFastEdit();
void IndexFastFree();

#endif /*   _INDEX_FAST_H  */


