/* 
 * sc.h
 *
 * x-kernel v3.3
 *
 * Copyright (c) 1993,1991,1990,1996  Arizona Board of Regents
 */

/*=============================              ==============================
  =============================  File: sc.h  ==============================
  =============================              ==============================

  Scs (searchable collections) are things that map:
  	type = 0: a string onto a (void *)
	type = 1: an integer (different from 0) onto a (void *)
	type = 2: a character address (different from NULL) onto a (void *)

  =========================================================================*/

#ifndef sc_h
#define sc_h


/* Hidden, private type declarations. The applications of this package should
 * only use is Sc, and they are to treat it as opaque: that is, they may
 * assign it, and pass it as arguments, but not manipulate what it points
 * to directly.
---------------------------------------------------------------------------*/
typedef struct TE { char *key;
		    void *value;
} _TE, *TEptr;

typedef struct scRecord { TEptr table;
			  TEptr first, last;
			  int   size, maxCount, count, type, isset;
} ScRecord, *Sc;


/* Return a new, empty Searchable Collection
--------------------------------------------*/
Sc ScCreate(int type, int size );

/* Destroy a Searchable Collection: frees memory, and sets sc=NULL
------------------------------------------------------------------*/
void ScDestroy(Sc sc );

/* Empty a Searchable Collection: Doesn't free any memory
---------------------------------------------------------*/
void ScClear(Sc sc);

/* Insert the pair <key, value> into the collection sc
------------------------------------------------------*/
void ScInsert(Sc sc, char *key, void *value);

/* Remove the pair <key, ? > from the collection sc. Returns 0 if the pair
 * was in the collection, -1 otherwise.
--------------------------------------------------------------------*/
int ScRemove(Sc sc, char *key);

/* Return the value associated with the given key in the Searchable
 * Collection sc, or 0 if no such pair exists.
--------------------------------------------------------------------*/
void *ScLookup(Sc sc, char *key);

/* Print all keys in the Searchable Collection sc, one key per line.
   only valid for types 0 or 1.
--------------------------------------------------------------------*/
void ScPrint(Sc sc);

/* Return the number of elements in sc
--------------------------------------*/
#define ScSize(sc)  ((sc)->count)

/* Iterate over the elements of the collection sc. At each iteration,
 * sckey and scvalue are set to the next <key, value> pair in the collection.
 * Usage:
 *		ScForEach(sc, sckey, scvalue) {
 *			 * whatever you want to do with sckey, scvalue *
 *		} ScNext();
----------------------------------------------------------------------------*/
#define ScForEach(sc, sckey, scvalue) { \
                 int scxx_index; \
		 for (scxx_index=0; scxx_index < (sc)->size; scxx_index++) { \
		     if ((sc)->table[scxx_index].key != NULL) { \
			*(char **)(&(sckey)) = (sc)->table[scxx_index].key; \
			*(char **)(&(scvalue)) = \
			  (char *)sc->table[scxx_index].value; \
			{ \

#define ScNext()        } } } }

#define ScForEachSet(sc, v)  ((sc)->table[scxx_index].value = (void *)(v))

#endif

